Re: Re-ordering of OR conditions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Re-ordering of OR conditions
Date
Msg-id 1297.1171039576@sss.pgh.pa.us
Whole thread Raw
In response to Re-ordering of OR conditions  ("Jim Nasby" <jim.nasby@enterprisedb.com>)
Responses Re: Re-ordering of OR conditions  ("Jim Nasby" <jim.nasby@enterprisedb.com>)
Re: Re-ordering of OR conditions  ("Simon Riggs" <simon@2ndquadrant.com>)
List pgsql-hackers
"Jim Nasby" <jim.nasby@enterprisedb.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.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: possible TODOs
Next
From: Gregory Stark
Date:
Subject: Re: Variable length varlena headers redux