Re: UNION or OR / INTERSECT or AND ?

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: "David W" <willou(dot)d(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: UNION or OR / INTERSECT or AND ?
Date: 2006-02-07 22:54:10
Message-ID: 700D8611-7875-49CE-988A-175E31053884@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Feb 7, 2006, at 23:04 , David W wrote:

> do i have to prefered to use UNION and INTERSECT or is it better with
> OR and AND ?

In general, EXPLAIN ANALYZE is your friend. I suspect using OR will
be better (and that's only a suspicion), but by using EXPLAIN ANALYZE
you can see exactly how the server is planning the queries based on
your actual situation (as long as your statistics are accurate. See
ANALYZE as well).

[EXPLAIN](http://www.postgresql.org/docs/current/interactive/sql-
explain.html)
[ANALYZE](http://www.postgresql.org/docs/current/interactive/sql-
analyze.html)

Once you've got some good EXPLAIN ANALYZE output, people on the
performance list may be able to help out if you still have questions.

http://archives.postgresql.org/pgsql-performance/

Michael Glaesemann
grzm myrealbox com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2006-02-08 00:00:00 Re: Clarification Regarding Vacuum and template1
Previous Message Tom Lane 2006-02-07 22:13:29 Re: B-tree performance improvements in 8.x