Consider the following table structure:
create table feed
(
id bigserial primary key,
event_date timestamp(0) not null,
...
);
create index feed_event_date_index on feed (event_date desc);
And the following query:
explain analyze select * from feed order by event_date desc
Sort (cost=1.02..1.02 rows=1 width=117) (actual time=0.051..0.052 rows=11 loops=1)
Sort Key: event_date DESC
Sort Method: quicksort Memory: 26kB
-> Seq Scan on feed (cost=0.00..1.01 rows=1 width=117) (actual time=0.032..0.035 rows=11 loops=1)
Planning Time: 0.130 ms
Execution Time: 0.161 ms
Apparently, feed_event_date_index
has not been taken into the account.
P.S. table has ~1000 records
My idea is to index table by date, because this is how I'm planning to search records in it in all the queries.