Subject | Re: Optimizing in (...) Statements |
---|---|
Author | Svein Erling Tysvær |
Post date | 2004-10-14T11:06:42Z |
I'm sure there are better ways to achieve what you want than using
UNION, but I've never heard of '<field> IN <constant values>' being
slow so it is hard to tell how. '<field> IN <SELECT ...>' is a
different beast that at least used to be slow and which I always
converted to an 'EXISTS (SELECT * FROM ... WHERE <field>...)'. Arno
has changed the optimiser so that this should be better now, but I've
never bothered to change my habits back (nor upgraded to Firebird 1.5)
, so I cannot tell whether or not there still are situations where his
improvements are still lacking.
For us to be able to help you, I would be good if you posted the
actual query, the plan and told us a bit about the indexes and
table(s) involved.
Set
UNION, but I've never heard of '<field> IN <constant values>' being
slow so it is hard to tell how. '<field> IN <SELECT ...>' is a
different beast that at least used to be slow and which I always
converted to an 'EXISTS (SELECT * FROM ... WHERE <field>...)'. Arno
has changed the optimiser so that this should be better now, but I've
never bothered to change my habits back (nor upgraded to Firebird 1.5)
, so I cannot tell whether or not there still are situations where his
improvements are still lacking.
For us to be able to help you, I would be good if you posted the
actual query, the plan and told us a bit about the indexes and
table(s) involved.
Set
--- In firebird-support@yahoogroups.com, "m_quadrat" wrote:
>
> Hallo all,
>
> I'm currently trying to optimize one of my queries wich includes two
> in (...) statements. Can't post the query right now, 'cause Firebird
> broke down.
>
> where
> Field1 in (1,2,3) and
> Field2 in (1,2)
>
> This query takes ages. I tried to replace the in (...) statements
> with:
>
> where
> Field1 = 1 and
> Field2 = 1
>
> union all
>
> where
> Field1 = 1 and
> FIeld2 = 2
>
> ....
>
> This runs much faster. Isn't there an easier way?