Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a64846f

Browse files
committed
Get rid of hashkeys field of Hash plan node, since it's redundant with
the hashclauses field of the parent HashJoin. This avoids problems with duplicated links to SubPlans in hash clauses, as per report from Andrew Holm-Hansen.
1 parent 38ba28e commit a64846f

File tree

8 files changed

+31
-66
lines changed

8 files changed

+31
-66
lines changed

src/backend/executor/nodeHash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.79 2003/08/04 02:39:59 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.80 2003/11/25 21:00:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -113,6 +113,7 @@ ExecInitHash(Hash *node, EState *estate)
113113
hashstate->ps.plan = (Plan *) node;
114114
hashstate->ps.state = estate;
115115
hashstate->hashtable = NULL;
116+
hashstate->hashkeys = NIL; /* will be set by parent HashJoin */
116117

117118
/*
118119
* Miscellaneous initialization

src/backend/executor/nodeHashjoin.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.57 2003/09/25 06:57:59 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.58 2003/11/25 21:00:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -308,7 +308,8 @@ ExecInitHashJoin(HashJoin *node, EState *estate)
308308
HashJoinState *hjstate;
309309
Plan *outerNode;
310310
Hash *hashNode;
311-
List *hclauses;
311+
List *lclauses;
312+
List *rclauses;
312313
List *hoperators;
313314
List *hcl;
314315

@@ -410,31 +411,31 @@ ExecInitHashJoin(HashJoin *node, EState *estate)
410411
hjstate->hj_CurTuple = (HashJoinTuple) NULL;
411412

412413
/*
413-
* The planner already made a list of the inner hashkeys for us, but
414-
* we also need a list of the outer hashkeys, as well as a list of the
415-
* hash operator OIDs. Both lists of exprs must then be prepared for
416-
* execution.
414+
* Deconstruct the hash clauses into outer and inner argument values,
415+
* so that we can evaluate those subexpressions separately. Also make
416+
* a list of the hash operator OIDs, in preparation for looking up the
417+
* hash functions to use.
417418
*/
418-
hjstate->hj_InnerHashKeys = (List *)
419-
ExecInitExpr((Expr *) hashNode->hashkeys,
420-
innerPlanState(hjstate));
421-
((HashState *) innerPlanState(hjstate))->hashkeys =
422-
hjstate->hj_InnerHashKeys;
423-
424-
hclauses = NIL;
419+
lclauses = NIL;
420+
rclauses = NIL;
425421
hoperators = NIL;
426-
foreach(hcl, node->hashclauses)
422+
foreach(hcl, hjstate->hashclauses)
427423
{
428-
OpExpr *hclause = (OpExpr *) lfirst(hcl);
424+
FuncExprState *fstate = (FuncExprState *) lfirst(hcl);
425+
OpExpr *hclause;
429426

427+
Assert(IsA(fstate, FuncExprState));
428+
hclause = (OpExpr *) fstate->xprstate.expr;
430429
Assert(IsA(hclause, OpExpr));
431-
hclauses = lappend(hclauses, get_leftop((Expr *) hclause));
430+
lclauses = lappend(lclauses, lfirst(fstate->args));
431+
rclauses = lappend(rclauses, lsecond(fstate->args));
432432
hoperators = lappendo(hoperators, hclause->opno);
433433
}
434-
hjstate->hj_OuterHashKeys = (List *)
435-
ExecInitExpr((Expr *) hclauses,
436-
(PlanState *) hjstate);
434+
hjstate->hj_OuterHashKeys = lclauses;
435+
hjstate->hj_InnerHashKeys = rclauses;
437436
hjstate->hj_HashOperators = hoperators;
437+
/* child Hash node needs to evaluate inner hash keys, too */
438+
((HashState *) innerPlanState(hjstate))->hashkeys = rclauses;
438439

439440
hjstate->js.ps.ps_OuterTupleSlot = NULL;
440441
hjstate->js.ps.ps_TupFromTlist = false;

src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.267 2003/11/12 21:15:52 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.268 2003/11/25 21:00:53 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -551,7 +551,6 @@ _copyHash(Hash *from)
551551
/*
552552
* copy remainder of node
553553
*/
554-
COPY_NODE_FIELD(hashkeys);
555554

556555
return newnode;
557556
}

src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.220 2003/11/12 21:15:52 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.221 2003/11/25 21:00:53 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -531,8 +531,6 @@ _outHash(StringInfo str, Hash *node)
531531
WRITE_NODE_TYPE("HASH");
532532

533533
_outPlanInfo(str, (Plan *) node);
534-
535-
WRITE_NODE_FIELD(hashkeys);
536534
}
537535

