Re: Planning without reason.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Tzahi Fadida <Tzahi(dot)ML(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Planning without reason.
Date: 2006-06-23 16:28:16
Message-ID: 16403.1151080096@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> On Fri, Jun 23, 2006 at 03:57:19PM +0300, Tzahi Fadida wrote:
>> (SELECT * FROM R
>> WHERE a=3, b=6,. ...)
>> UNION
>> (SELECT * FROM R
>> WHERE b=5, d=2,. ...)
>> UNION
>> ....
>> And lots of unions.

> Do you need UNION, or do you actually mean UNION ALL?

> Also, couldn't you just do:

> SELECT * FROM R
> WHERE (a=3, b=6, ...)
> OR (b=5, d=2, ...)
> etc

That seems to be what Tzahi wants the system to do for him. But the OR
format is not in general logically equivalent to either UNION or UNION
ALL, because UNION would cause duplicate output rows to be suppressed
whereas UNION ALL could allow the same table row to be emitted multiple
times (if two different WHERE conditions could select the same row).

It's conceivable that the planner could prove that neither effect is
possible in a particular query and then make the transformation
automatically, but I'm not about to expend that kind of planning effort
on such an odd case --- checking for it would waste entirely too many
cycles in most cases.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-06-23 16:31:51 Re: Overhead for stats_command_string et al, take 2
Previous Message Hannu Krosing 2006-06-23 16:27:53 Re: vacuum, performance, and MVCC