Subject Re: [ib-support] Problem with plan selection - doesn't seem right (Resubmit)
Author Arno Brinkman
Hi,

> how can this possibly be the best index? Michael is selecting MAX and has
> defined a descending index. Even if there is a couple of duplicates, I
> would believe "ORDERSDBYSEQNUM" to be the best choice.

No, Sean is right.
An index for MAX() is used when the ORDER of the query is determined.
for example: PLAN (ORDERSD ORDER ORDERSDBYSEQNUM)
But because the resultset is depended from od_om_id no index can be used for
the MAX(). Indices for Aggregate functions are added to the sort-clause.

> Are you saying that Fb/IB would choose "ORDERSDBYSEQNUM" if he changed it
to
> CREATE DESCENDING INDEX ORDERSDBYSEQNUM ON ORDERSD (OD_OM_ID, OD_SEQNUM,
> OD_ID);?

Only if it has an better selectivity.

Regards,
Arno