538536
/*****************************************************************************

src/backend/optimizer/plan/createplan.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.159 2003/11/12 21:15:53 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.160 2003/11/25 21:00:53 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -97,7 +97,7 @@ static HashJoin *make_hashjoin(List *tlist,
9797
List *hashclauses,
9898
Plan *lefttree, Plan *righttree,
9999
JoinType jointype);
100-
static Hash *make_hash(List *tlist, List *hashkeys, Plan *lefttree);
100+
static Hash *make_hash(List *tlist, Plan *lefttree);
101101
static MergeJoin *make_mergejoin(List *tlist,
102102
List *joinclauses, List *otherclauses,
103103
List *mergeclauses,
@@ -1067,8 +1067,6 @@ create_hashjoin_plan(Query *root,
10671067
List *hashclauses;
10681068
HashJoin *join_plan;
10691069
Hash *hash_plan;
1070-
List *innerhashkeys;
1071-
List *hcl;
10721070

10731071
/* Get the join qual clauses (in plain expression form) */
10741072
if (IS_OUTER_JOIN(best_path->jpath.jointype))
@@ -1102,22 +1100,13 @@ create_hashjoin_plan(Query *root,
11021100
otherclauses = order_qual_clauses(root, otherclauses);
11031101
hashclauses = order_qual_clauses(root, hashclauses);
11041102

1105-
/*
1106-
* Extract the inner hash keys (right-hand operands of the
1107-
* hashclauses) to put in the Hash node.
1108-
*/
1109-
innerhashkeys = NIL;
1110-
foreach(hcl, hashclauses)
1111-
innerhashkeys = lappend(innerhashkeys, get_rightop(lfirst(hcl)));
1112-
11131103
/* We don't want any excess columns in the hashed tuples */
11141104
disuse_physical_tlist(inner_plan, best_path->jpath.innerjoinpath);
11151105

11161106
/*
11171107
* Build the hash node and hash join node.
11181108
*/
11191109
hash_plan = make_hash(inner_plan->targetlist,
1120-
innerhashkeys,
11211110
inner_plan);
11221111
join_plan = make_hashjoin(tlist,
11231112
joinclauses,
@@ -1728,7 +1717,7 @@ make_hashjoin(List *tlist,
17281717
}
17291718

17301719
static Hash *
1731-
make_hash(List *tlist, List *hashkeys, Plan *lefttree)
1720+
make_hash(List *tlist, Plan *lefttree)
17321721
{
17331722
Hash *node = makeNode(Hash);
17341723
Plan *plan = &node->plan;
@@ -1744,7 +1733,6 @@ make_hash(List *tlist, List *hashkeys, Plan *lefttree)
17441733
plan->qual = NIL;
17451734
plan->lefttree = lefttree;
17461735
plan->righttree = NULL;
1747-
node->hashkeys = hashkeys;
17481736

17491737
return node;
17501738
}

src/backend/optimizer/plan/setrefs.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.97 2003/08/08 21:41:50 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.98 2003/11/25 21:00:54 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -167,24 +167,6 @@ set_plan_references(Plan *plan, List *rtable)
167167
(Node *) ((HashJoin *) plan)->hashclauses);
168168
break;
169169
case T_Hash:
170-
171-
/*
172-
* Hash does not evaluate its targetlist or quals, so don't
173-
* touch those (see comments below). But we do need to fix
174-
* its hashkeys. The hashkeys are a little bizarre because
175-
* they need to match the hashclauses of the parent HashJoin
176-
* node, so we use join_references to fix them.
177-
*/
178-
((Hash *) plan)->hashkeys =
179-
join_references(((Hash *) plan)->hashkeys,
180-
rtable,
181-
NIL,
182-
plan->lefttree->targetlist,
183-
(Index) 0,
184-
targetlist_has_non_vars(plan->lefttree->targetlist));
185-
fix_expr_references(plan,
186-
(Node *) ((Hash *) plan)->hashkeys);
187-
break;
188170
case T_Material:
189171
case T_Sort:
190172
case T_Unique:

src/backend/optimizer/plan/subselect.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.83 2003/10/18 16:52:15 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.84 2003/11/25 21:00:54 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1013,10 +1013,6 @@ finalize_plan(Plan *plan, List *rtable,
10131013
break;
10141014

10151015
case T_Hash:
1016-
finalize_primnode((Node *) ((Hash *) plan)->hashkeys,
1017-
&context);
1018-
break;
1019-
10201016
case T_Agg:
10211017
case T_SeqScan:
10221018
case T_Material:

src/include/nodes/plannodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: plannodes.h,v 1.70 2003/11/12 21:15:59 tgl Exp $
10+
* $Id: plannodes.h,v 1.71 2003/11/25 21:00:54 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -350,7 +350,7 @@ typedef struct Unique
350350
typedef struct Hash
351351
{
352352
Plan plan;
353-
List *hashkeys;
353+
/* all other info is in the parent HashJoin node */
354354
} Hash;
355355

356356
/* ----------------

0 commit comments

Comments
 (0)