I have a table with > 4.5 million rows and my SELECT query is far too slow for my needs.
The table is created with:
CREATE TABLE all_leg
The index won't help.
Two solutions:
You chould either change the query to:
WHERE dep_dt >= '2017-08-15 00:00:00' AND dep_dt < '2017-08-16 00:00:00'
Then the index can be used.
Create an index on an expression:
CREATE INDEX ON all_legs(((dep_dt AT TIME ZONE 'UTC')::date));
(or a different time zone) and change the query to
WHERE (dep_dt AT TIME ZONE 'UTC')::date = '2017-08-16'
The AT TIME ZONE is necessary because otherwise the result of the cast would depend on your current TimeZone setting.
The first solution is simpler, but the second has the advantage that you can add price_ct to the index like this:
CREATE INDEX ON all_legs(((dep_dt AT TIME ZONE 'UTC')::date), price_ct);
Then you don't need a sort any more, and your query will be as fast as it can theoretically get.