I have a very large table with 100M+ rows. I am trying to find if there is a faster way to execute the following.
Query:
SELECT *
FROM "public".example
WHERE a = "foo" and b = "bar"
order by c /* could be any of fields c to z */
limit 100;
Here is the table and indexes I have setup now.
Table:
- id
- a (string)
- b (string)
- c ... z (all integers)
Indexes:
"example_multi_idx" btree (a, b)
"c_idx" btree (c)
Thoughts:
- If I was only sorting by
cthen an index of"example_multi_idx_with_c" btree (a, b, c)performs wonderfully. However, if I throw in a variety of sort by's, then I would need to create n number of multi-key indexes, which seems wasteful.