Re: Any better plan for this query?.. - Mailing list pgsql-performance

From Simon Riggs
Subject Re: Any better plan for this query?..
Date
Msg-id 1242739192.14551.204.camel@ebony.2ndQuadrant
Whole thread Raw
In response to Re: Any better plan for this query?..  (Matthew Wakeling <matthew@flymine.org>)
List 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


pgsql-performance by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Any better plan for this query?..
Next
From: Scott Carey
Date:
Subject: Re: Any better plan for this query?..