EspressoSystems / hotshot-query-service

Generic query service for HotShot applications
https://espressosystems.github.io/hotshot-query-service/
GNU General Public License v3.0
5 stars 1 forks source link

Fix multi-column ORDER BY clauses #736

Closed jbearer closed 1 week ago

jbearer commented 1 week ago

Postgres treats ORDER BY (col1, col2) [DESC] very differently from ORDER BY col1 [DESC], col2 [DESC]. If there is a multi-column index on (col1, col2), only the latter (without parentheses) will use the index. This is causing some extremely slow queries on Decaf and Mainnet, particularly in the block explorer; these are queries which should be almost trivial.

This may overlap a bit with work done in #728 , however this PR is specifically meant to address this issue exhaustively, and to be standalone, so hopefully we can merge this very quickly, as it's a huge performance improvement.

This PR:

This changes fixes every occurence of these type of queries.