Re: [HACKERS] LATERAL quals revisited

2013-08-19 Thread Tom Lane
Some time ago, I wrote: > I've been studying the bug reported at > http://www.postgresql.org/message-id/20130617235236.GA1636@jeremyevans.local > ... > After some contemplation, I think that the most practical way to fix > this is for deconstruct_recurse and distribute_qual_to_rels to > effectively

Re: [HACKERS] LATERAL quals revisited

2013-08-14 Thread Tom Lane
Antonin Houska writes: > On 07/04/2013 06:11 PM, Antonin Houska wrote: >> On 07/03/2013 08:32 PM, Tom Lane wrote: >>> Another possibility would be to keep the optimization, but disable it in >>> queries that use LATERAL. I don't much care for that though --- seems >>> too Rube Goldbergish, and in

Re: [HACKERS] LATERAL quals revisited

2013-07-19 Thread Tom Lane
Ashutosh Bapat writes: > On Wed, Jun 26, 2013 at 1:30 AM, Tom Lane wrote: >> For there to *be* a unique "appropriate outer join", we need to require >> that a LATERAL-using qual clause that's under an outer join contain >> lateral references only to the outer side of the nearest enclosing outer >

Re: [HACKERS] LATERAL quals revisited

2013-07-19 Thread Ashutosh Bapat
I have couple of questions. On Wed, Jun 26, 2013 at 1:30 AM, Tom Lane wrote: > I've been studying the bug reported at > > http://www.postgresql.org/message-id/20130617235236.GA1636@jeremyevans.local > that the planner can do the wrong thing with queries like > > SELECT * FROM > i LEFT JOIN LAT

Re: [HACKERS] LATERAL quals revisited

2013-07-12 Thread Antonin Houska
On 07/04/2013 06:11 PM, Antonin Houska wrote: On 07/03/2013 08:32 PM, Tom Lane wrote: Another possibility would be to keep the optimization, but disable it in queries that use LATERAL. I don't much care for that though --- seems too Rube Goldbergish, and in any case I have a lot less faith in t

Re: [HACKERS] LATERAL quals revisited

2013-07-04 Thread Antonin Houska
On 07/03/2013 08:32 PM, Tom Lane wrote: Another possibility would be to keep the optimization, but disable it in queries that use LATERAL. I don't much care for that though --- seems too Rube Goldbergish, and in any case I have a lot less faith in the whole concept now than I had before I starte

Re: [HACKERS] LATERAL quals revisited

2013-07-03 Thread Tom Lane
I wrote: > So attached is a draft patch for this. It's not complete yet because > there are various comments that are now wrong and need to be updated; > but I think the code is functioning correctly. Hm, spoke too soon :-(. This query causes an assertion failure, with or without my draft patch:

Re: [HACKERS] LATERAL quals revisited

2013-06-26 Thread Tom Lane
Antonin Houska writes: > If the WHERE clause moves up, then the resulting plan might be less > efficient than the one we'd get if the subquery hadn't been pulled-up at > all. No, because we can push the qual back down again (using a parameterized path) if that's appropriate. The problem at thi

Re: [HACKERS] LATERAL quals revisited

2013-06-26 Thread Antonin Houska
On 06/26/2013 12:52 AM, Tom Lane wrote: Instead of setting it aside, can we (mis)use placeholder var (PHV), to ensure that the WHERE clause is evaluated below the OJ; instead of combining it with the ON clause? No, that doesn't help; it has to be part of the joinquals at the join node, or you do

Re: [HACKERS] LATERAL quals revisited

2013-06-25 Thread Tom Lane
Antonin Houska writes: > On 06/25/2013 10:00 PM, Tom Lane wrote: >> After some contemplation, I think that the most practical way to fix >> this is for deconstruct_recurse and distribute_qual_to_rels to >> effectively move such a qual to the place where it logically belongs; >> that is, rather tha

Re: [HACKERS] LATERAL quals revisited

2013-06-25 Thread Antonin Houska
(Please excuse me if my proposal sounds silly, i'm still not too advanced in this area...) On 06/25/2013 10:00 PM, Tom Lane wrote: After some contemplation, I think that the most practical way to fix this is for deconstruct_recurse and distribute_qual_to_rels to effectively move such a qual to

[HACKERS] LATERAL quals revisited

2013-06-25 Thread Tom Lane
I've been studying the bug reported at http://www.postgresql.org/message-id/20130617235236.GA1636@jeremyevans.local that the planner can do the wrong thing with queries like SELECT * FROM i LEFT JOIN LATERAL (SELECT * FROM j WHERE i.n = j.n) j ON true; I think the fundamental problem is that, b