Thread: pgsql: Repair planner bug introduced in 8.2 by ability to rearrange

pgsql: Repair planner bug introduced in 8.2 by ability to rearrange

From
tgl@postgresql.org (Tom Lane)
Date:
Log Message:
-----------
Repair planner bug introduced in 8.2 by ability to rearrange outer joins:
in cases where a sub-SELECT inserts a WHERE clause between two outer joins,
that clause may prevent us from re-ordering the two outer joins.  The code
was considering only the joins' own ON-conditions in determining reordering
safety, which is not good enough.  Add a "delay_upper_joins" flag to
OuterJoinInfo to flag that we have detected such a clause and higher-level
outer joins shouldn't be permitted to commute with this one.  (This might
seem overly coarse, but given the current rules for OJ reordering, it's
sufficient AFAICT.)

The failure case is actually pretty narrow: it needs a WHERE clause within
the RHS of a left join that checks the RHS of a lower left join, but is not
strict for that RHS (else we'd have simplified the lower join to a plain
join).  Even then no failure will be manifest unless the planner chooses to
rearrange the join order.

Per bug report from Adam Terrey.

Modified Files:
--------------
    pgsql/src/backend/nodes:
        copyfuncs.c (r1.375 -> r1.376)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/copyfuncs.c.diff?r1=1.375&r2=1.376)
        equalfuncs.c (r1.306 -> r1.307)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/equalfuncs.c.diff?r1=1.306&r2=1.307)
        outfuncs.c (r1.307 -> r1.308)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/outfuncs.c.diff?r1=1.307&r2=1.308)
    pgsql/src/backend/optimizer/plan:
        initsplan.c (r1.131 -> r1.132)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/initsplan.c.diff?r1=1.131&r2=1.132)
    pgsql/src/include/nodes:
        relation.h (r1.142 -> r1.143)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/nodes/relation.h.diff?r1=1.142&r2=1.143)
    pgsql/src/test/regress/expected:
        join.out (r1.29 -> r1.30)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/join.out.diff?r1=1.29&r2=1.30)
        join_1.out (r1.11 -> r1.12)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/join_1.out.diff?r1=1.11&r2=1.12)
    pgsql/src/test/regress/sql:
        join.sql (r1.20 -> r1.21)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/join.sql.diff?r1=1.20&r2=1.21)