Re: Strange result with LATERAL query

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Strange result with LATERAL query
Date: 2016-08-24 15:26:04
Message-ID: CAFj8pRCfni0u7DopgpaSdtzhvh=6-tvJwGRGjjewev6=WubLJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2016-08-24 17:08 GMT+02:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> writes:
> > Something is wrong with the way chgParam is being handled in Agg nodes.
> > The code in ExecReScanAgg seems to assume that if the lefttree doesn't
> > have any parameter changes then it suffices to re-project the data from
> > the existing hashtable; but of course this is nonsense if the parameter
> > is in an input to an aggregate function.
>
> It looks like it's sufficient to do this:
>
> diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/
> nodeAgg.c
> index 1ec2515..f468fad 100644
> *** a/src/backend/executor/nodeAgg.c
> --- b/src/backend/executor/nodeAgg.c
> *************** ExecReScanAgg(AggState *node)
> *** 3425,3435 ****
> return;
>
> /*
> ! * If we do have the hash table and the subplan does not
> have any
> ! * parameter changes, then we can just rescan the existing
> hash table;
> ! * no need to build it again.
> */
> ! if (outerPlan->chgParam == NULL)
> {
> ResetTupleHashIterator(node->hashtable,
> &node->hashiter);
> return;
> --- 3425,3436 ----
> return;
>
> /*
> ! * If we do have the hash table and there are no relevant
> parameter
> ! * changes, then we can just rescan the existing hash
> table; no need
> ! * to build it again.
> */
> ! if (node->ss.ps.chgParam == NULL &&
> ! outerPlan->chgParam == NULL)
> {
> ResetTupleHashIterator(node->hashtable,
> &node->hashiter);
> return;
>
>
> I'm not sure if it's worth trying to distinguish whether the Param is
> inside any aggregate calls or not. The existing code gets the right
> answer for
>
> select array(select x+sum(y) from generate_series(1,3) y group by y)
> from generate_series(1,3) x;
>
> and we'd be losing some efficiency for cases like that if we fix
> it as above. But is it worth the trouble?
>
>
The result should not depend on GUC - hashagg on/off changing output - it
is error.

Regards

Pavel

> regards, tom lane
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Gierth 2016-08-24 15:29:16 Re: Strange result with LATERAL query
Previous Message Tom Lane 2016-08-24 15:08:28 Re: Strange result with LATERAL query