Re: Re-ordering of OR conditions

From: "Jim Nasby" <jim(dot)nasby(at)enterprisedb(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "PostgreSQL-development Development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re-ordering of OR conditions
Date: 2007-02-09 16:50:20
Message-ID: EA959EAD-996D-449B-8FA2-7EA8960E46A6@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Feb 9, 2007, at 10:46 AM, Tom Lane wrote:
> "Jim Nasby" <jim(dot)nasby(at)enterprisedb(dot)com> writes:
>> IF I run the following with the a < 2900 condition first, the more
>> expensive EXISTS only gets executed when needed, but if I change the
>> order of the OR's, the EXISTS is always executed. It would be good if
>> the optimizer could re-order the OR conditions based on estimated
>> cost (granted, this wouldn't work very well if you've got functions
>> in the OR, but it'd still be useful):
>
> I looked at this for a bit. It's in principle do-able but I'm not
> sure it's a good idea. The problem is that while AND'ed condition
> lists are usually fairly short and hence cheap to sort, OR'ed
> condition
> lists are not infrequently very long --- nobody blinks an eye at
> hundreds of items in an IN-list for instance. I'm afraid we'd waste
> a lot more cycles sorting than we could hope to regain.

Do people actually do that with OR lists though? My understanding is
that now IN lists are converted to arrays, so I'd think that wouldn't
be an issue there.

Is it easy for the planner to discern between simple OR expressions
and stuff like EXISTS? If so it might be worth automatically pushing
EXISTS to the end...
--
Jim Nasby jim(dot)nasby(at)enterprisedb(dot)com
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2007-02-09 16:58:48 Re: Proposal: TABLE functions
Previous Message Gregory Stark 2007-02-09 16:50:05 Re: Variable length varlena headers redux