| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
| Cc: | Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: EXISTS clauses not being optimized in the face of 'one time pass' optimizable expressions |
| Date: | 2016-07-01 14:11:09 |
| Message-ID: | 18138.1467382269@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Fri, Jul 1, 2016 at 9:52 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Maybe, but neither UNION nor UNION ALL would duplicate the semantics
>> of OR, so there's some handwaving here that I missed.
> SELECT * FROM foo WHERE a = 5 OR a = 4
> isn't equivalent to
> SELECT * FROM foo WHERE a = 5
> UNION
> SELECT * FROM foo WHERE a = 4
> ?
It probably is, but you're assuming that "a" appears in the list of
columns being unioned. If you make that just "SELECT b FROM ..."
then the latter form gets rid of duplicate b values where the first
doesn't. On the other hand, UNION ALL might introduce duplicates
not present in the OR query's result.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2016-07-01 14:15:00 | Re: Postgres_fdw join pushdown - wrong results with whole-row reference |
| Previous Message | Amit Kapila | 2016-07-01 14:09:17 | Re: Documentation fixes for pg_visibility |