Subject Re: Re[2]: [ib-support] WHERE optimization
Author Arno Brinkman
Hi,

> >>Does anybody know the order in which the predicates from the WHERE
clause
> >>of a SELECT statement execute.
> >>
> >>For example
> >>
> >>WHERE
> >> PREDICATE_1 and PREDICATE_2 and PREDICATE_3
> >>
> >>which one is first
>
> > I think this is determined by the plan. The plan tries to retrieve the
> > records as cheap as possible, and will start by evaluating what it
> > perceives to be the most restrictive predicate having an index (please
> > correct me if I'm wrong).
>
> I think it might also depend if some of those predicates are grouped
> together by parentheses(ex. "(PREDICTATE_1 AND PREDICATE_2) AND
> PREDICATE_3" ). And even using an OR might change things too. One
> thing I noticed is that the optimizer seems to try to use indices that
> englobe fields used in more than one predicate.
>
> Maybe someone with more knowledge of the optimizer can give a better
> answer(Arno!?).

Ordering has no effect on the execute. The optimizer consider all predicates
in the where-clause. It also eliminate duplicates and makes new predicates
from other predicates when possible. I hope you can somewhat with this
information ?

Regards,
Arno