pgsql: Fix subquery pullup to wrap a PlaceHolderVar around the entire - Mailing list pgsql-committers

From tgl@postgresql.org (Tom Lane)
Subject pgsql: Fix subquery pullup to wrap a PlaceHolderVar around the entire
Date
Msg-id 20090902175233.835E6753FB7@cvs.postgresql.org
Whole thread Raw
List pgsql-committers
Log Message:
-----------
Fix subquery pullup to wrap a PlaceHolderVar around the entire RowExpr
that's generated for a whole-row Var referencing the subquery, when the
subquery is in the nullable side of an outer join.  The previous coding
instead put PlaceHolderVars around the elements of the RowExpr.  The effect
was that when the outer join made the subquery outputs go to null, the
whole-row Var produced ROW(NULL,NULL,...) rather than just NULL.  There
are arguments afoot about whether those things ought to be semantically
indistinguishable, but for the moment they are not entirely so, and the
planner needs to take care that its machinations preserve the difference.
Per bug #5025.

Making this feasible required refactoring ResolveNew() to allow more caller
control over what is substituted for a Var.  I chose to make ResolveNew()
a wrapper around a new general-purpose function replace_rte_variables().
I also fixed the ancient bogosity that ResolveNew might fail to set
a query's hasSubLinks field after inserting a SubLink in it.  Although
all current callers make sure that happens anyway, we've had bugs of that
sort before, and it seemed like a good time to install a proper solution.

Back-patch to 8.4.  The problem can be demonstrated clear back to 8.0,
but the fix would be too invasive in earlier branches; not to mention
that people may be depending on the subtly-incorrect behavior.  The
8.4 series is new enough that fixing this probably won't cause complaints,
but it might in older branches.  Also, 8.4 shows the incorrect behavior
in more cases than older branches do, because it is able to flatten
subqueries in more cases.

Tags:
----
REL8_4_STABLE

Modified Files:
--------------
    pgsql/src/backend/optimizer/path:
        allpaths.c (r1.183.2.1 -> r1.183.2.2)

(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/path/allpaths.c?r1=1.183.2.1&r2=1.183.2.2)
    pgsql/src/backend/optimizer/prep:
        prepjointree.c (r1.66 -> r1.66.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/prep/prepjointree.c?r1=1.66&r2=1.66.2.1)
        prepunion.c (r1.171.2.2 -> r1.171.2.3)

(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/prep/prepunion.c?r1=1.171.2.2&r2=1.171.2.3)
    pgsql/src/backend/rewrite:
        rewriteHandler.c (r1.186 -> r1.186.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/rewrite/rewriteHandler.c?r1=1.186&r2=1.186.2.1)
        rewriteManip.c (r1.122 -> r1.122.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/rewrite/rewriteManip.c?r1=1.122&r2=1.122.2.1)
    pgsql/src/include/rewrite:
        rewriteManip.h (r1.50 -> r1.50.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/rewrite/rewriteManip.h?r1=1.50&r2=1.50.2.1)
    pgsql/src/test/regress/expected:
        join.out (r1.36.2.1 -> r1.36.2.2)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/join.out?r1=1.36.2.1&r2=1.36.2.2)
    pgsql/src/test/regress/sql:
        join.sql (r1.27.2.1 -> r1.27.2.2)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/join.sql?r1=1.27.2.1&r2=1.27.2.2)

pgsql-committers by date:

Previous
From: tgl@postgresql.org (Tom Lane)
Date:
Subject: pgsql: Fix subquery pullup to wrap a PlaceHolderVar around the entire
Next
From: mha@postgresql.org (Magnus Hagander)
Date:
Subject: pgsql: Revert Makefile modification that broke the MSVC build.