| От | Christoph Haller |
|---|---|
| Тема | Re: Group by, count, order by and limit |
| Дата | |
| Msg-id | 3E52085D.AC957AD0@rodos.fzk.de обсуждение |
| Ответ на | Group by, count, order by and limit (Anuradha Ratnaweera <anuradha@lklug.pdn.ac.lk>) |
| Список | pgsql-hackers |
> > Consider this query on a large table with lots of different IDs: > > SELECT id FROM my_table GROUP BY id ORDER BY count(id) LIMIT 10; > > It has an index on id. Obviously, the index helps to evaluate count(id) > for a given value of id, but count()s for all the `id's should be > evaluated, so sort() will take most of the time. > > Is there a way to improve performance of this query? If not, please > give some indication to do a workaround on the source itself, so perhaps > I may be able to come out with a patch. > Is there a difference in performance if you re-write it as SELECT id, count(id) FROM my_table GROUP BY id ORDER BY 2 LIMIT 10 ; ? Regards, Christoph
В списке pgsql-hackers по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера