Hello,
Assuming I have a huge table (doesn't fit in RAM), of which the most
important fields are "id" which is a SERIAL PRIMARY KEY and "active"
which is a boolean, and I'm issuing a query like:
SELECT * FROM table ORDER BY id DESC LIMIT 10
... is pgsql smart enough to use the index to fetch only the 10
required rows instead of reading the whole table, then sorting it,
then trimming the result set? How about in the following queries:
SELECT * FROM table ORDER BY id DESC LIMIT 10 OFFSET 10
SELECT * FROM table WHERE active ORDER BY id DESC LIMIT 10 OFFSET 10
Or, more generally, is there some set of circumstances under which the
catastrophic scenario will happen?