Performance problem with correlated sub-query

Поиск
Список
Период
Сортировка
От Howard, Steven (US - Tulsa)
Тема Performance problem with correlated sub-query
Дата
Msg-id B01CED063D983443814231E600C9AB7B059629@uscnt0416.us.deloitte.com
обсуждение исходный текст
Ответы Re: Performance problem with correlated sub-query  (Mike Mascari <mascarm@mascari.com>)
Re: Performance problem with correlated sub-query  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: Performance problem with correlated sub-query  (Shridhar Daithankar <shridhar@frodo.hserus.net>)
Список pgsql-general

I have created a web app that stores and displays all the messages from my database maintenance jobs that run each night. The web app uses Java servlets and has PostgreSQL 7.0 as the back end.

 

When the user requests the first page, he gets a list of all the servers with maintenance records in the database, and a drop down list of all the dates of maintenance records. If the user chooses a date first, then the app uses a prepared statement with the date contained in a parameter, and this executes very quickly – no problems.

 

However, if the web page user does not choose a date, then the app uses a correlated sub-query to grab only the current (latest) day’s maintenance records. The query that is executed is:

 

select servername, databasename, message from messages o where o.date_of_msg =

            (select max(date_of_msg) from messages i where i.servername = o.servername);

 

And this is a dog. It takes 15 – 20 minutes to execute the query (there are about 200,000 rows in the table). I have an index on (servername, date_of_msg), but it doesn’t seem to be used in this query.

 

Is there a way to improve the performance on this query?

 

Thanks,

 

Steve Howard

 


This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, you should delete this message. Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.

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

Предыдущее
От: Tatsuo Ishii
Дата:
Сообщение: Re: Postgre and Web Request
Следующее
От: Edmund Dengler
Дата:
Сообщение: Unable to use index?