| От | Tom Lane |
|---|---|
| Тема | Re: slow query using sub select |
| Дата | |
| Msg-id | 15852.1148339244@sss.pgh.pa.us обсуждение |
| Ответ на | slow query using sub select ("Tim Jones" <TJones@optio.com>) |
| Список | pgsql-performance |
"Tim Jones" <TJones@optio.com> writes:
> I am having a problem with a sub select query being kinda slow. The
> query is as follows:
> select batterycode, batterydescription, observationdate from Battery t1
> where patientidentifier=611802158 and observationdate = (select
> max(observationdate) from Battery t2 where t2.batterycode=t1.batterycode
> and patientidentifier=611802158) order by batterydescription.
Yeah, this is essentially impossible for the planner to optimize,
because it doesn't see any way to de-correlate the subselect, so it does
it over again for every row. You might find it works better if you cast
the thing as a SELECT DISTINCT ON problem (look at the "weather report"
example in the SELECT reference page).
regards, tom lane
В списке pgsql-performance по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера