This might not be new for some but I though of posting it here for others :
Database : Any version
Optimizer : RULE (or CHOOSE without stats)
A table has two indexes with 3 and 5 columns respectively in them. A query uses first column (and only that column) from both these indexes in its WHERE clause. The plan shows INDX_1 (with 3 columns) being used.
The table was reoraganized and both the indexes recreated. Now, the plan for the same query shows INDX_2 being used. Use of this index is not proper because it is less selective and hence slows down the query.
WHY IS THE CHANGE IN THE PLAN ? How reorg affected plan ?
Answer is : For typical queries like those described above - using one (which is the leading column) column from more than one indexes in the WHERE clause, the RBO decides to use the index that was 'created' LAST !!
So, in my case, before reorg, INDX_1 had a later 'created' timestamp than that for INDX_2 and it was getting used. During reorg, it happened that INDX_2 got created after INDX_1 and the RBO started using INDX_2.
It turns out that this is a 'documented' stuff.
Isn't this interesting ? And : all you DBAs that take care of databases running under RBO take care of this when you decide to reorg a table and its indexes ? Moreover, this rule is applicable to PK as well !!
Any comments ?
[Edited by svk on 01-04-2002 at 11:44 AM]
