Re: Suboptimal query plan fixed by replacing OR with UNION - Mailing list pgsql-general

From Tom Lane
Subject Re: Suboptimal query plan fixed by replacing OR with UNION
Date
Msg-id 2555.1341528681@sss.pgh.pa.us
Whole thread Raw
In response to Suboptimal query plan fixed by replacing OR with UNION  (Steven Schlansker <steven@likeness.com>)
Responses Re: Suboptimal query plan fixed by replacing OR with UNION  (Steven Schlansker <steven@likeness.com>)
List pgsql-general
Steven Schlansker <steven@likeness.com> writes:
> Why is using an OR so awful here?

Because the OR stops it from being a join (it possibly needs to return
some rows that are not in the semijoin of the two tables).

> Why does it pick a sequential scan?  Is this an optimizer bug

No.  It can't transform OR into a UNION because the results might not
be the same.  I assume you don't care about removal of duplicates, or
have some reason to know that there won't be any ... but the planner
doesn't know that.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Server writing short WAL files
Next
From: Simon Riggs
Date:
Subject: Re: Packt's PostgreSQL 9 Administration Cookbook: LITE Editions?