Re: Poor query plan across OR operator - Mailing list pgsql-performance

From Tom Lane
Subject Re: Poor query plan across OR operator
Date
Msg-id 14275.1264524114@sss.pgh.pa.us
Whole thread Raw
In response to Poor query plan across OR operator  (Mark Hills <Mark.Hills@framestore.com>)
Responses Re: Poor query plan across OR operator
List pgsql-performance
Mark Hills <Mark.Hills@framestore.com> writes:
> One of our most-used queries performs poorly (taking over 2 seconds) and a
> tiny amount of refactoring shows it can be fast (less than 1ms) by
> transforming the OR case (which spans two tables) into a UNION.

I'd suggest going with the UNION.  We are unlikely to make the planner
look for such cases, because usually such a transformation would be a
net loss.  It seems like rather a corner case that it's a win even on
your example.

            regards, tom lane

pgsql-performance by date:

Previous
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: Poor query plan across OR operator
Next
From: Richard Neill
Date:
Subject: Should the optimiser convert a CASE into a WHERE if it can?