Re: Getting row with id=max(id)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Getting row with id=max(id)
Дата
Msg-id 10021.992018040@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Getting row with id=max(id)  (Gerald Gutierrez <gml1@coldresist.com>)
Список pgsql-sql
Gerald Gutierrez <gml1@coldresist.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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Re: About i8n
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Re: [HACKERS] Re: behavior of ' = NULL' vs. MySQL vs. Standards