[Info-Ingres] To order by, or NOT to order by

Laframboise André andre.laframboise at lac-bac.gc.ca
Mon Dec 10 23:52:44 CST 2007


I realize the 'order by' question has been discussed to death and I'm
likely just opening a can of worms, but please bare with me.
 
I have a case that I can't explain.
 
I have a 35 million row table with some varchar columns.
These varchar columns have  secondary indexes.
 
If I do a wildcard range search on one of the varchars, i.e. >='aa%'
with an order by on the varchar, the optimizer decides to 
ignore the secondary indexes because I'm calling back most 
of the rows (according to the stats). The QEP ends up doing a scan, 
then sorts the result set. Takes a very long time. Fair enough.
 
But, if i drop or ignore the stats, the QEP will use the secondary and return
results almost instantly. The order by obviously didn't sort anything. Does
this mean the optimizer thought the 'order by' was redundant and returned 
the rows according to the order in the secondary index ? 
 
I know were not supposed to rely on the row order in any tables or indexes.
 
Andre



More information about the Info-Ingres mailing list