Re: Strange workaround for slow query

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Yeb Havinga <yebhavinga(at)gmail(dot)com>, sverhagen(at)wps-nl(dot)com, pgsql-performance(at)postgresql(dot)org
Subject: Re: Strange workaround for slow query
Date: 2010-03-10 22:41:35
Message-ID: 603c8f071003101441g4b116429t5044db4c52c7a32f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Mar 10, 2010 at 5:37 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> It does seem like once the materialize step is done we could notice
>> that the tuplestore is empty and, given that uses no outer variables
>> or parameters and therefore will never be re-executed, we could skip
>> the rest of the index scan.
>
> Yeah, the same thing occurred to me while looking at this example.
>
> Right now, nodeNestloop is not really aware of whether the inner scan
> depends on any parameters from the outer scan, so it's a bit hard to
> determine whether the join can be abandoned.  However, I have 9.1
> plans to change that --- I'd like to get rid of the current
> pass-the-outer-tuple-to-ReScan hack entirely, in favor of having
> nodeNestloop explicitly set PARAM_EXEC parameters for the inner scan.
> Once that's in, it would be pretty easy to apply this optimization.
> (I've added a note to my private TODO file about it.)

Oh, cool. I was thinking about working on that exact project (getting
rid of the outer tuple stuff) per some of our earlier conversations,
but I don't understand the code well enough so it is likely to be
exceedingly slow going if I have to do it.

> Another possible objection is that if the inner scan has any volatile
> functions in its quals, it might yield a different result upon rescan
> even without parameters.  However, since we are already willing to stick
> a Materialize node on it at the whim of the planner, I don't see how
> such a short-circuit in the executor would make things any worse.

+1.

...Robert

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Paul McGarry 2010-03-11 01:28:21 shared_buffers advice
Previous Message Tom Lane 2010-03-10 22:37:20 Re: Strange workaround for slow query