Tuning Select Not IN statement(2 Merged) [message #510151] |
Thu, 02 June 2011 11:25 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
getzeeshan
Messages: 65 Registered: July 2008
|
Member |
|
|
Hi There,
We have a person running a query and following is the explain plan
explain plan for
select distinct(extractvalue(xmltype(a.email_variables), '/CalliopeData/Attributes/HOTEL_BRAND')) as ThisBrand
from hh.t_ecomm_mem_relations a
where extractvalue(xmltype(a.email_variables), '/CalliopeData/Attributes/HOTEL_BRAND') not in (select b.code_brand from hh.t_pr_brand b)
and a.code_corr_ecat = 'PREA'
and a.status = 'S'
and a.audit_time > sysdate - 1
;
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1904775187
-------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 32018 | 25 (4)| 00:00:01 | | |
| 1 | HASH UNIQUE | | 14 | 32018 | 25 (4)| 00:00:01 | | |
|* 2 | FILTER | | | | | | | |
| 3 | PARTITION RANGE ITERATOR | | 14 | 32018 | 17 (0)| 00:00:01 | KEY | 13 |
|* 4 | TABLE ACCESS BY LOCAL INDEX ROWID| T_ECOMM_MEM_RELATIONS | 14 | 32018 | 17 (0)| 00:00:01 | KEY | 13 |
|* 5 | INDEX RANGE SCAN | X_ECOMM_MEM_RELATIONS3 | 15 | | 3 (0)| 00:00:01 | KEY | 13 |
|* 6 | INDEX FULL SCAN | I_PR_BRAND | 1 | 3 | 1 (0)| 00:00:01 | | |
-------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "HH"."T_PR_BRAND" "B" WHERE
LNNVL("B"."CODE_BRAND"<>EXTRACTVALUE("XMLTYPE"."XMLTYPE"(:B1),'/CalliopeData/Attributes/HOTEL_BRAND'))))
4 - filter("A"."STATUS"='S')
5 - access("A"."AUDIT_TIME">SYSDATE@!-1 AND "A"."CODE_CORR_ECAT"='PREA')
filter("A"."CODE_CORR_ECAT"='PREA')
6 - filter(LNNVL("B"."CODE_BRAND"<>EXTRACTVALUE("XMLTYPE"."XMLTYPE"(:B1),'/CalliopeData/Attributes/HOTEL_BRAND')))
=========================
Please let me know if something can be done for this I tried not exists and some Antijoin hints in the subquery which is used in filter NOT IN
I tried minus too
* < code tags > added by BlackSwan; please do so yourself in future
[Updated on: Thu, 02 June 2011 12:16] by Moderator Report message to a moderator
|
|
|
|
|
Re: Tuning Select Not IN statement [message #510159 is a reply to message #510158] |
Thu, 02 June 2011 11:45 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
getzeeshan
Messages: 65 Registered: July 2008
|
Member |
|
|
Im not looking for an instant awnser... It happened that I clicked the tab twice while posting the message and it had posted the same thing again and again so I edited the etxt with one liner
version 10.2.0.4 -- sorry about this.
I have also attached the explain plan as a textpad doc for clear picture
|
|
|
|
|
Re: Tuning Select Not IN statement [message #510242 is a reply to message #510188] |
Fri, 03 June 2011 03:48 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13965 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
That would imply the problem is actually the xml functions. Does this one perform better:
SELECT DISTINCT this_brand
FROM (SELECT extractvalue(xmltype(a.email_variables), '/CalliopeData/Attributes/HOTEL_BRAND')
from hh.t_ecomm_mem_relations a
where a.code_corr_ecat = 'PREA'
and a.status = 'S'
and a.audit_time > sysdate - 1)
WHERE this_brand NOT IN (select b.code_brand from hh.t_pr_brand b);
|
|
|
|
|
Re: Tuning Select Not IN statement [message #510315 is a reply to message #510299] |
Fri, 03 June 2011 10:00 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
getzeeshan
Messages: 65 Registered: July 2008
|
Member |
|
|
this is the prod plan
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1904775187
-------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 32018 | 24 (5)| 00:00:01 | | |
| 1 | HASH UNIQUE | | 14 | 32018 | 24 (5)| 00:00:01 | | |
|* 2 | FILTER | | | | | | | |
| 3 | PARTITION RANGE ITERATOR | | 14 | 32018 | 16 (0)| 00:00:01 | KEY | 13 |
|* 4 | TABLE ACCESS BY LOCAL INDEX ROWID| T_ECOMM_MEM_RELATIONS | 14 | 32018 | 16 (0)| 00:00:01 | KEY | 13 |
|* 5 | INDEX RANGE SCAN | X_ECOMM_MEM_RELATIONS3 | 15 | | 3 (0)| 00:00:01 | KEY | 13 |
|* 6 | INDEX FULL SCAN | I_PR_BRAND | 1 | 3 | 1 (0)| 00:00:01 | | |
-------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "HH"."T_PR_BRAND" "B" WHERE
LNNVL("B"."CODE_BRAND"<>EXTRACTVALUE("XMLTYPE"."XMLTYPE"(:B1),'/CalliopeData/Attributes/HOTEL_BRAND'))))
4 - filter("A"."STATUS"='S')
5 - access("A"."AUDIT_TIME">SYSDATE@!-1 AND "A"."CODE_CORR_ECAT"='PREA')
filter("A"."CODE_CORR_ECAT"='PREA')
6 - filter(LNNVL("B"."CODE_BRAND"<>EXTRACTVALUE("XMLTYPE"."XMLTYPE"(:B1),'/CalliopeData/Attributes/HOTEL_BRAND')))
23 rows selected.
* [ code tags ] fixed by BlackSwan
[Updated on: Fri, 03 June 2011 10:02] by Moderator Report message to a moderator
|
|
|
|
Re: Tuning Select Not IN statement [message #510317 is a reply to message #510316] |
Fri, 03 June 2011 10:03 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
getzeeshan
Messages: 65 Registered: July 2008
|
Member |
|
|
Sorry I forgot to mention one more thing...
The above suggestion of query to execute "this brand" is not a variable --> Its a an alias for ""extractvalue(xmltype(a.email_variables), '/CalliopeData/Attributes/HOTEL_BRAND')""
so the query suggested to run is throwing line 1 as invalid variable.
|
|
|
Re: Tuning Select Not IN statement [message #510318 is a reply to message #510317] |
Fri, 03 June 2011 10:09 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
cookiemonster
Messages: 13965 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
I know it's not a variable:
SELECT DISTINCT this_brand
FROM (SELECT extractvalue(xmltype(a.email_variables), '/CalliopeData/Attributes/HOTEL_BRAND') as this_brand --I missed the alias here
from hh.t_ecomm_mem_relations a
where a.code_corr_ecat = 'PREA'
and a.status = 'S'
and a.audit_time > sysdate - 1)
WHERE this_brand NOT IN (select b.code_brand from hh.t_pr_brand b);
|
|
|
Re: Tuning Select Not IN statement [message #510343 is a reply to message #510249] |
Fri, 03 June 2011 15:39 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
getzeeshan
Messages: 65 Registered: July 2008
|
Member |
|
|
I think the above one works super fast
15:38:53 SYS@hhuat SQL> SELECT DISTINCT this_brand
FROM (SELECT extractvalue(xmltype(a.email_variables), '/CalliopeData/Attributes/HOTEL_BRAND') as this_brand --I missed the alias here
15:39:29 2 15:39:29 3 from hh.t_ecomm_mem_relations a
where a.code_corr_ecat = 'PREA'
15:39:29 4 15:39:29 5 and a.status = 'S'
15:39:29 6 and a.audit_time > sysdate - 1)
15:39:29 7 WHERE this_brand NOT IN (select b.code_brand from hh.t_pr_brand b);
no rows selected
Elapsed: 00:00:00.00
CM: fixed code tags
[Updated on: Fri, 03 June 2011 16:19] by Moderator Report message to a moderator
|
|
|
|
Re: Tuning Select Not IN statement [message #510353 is a reply to message #510347] |
Fri, 03 June 2011 17:59 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
getzeeshan
Messages: 65 Registered: July 2008
|
Member |
|
|
I totally agree with you working on a real data set would help us get a better plan and work around. Let me check with the developer if hes going to run the same again a similar query with the proper data to retrieve.
and thx for Code tag.
Thx! for all your help on this.
|
|
|