0
where x and y and z

or

where y and z and x

Is there a difference in terms of performance and how does the PostgreSQL filter?
Where can I find documentation on this?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
ali
  • 25
  • 1
  • 1
  • 9
  • possible duplicate of [SQL question: Does the order of the WHERE clause make a difference?](http://stackoverflow.com/questions/1458060/sql-question-does-the-order-of-the-where-clause-make-a-difference) – Tim Radcliffe Jul 04 '13 at 12:19
  • but i'm asking how does the postgresql planner handle this? – ali Jul 04 '13 at 13:08

2 Answers2

3

SQL is not a procedural language. The order in which WHERE conditions appear is completely irrelevant. PostgreSQL will evaluate the whole expression for every row, but decide where and when to apply each expression according to the query plan.

Just make sure that you get the logic straight according to operator precedence.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
1

Just prepend your query with EXPLAIN and you will see nice information about what planner is really planning.
http://www.postgresql.org/docs/9.2/static/sql-explain.html

ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46