Re: Any better plan for this query?..

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Matthew Wakeling <matthew(at)flymine(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dimitri <dimitrik(dot)fr(at)gmail(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Dimitri Fontaine <dfontaine(at)hi-media(dot)com>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Aidan Van Dyk <aidan(at)highrise(dot)ca>, Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Any better plan for this query?..
Date: 2009-05-19 13:19:52
Message-ID: 1242739192.14551.204.camel@ebony.2ndQuadrant
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On Tue, 2009-05-19 at 13:01 +0100, Matthew Wakeling wrote:

> That leads me on to another topic. Consider the query:
>
> SELECT * FROM table ORDER BY a, b
>
> where the column "a" is declared UNIQUE and has an index. Does Postgres
> eliminate "b" from the ORDER BY, and therefore allow fetching without
> sorting from the index?

No, because we don't use unique constraints much at all to infer things.

> Or how about this query:
>
> SELECT * FROM table1, table2 WHERE table1.fk = table2.id ORDER BY
> table1.id, table2.id
>
> where both "id" columns are UNIQUE with an index. Do we eliminate
> "table2.id" from the ORDER BY in this case?

Yes, that is eliminated via equivalence classes.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Simon Riggs 2009-05-19 13:35:37 Re: Any better plan for this query?..
Previous Message Simon Riggs 2009-05-19 13:10:29 Re: Any better plan for this query?..