Re: Suboptimal query plan fixed by replacing OR with UNION

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steven Schlansker <steven(at)likeness(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, David Stryker <stryker(at)likeness(dot)com>
Subject: Re: Suboptimal query plan fixed by replacing OR with UNION
Date: 2012-07-05 22:51:21
Message-ID: 2555.1341528681@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steven Schlansker <steven(at)likeness(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2012-07-05 22:53:13 Re: Packt's PostgreSQL 9 Administration Cookbook: LITE Editions?
Previous Message Tom Lane 2012-07-05 22:00:02 Re: Server writing short WAL files