Subject | Re: [firebird-support] Re: Index not picked up by optimizer |
---|---|
Author | Ann W. Harrison |
Post date | 2007-03-02T22:20:55Z |
dr_bentonquest wrote:
distribution of values in the index. One is that the majority of the
entries will be NOT any particular value. So it won't use an index
if the conjunct is <field> NE <value> or NOT (<field> EQ <value>).
If there were no other index, it would use the compound index because
it can use the first term, but searching a smaller index is faster
than searching a larger one, so CUSTOMER is favored over CUSTOMER +
some unusable term.
Regards,
Ann
> Strange, isn't it? The index is picked up when using "greater thanAh! that's the clue. The optimizer makes some assumptions about the
> zero", but it is NOT when using "different than zero" (<> symbol) or
> "not equal to zero" (not field_name=0) or with your suggestion
> (field_name+0 <> 0)
>
> I should add this: When using "<>0" and "not field_name=0" the proper
> index is NOT picked up, but another index is. In this cases, the
> optimizer chooses an index that contains only the first field,
> CUSTOMER, because this field is a FK on the table and a RDB$FOREIGN
> index exists for it.
distribution of values in the index. One is that the majority of the
entries will be NOT any particular value. So it won't use an index
if the conjunct is <field> NE <value> or NOT (<field> EQ <value>).
If there were no other index, it would use the compound index because
it can use the first term, but searching a smaller index is faster
than searching a larger one, so CUSTOMER is favored over CUSTOMER +
some unusable term.
Regards,
Ann