Re: [GENERAL] Suboptimal query plan fixed by replacing OR with UNION

2012-07-09 Thread Steven Schlansker
On Jul 6, 2012, at 9:24 PM, Gurjeet Singh wrote: > On Thu, Jul 5, 2012 at 7:16 PM, Steven Schlansker wrote: > > On Jul 5, 2012, at 3:51 PM, Tom Lane wrote: > > > Steven Schlansker writes: > >> Why is using an OR so awful here? > > > > Because the OR stops it from being a join (it possibly need

Re: [GENERAL] Suboptimal query plan fixed by replacing OR with UNION

2012-07-06 Thread Gurjeet Singh
On Thu, Jul 5, 2012 at 7:16 PM, Steven Schlansker wrote: > > On Jul 5, 2012, at 3:51 PM, Tom Lane wrote: > > > Steven Schlansker writes: > >> Why is using an OR so awful here? > > > > Because the OR stops it from being a join (it possibly needs to return > > some rows that are not in the semijoin

Re: [GENERAL] Suboptimal query plan fixed by replacing OR with UNION

2012-07-06 Thread Steven Schlansker
On Jul 5, 2012, at 6:35 PM, Jasen Betts wrote: > I note you've decided to rewrite this query as a union > >> SELECT * FROM account >> WHERE user_id in >>(SELECT user_id FROM account >> WHERE id = >> ANY('{-02f6-379d-c000-00026810,-0320-b467-c000-00026810,000

Re: [GENERAL] Suboptimal query plan fixed by replacing OR with UNION

2012-07-05 Thread Jasen Betts
I note you've decided to rewrite this query as a union > SELECT * FROM account > WHERE user_id in > (SELECT user_id FROM account > WHERE id = > ANY('{-02f6-379d-c000-00026810,-0320-b467-c000-00026810,-000d-cefb-c000-00026810}')) > OR > id =

Re: [GENERAL] Suboptimal query plan fixed by replacing OR with UNION

2012-07-05 Thread Steven Schlansker
On Jul 5, 2012, at 3:51 PM, Tom Lane wrote: > Steven Schlansker writes: >> Why is using an OR so awful here? > > Because the OR stops it from being a join (it possibly needs to return > some rows that are not in the semijoin of the two tables). > >> Why does it pick a sequential scan? Is this

Re: [GENERAL] Suboptimal query plan fixed by replacing OR with UNION

2012-07-05 Thread Tom Lane
Steven Schlansker writes: > Why is using an OR so awful here? Because the OR stops it from being a join (it possibly needs to return some rows that are not in the semijoin of the two tables). > Why does it pick a sequential scan? Is this an optimizer bug No. It can't transform OR into a UNION