Re: faster SELECT - Mailing list pgsql-general

From Tom Lane
Subject Re: faster SELECT
Date
Msg-id 3872.1078759419@sss.pgh.pa.us
Whole thread Raw
In response to Re: faster SELECT  (Andrew Rawnsley <ronz@ravensfield.com>)
List pgsql-general
Andrew Rawnsley <ronz@ravensfield.com> writes:
> It is a fairly well known optimization in Oracle (at least with the
> rule-based optimizer, and IIRC non-indexed clauses) to optimize the
> WHERE clause right to left.

That rule doesn't apply to Postgres, though.

If the optimizer does not have any reasons of its own to reorganize the
query (and that's a pretty big "if") then the WHERE clauses will get
evaluated left-to-right.  So if you know which clause is more selective,
write it first.

In practice this really only applies to restriction clauses
(single-relation tests) that are not going to be implemented via an
index scan.  Join and index clauses will get sliced, diced, and used
no matter what order you list 'em in.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: postmaster freeze
Next
From: "Markus Wollny"
Date:
Subject: Character Encoding Confusion