Probably, the sequential scan was faster. There is a big cost to jumping all over
the place, loading both the index pages and the data pages. Typically, it is about 10% of the data volume
for a file, but I don’t know what the metric is for PostgreSQL. If you want to force the index behavior,
you might try finding out how many items you can put into a IN list, and then
repeating it with E.g.: SELECT * FROM table_name WHERE id IN
(2,4,6,8) SELECT * FROM table_name WHERE id IN (1,2,3,4) SELECT * FROM table_name WHERE id IN (9,121,13,14) Etc. I am guessing that the sequential scan is
faster. You could also try OR lists, which accomplish
the same thing. You might also select the ID values into a
temporary table and then do a join. I am guessing that the join query would
work pretty well. Give it a try and see, and then tell us
what you saw. From:
pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Surabhi Ahuja I have a
table where the primary key "id" is a serial key. |