Gerald Gutierrez <gml1(at)coldresist(dot)com> writes:
> I'd like to get the row with ID=4. I've tried:
> SELECT * FROM mytable WHERE id=(SELECT MAX(id) FROM mytable);
> The subquery can take a /really/ long time on a table that is large. The query:
> SELECT * FROM mytable ORDER BY id DESC LIMIT 1;
> doesn't seem to help very much.
It should help a lot, if you have an index on id. Have you vacuum
analyzed the table recently?
regards, tom lane