Re: select max(field) from table much faster with a group by clause?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: select max(field) from table much faster with a group by clause?
Дата
Msg-id 4305.1193924619@sss.pgh.pa.us
обсуждение исходный текст
Ответ на select max(field) from table much faster with a group by clause?  (Palle Girgensohn <girgen@pingpong.net>)
Ответы Re: select max(field) from table much faster with a group by clause?
Re: select max(field) from table much faster with a group by clause?
Список pgsql-performance
Palle Girgensohn <girgen@pingpong.net> writes:
> When running
>  select max("when") from login where userid='userid'
> it takes a second or two, but when adding "group by userid" the planner
> decides on using another plan, and it gets *much* faster. See example below.

It's only faster for cases where there are few or no rows for the
particular userid ...

> Number of tuples per user varies from zero to a couple of thousands.

The planner is using an intermediate estimate of 406 rows.  You might be
well advised to increase the statistics target for login.userid --- with
luck that would help it to choose the right plan type for both common
and uncommon userids.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [Fwd: Re: Outer joins and Seq scans]
Следующее
От: Palle Girgensohn
Дата:
Сообщение: Re: select max(field) from table much faster with a group by clause?