| От | Tom Lane |
|---|---|
| Тема | Re: Performance problems with DISTINCT ON |
| Дата | |
| Msg-id | 29240.1254624784@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Performance problems with DISTINCT ON ("Sgarbossa Domenico" <domenico.sgarbossa@eniac.it>) |
| Список | pgsql-performance |
"Sgarbossa Domenico" <domenico.sgarbossa@eniac.it> writes:
> I guess the right query is:
> select distinct on (articolo) articolo,data_ent,prezzo from listini_anagrafici order by articolo, data_ent desc
> but it seems that this query runs slowly... about 5/6 seconds.
> I've tried adding this index
> CREATE INDEX articolo_data_ent ON listini_anagrafici (articoli, data_ent)
> but it doesn't helps.
That index doesn't match the query ordering. You could do
select distinct on (articolo) articolo,data_ent,prezzo from listini_anagrafici order by articolo desc, data_ent desc
In more recent versions of Postgres you could make an index with one
column ascending and the other descending, but AFAIR 8.1 doesn't have
that.
regards, tom lane
В списке pgsql-performance по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера