pgsql: Fix the handling of sub-SELECTs appearing in the arguments of an

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix the handling of sub-SELECTs appearing in the arguments of an
Date: 2009-04-25 16:45:03
Message-ID: 20090425164503.269D37540A1@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Log Message:
-----------
Fix the handling of sub-SELECTs appearing in the arguments of an outer-level
aggregate function. By definition, such a sub-SELECT cannot reference any
variables of query levels between itself and the aggregate's semantic level
(else the aggregate would've been assigned to that lower level instead).
So the correct, most efficient implementation is to treat the sub-SELECT as
being a sub-select of that outer query level, not the level the aggregate
syntactically appears in. Not doing so also confuses the heck out of our
parameter-passing logic, as illustrated in bug report from Daniel Grace.

Fortunately, we were already copying the whole Aggref expression up to the
outer query level, so all that's needed is to delay SS_process_sublinks
processing of the sub-SELECT until control returns to the outer level.

This has been broken since we introduced spec-compliant treatment of
outer aggregates in 7.4; so patch all the way back.

Tags:
----
REL8_3_STABLE

Modified Files:
--------------
pgsql/src/backend/optimizer/plan:
subselect.c (r1.129.2.2 -> r1.129.2.3)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/subselect.c?r1=1.129.2.2&r2=1.129.2.3)
pgsql/src/test/regress/expected:
aggregates.out (r1.16.2.1 -> r1.16.2.2)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/aggregates.out?r1=1.16.2.1&r2=1.16.2.2)
pgsql/src/test/regress/sql:
aggregates.sql (r1.13.4.1 -> r1.13.4.2)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/aggregates.sql?r1=1.13.4.1&r2=1.13.4.2)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2009-04-25 16:45:12 pgsql: Fix the handling of sub-SELECTs appearing in the arguments of an
Previous Message Tom Lane 2009-04-25 16:44:56 pgsql: Fix the handling of sub-SELECTs appearing in the arguments of an