Band-aid solution for problems with SubPlans used in hash join clauses,
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 25 Nov 2003 19:17:16 +0000 (19:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 25 Nov 2003 19:17:16 +0000 (19:17 +0000)
per report from Andrew Holm-Hansen.  The difficulty arises from the fact
that the planner allowed a Hash node's hashkeys to share substructure
with the parent HashJoin node's hashclauses, plus some rather bizarre
choices about who initializes what during executor startup.  A cleaner
but more invasive solution is to not store hashkeys separately in the
plan tree at all, but let the HashJoin node deconstruct hashclauses
during executor startup.  I plan to fix it that way in HEAD.

src/backend/executor/nodeHashjoin.c
src/backend/optimizer/plan/createplan.c

index 0778de3d3d260836aff853b207a0560cf566cd17..8524bbec9c4d8955c6ccda70741aab86ea3da224 100644 (file)
@@ -417,7 +417,7 @@ ExecInitHashJoin(HashJoin *node, EState *estate)
         */
        hjstate->hj_InnerHashKeys = (List *)
                ExecInitExpr((Expr *) hashNode->hashkeys,
-                                        innerPlanState(hjstate));
+                                        (PlanState *) hjstate);
        ((HashState *) innerPlanState(hjstate))->hashkeys =
                hjstate->hj_InnerHashKeys;
 
index 0bd9c830440767b5b769582719599e381d5b7483..5b915c2109cbd359baa0c1a1369fe5ef59e4eb91 100644 (file)
@@ -1093,12 +1093,14 @@ create_hashjoin_plan(Query *root,
        hashclauses = order_qual_clauses(root, hashclauses);
 
        /*
-        * Extract the inner hash keys (right-hand operands of the
-        * hashclauses) to put in the Hash node.
+        * Extract the inner hash keys (right-hand operands of the hashclauses)
+        * to put in the Hash node.  Must do a deep copy in case there are
+        * subplans in the hash keys.
         */
        innerhashkeys = NIL;
        foreach(hcl, hashclauses)
-               innerhashkeys = lappend(innerhashkeys, get_rightop(lfirst(hcl)));
+               innerhashkeys = lappend(innerhashkeys,
+                                                               copyObject(get_rightop(lfirst(hcl))));
 
        /* We don't want any excess columns in the hashed tuples */
        disuse_physical_tlist(inner_plan, best_path->jpath.innerjoinpath);