Gerald Gutierrez writes:
> 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. What query is the fastest at getting this row?
One of these two. ;-)
The second is generally thought to be faster, at least if you use the
latest version of PostgreSQL.
> A related question is: is there a way to time a query in psql, like the
> client of MySQL does?
Not in a built-in way.
--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter