Skip site navigation (1) Skip section navigation (2)

pgsql: Fix subquery pullup to wrap a PlaceHolderVar around the entire

From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix subquery pullup to wrap a PlaceHolderVar around the entire
Date: 2009-09-02 17:52:24
Message-ID: 20090902175224.74769753FB7@cvs.postgresql.org (view raw or flat)
Thread:
Lists: 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.

Modified Files:
--------------
    pgsql/src/backend/optimizer/path:
        allpaths.c (r1.184 -> r1.185)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/path/allpaths.c?r1=1.184&r2=1.185)
    pgsql/src/backend/optimizer/prep:
        prepjointree.c (r1.66 -> r1.67)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/prep/prepjointree.c?r1=1.66&r2=1.67)
        prepunion.c (r1.173 -> r1.174)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/prep/prepunion.c?r1=1.173&r2=1.174)
    pgsql/src/backend/rewrite:
        rewriteHandler.c (r1.186 -> r1.187)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/rewrite/rewriteHandler.c?r1=1.186&r2=1.187)
        rewriteManip.c (r1.122 -> r1.123)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/rewrite/rewriteManip.c?r1=1.122&r2=1.123)
    pgsql/src/include/rewrite:
        rewriteManip.h (r1.50 -> r1.51)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/rewrite/rewriteManip.h?r1=1.50&r2=1.51)
    pgsql/src/test/regress/expected:
        join.out (r1.39 -> r1.40)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/join.out?r1=1.39&r2=1.40)
    pgsql/src/test/regress/sql:
        join.sql (r1.30 -> r1.31)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/join.sql?r1=1.30&r2=1.31)

pgsql-committers by date

Next:From: Tom LaneDate: 2009-09-02 17:52:33
Subject: pgsql: Fix subquery pullup to wrap a PlaceHolderVar around the entire
Previous:From: Magnus HaganderDate: 2009-09-02 17:24:21
Subject: Re: pgsql: Derived files that are shipped in the distribution used to be

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group