Subject | Re: select IN subquery with lots of OR in subquery is very slow |
---|---|
Author | navneet77 |
Post date | 2008-02-13T12:54:43Z |
Thanks I will try that. Is there any way I can change a simillar NOT
IN query. Like
select * from TABLE_A where TABLE_A_ID NOT IN (select TABLE_A_ID from
TABLE_B where TABLE_B.COL_B = 'something' or TABLE_B.COL_B
= 'something2' or TABLE_B.COL_B = 'something3' or TABLE_B.COL_B
= 'something4'...)
Navneet
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@...>
wrote:
subqueries require. (b.COL_B should be indexed, of course...)
IN query. Like
select * from TABLE_A where TABLE_A_ID NOT IN (select TABLE_A_ID from
TABLE_B where TABLE_B.COL_B = 'something' or TABLE_B.COL_B
= 'something2' or TABLE_B.COL_B = 'something3' or TABLE_B.COL_B
= 'something4'...)
Navneet
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@...>
wrote:
>records
> At 09:30 PM 13/02/2008, you wrote:
> >I am using the latest version firebird server on windows. I have a
> >query like
> >
> >select * from TABLE_A where TABLE_A_ID in (select TABLE_A_ID from
> >TABLE_B where TABLE_B.COL_B = 'something' or TABLE_B.COL_B
> >= 'something2' or TABLE_B.COL_B = 'something3' or TABLE_B.COL_B
> >= 'something4'...)
> >
> >Both TABLE_A_ID and COL_B has an index. TABLE_B has about 26000
> >and the query statistics says more than 900000 index reads forTABLE_B
> >and the query takes about a minute to complete.this
> >
> >The more OR i have in the subquery the longer it takes.
> >
> >If I run the subquery seperately it returns almost instantly. Is
> >how it is suppose to work.are almost certainly a lot more costly than a clean inner join:
>
> Yes. This is a case where multiple consecutive correlated queries
>('something', 'something2','something3','something4'...)
> select a.* from TABLE_A a
> join TABLE_B b
> on
> a.TABLE_A_ID = b.TABLE_A_ID
> where b.COL_B in
>the IN() list but not with all the repetition that the correlated
> You'll still get an indexed read (an OR search) on each member of
subqueries require. (b.COL_B should be indexed, of course...)
>
> ./heLen
>