Re: Inoptimal query plan for max() and multicolumn index - Mailing list pgsql-performance

From F. BROUARD / SQLpro
Subject Re: Inoptimal query plan for max() and multicolumn index
Date
Msg-id 4E00771E.80403@club-internet.fr
Whole thread Raw
In response to Re: Inoptimal query plan for max() and multicolumn index  (Vladimir Kulev <me@lightoze.net>)
List pgsql-performance
Le 20/06/2011 18:08, Vladimir Kulev a écrit :
>
> Yes, exactly :)

SQL Server does it but PG does not. Expect this for the future....

So try to rewrite the query like this :

select max(timestamp) from sms where number = '5502712'
UNIUON ALL,
select max(timestamp) from sms where number = '5802693'
UNION ALL
select max(timestamp) from sms where number = '5801981'

To see what happen to the query plan !

A +

>
> On Mon, Jun 20, 2011 at 7:41 PM, Kevin Grittner
> <Kevin.Grittner@wicourts.gov>  wrote:
>> I expect you're hoping for a plan similar to what this gives you?:
>>
>> explain analyze select greatest(
>>   (select max(timestamp) from sms where number = '5502712'),
>>   (select max(timestamp) from sms where number = '5802693'),
>>   (select max(timestamp) from sms where number = '5801981'));
>


--
Frédéric BROUARD - expert SGBDR et SQL - MVP SQL Server - 06 11 86 40 66
Le site sur le langage SQL et les SGBDR  :  http://sqlpro.developpez.com
Enseignant Arts & Métiers PACA, ISEN Toulon et CESI/EXIA Aix en Provence
Audit, conseil, expertise, formation, modélisation, tuning, optimisation
*********************** http://www.sqlspot.com *************************


pgsql-performance by date:

Previous
From: Yeb Havinga
Date:
Subject: Re: Contemplating SSD Hardware RAID
Next
From: Florian Weimer
Date:
Subject: Re: Contemplating SSD Hardware RAID