I have a query in the form:
select a, b, c, d, e, f, g, h,
row_number () over (partition by a, b order by c, d, e, f) as order
from table;
And it’s performance is kind of terrible.
We have tried creating 2 indexes, the first for the partition by columns (a and b) and the second for the order by columns (c, d, e, f).
Using the explain plan we have found that indexes are not being used. Altough they are usefeul for other querys with a group by clause.
Any idea on how to refactor the query, or re-create the indexes so that they help with performance on this query?
Thanks in advance
To quote from a previous answer of mine:
In your case, you’re selecting everything from the table so I’m guessing 1. is the main reason, in which case you’re hosed.
You could try the index
a, b, c, d, e, f, and I’m not saying that gathering statistics won’t help. If you haven’t I’d recommend doing it anyway:There’s also the remote possibility that your table is massively fragmented. If so
alter table my_table moveand then gather statistics.