Skip to content

Commit 145014f

Browse files
committed
Make further use of new bitmapset code: executor's chgParam, extParam,
locParam lists can be converted to bitmapsets to speed updating. Also, replace 'locParam' with 'allParam', which contains all the paramIDs relevant to the node (i.e., the union of extParam and locParam); this saves a step during SetChangedParamList() without costing anything elsewhere.
1 parent c15a4c2 commit 145014f

File tree

17 files changed

+268
-194
lines changed

17 files changed

+268
-194
lines changed

src/backend/executor/execAmi.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.68 2002/12/14 00:17:50 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.69 2003/02/09 00:30:39 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -55,7 +55,7 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt)
5555
InstrEndLoop(node->instrument);
5656

5757
/* If we have changed parameters, propagate that info */
58-
if (node->chgParam != NIL)
58+
if (node->chgParam != NULL)
5959
{
6060
List *lst;
6161

@@ -64,25 +64,25 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt)
6464
SubPlanState *sstate = (SubPlanState *) lfirst(lst);
6565
PlanState *splan = sstate->planstate;
6666

67-
if (splan->plan->extParam != NIL) /* don't care about child
68-
* locParam */
69-
SetChangedParamList(splan, node->chgParam);
70-
if (splan->chgParam != NIL)
67+
if (splan->plan->extParam != NULL) /* don't care about child
68+
* local Params */
69+
UpdateChangedParamSet(splan, node->chgParam);
70+
if (splan->chgParam != NULL)
7171
ExecReScanSetParamPlan(sstate, node);
7272
}
7373
foreach(lst, node->subPlan)
7474
{
7575
SubPlanState *sstate = (SubPlanState *) lfirst(lst);
7676
PlanState *splan = sstate->planstate;
7777

78-
if (splan->plan->extParam != NIL)
79-
SetChangedParamList(splan, node->chgParam);
78+
if (splan->plan->extParam != NULL)
79+
UpdateChangedParamSet(splan, node->chgParam);
8080
}
8181
/* Well. Now set chgParam for left/right trees. */
8282
if (node->lefttree != NULL)
83-
SetChangedParamList(node->lefttree, node->chgParam);
83+
UpdateChangedParamSet(node->lefttree, node->chgParam);
8484
if (node->righttree != NULL)
85-
SetChangedParamList(node->righttree, node->chgParam);
85+
UpdateChangedParamSet(node->righttree, node->chgParam);
8686
}
8787

8888
switch (nodeTag(node))
@@ -165,10 +165,10 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt)
165165
return;
166166
}
167167

168-
if (node->chgParam != NIL)
168+
if (node->chgParam != NULL)
169169
{
170-
freeList(node->chgParam);
171-
node->chgParam = NIL;
170+
bms_free(node->chgParam);
171+
node->chgParam = NULL;
172172
}
173173
}
174174

src/backend/executor/execProcnode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.34 2002/12/14 00:17:50 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.35 2003/02/09 00:30:39 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -282,7 +282,7 @@ ExecProcNode(PlanState *node)
282282
if (node == NULL)
283283
return NULL;
284284

285-
if (node->chgParam != NIL) /* something changed */
285+
if (node->chgParam != NULL) /* something changed */
286286
ExecReScan(node, NULL); /* let ReScan handle this */
287287

288288
if (node->instrument)
@@ -504,10 +504,10 @@ ExecEndNode(PlanState *node)
504504
foreach(subp, node->subPlan)
505505
ExecEndSubPlan((SubPlanState *) lfirst(subp));
506506

507-
if (node->chgParam != NIL)
507+
if (node->chgParam != NULL)
508508
{
509-
freeList(node->chgParam);
510-
node->chgParam = NIL;
509+
bms_free(node->chgParam);
510+
node->chgParam = NULL;
511511
}
512512

513513
switch (nodeTag(node))

src/backend/executor/execUtils.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.96 2003/01/23 05:10:39 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.97 2003/02/09 00:30:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -874,25 +874,28 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
874874
}
875875
}
876876

877+
/*
878+
* UpdateChangedParamSet
879+
* Add changed parameters to a plan node's chgParam set
880+
*/
877881
void
878-
SetChangedParamList(PlanState *node, List *newchg)
882+
UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
879883
{
880-
List *nl;
881-
882-
foreach(nl, newchg)
883-
{
884-
int paramId = lfirsti(nl);
884+
Bitmapset *parmset;
885885

886-
/* if this node doesn't depend on a param ... */
887-
if (!intMember(paramId, node->plan->extParam) &&
888-
!intMember(paramId, node->plan->locParam))
889-
continue;
890-
/* if this param is already in list of changed ones ... */
891-
if (intMember(paramId, node->chgParam))
892-
continue;
893-
/* else - add this param to the list */
894-
node->chgParam = lappendi(node->chgParam, paramId);
895-
}
886+
/*
887+
* The plan node only depends on params listed in its allParam set.
888+
* Don't include anything else into its chgParam set.
889+
*/
890+
parmset = bms_intersect(node->plan->allParam, newchg);
891+
/*
892+
* Keep node->chgParam == NULL if there's not actually any members;
893+
* this allows the simplest possible tests in executor node files.
894+
*/
895+
if (!bms_is_empty(parmset))
896+
node->chgParam = bms_join(node->chgParam, parmset);
897+
else
898+
bms_free(parmset);
896899
}
897900

898901
/*

src/backend/executor/nodeAgg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* Portions Copyright (c) 1994, Regents of the University of California
4646
*
4747
* IDENTIFICATION
48-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.103 2003/02/04 00:48:23 tgl Exp $
48+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.104 2003/02/09 00:30:39 tgl Exp $
4949
*
5050
*-------------------------------------------------------------------------
5151
*/
@@ -1405,7 +1405,7 @@ ExecReScanAgg(AggState *node, ExprContext *exprCtxt)
14051405
* if chgParam of subnode is not null then plan will be re-scanned by
14061406
* first ExecProcNode.
14071407
*/
1408-
if (((PlanState *) node)->lefttree->chgParam == NIL)
1408+
if (((PlanState *) node)->lefttree->chgParam == NULL)
14091409
ExecReScan(((PlanState *) node)->lefttree, exprCtxt);
14101410
}
14111411

src/backend/executor/nodeAppend.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.51 2002/12/05 15:50:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.52 2003/02/09 00:30:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -361,14 +361,14 @@ ExecReScanAppend(AppendState *node, ExprContext *exprCtxt)
361361
* ExecReScan doesn't know about my subplans, so I have to do
362362
* changed-parameter signaling myself.
363363
*/
364-
if (node->ps.chgParam != NIL)
365-
SetChangedParamList(subnode, node->ps.chgParam);
364+
if (node->ps.chgParam != NULL)
365+
UpdateChangedParamSet(subnode, node->ps.chgParam);
366366

367367
/*
368368
* if chgParam of subnode is not null then plan will be re-scanned
369369
* by first ExecProcNode.
370370
*/
371-
if (subnode->chgParam == NIL)
371+
if (subnode->chgParam == NULL)
372372
{
373373
/* make sure estate is correct for this subnode (needed??) */
374374
node->as_whichplan = i;

src/backend/executor/nodeSubplan.c

Lines changed: 42 additions & 37 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/executor/nodeSubplan.c,v 1.43 2003/01/12 04:03:34 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.44 2003/02/09 00:30:39 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -80,7 +80,7 @@ ExecHashSubPlan(SubPlanState *node,
8080
* If first time through or we need to rescan the subplan, build
8181
* the hash table.
8282
*/
83-
if (node->hashtable == NULL || planstate->chgParam != NIL)
83+
if (node->hashtable == NULL || planstate->chgParam != NULL)
8484
buildSubPlanHash(node);
8585

8686
/*
@@ -218,22 +218,18 @@ ExecScanSubPlan(SubPlanState *node,
218218
* Set Params of this plan from parent plan correlation Vars
219219
*/
220220
pvar = node->args;
221-
if (subplan->parParam != NIL)
221+
foreach(lst, subplan->parParam)
222222
{
223-
foreach(lst, subplan->parParam)
224-
{
225-
ParamExecData *prm;
226-
227-
prm = &(econtext->ecxt_param_exec_vals[lfirsti(lst)]);
228-
Assert(pvar != NIL);
229-
prm->value = ExecEvalExprSwitchContext((ExprState *) lfirst(pvar),
230-
econtext,
231-
&(prm->isnull),
232-
NULL);
233-
pvar = lnext(pvar);
234-
}
235-
planstate->chgParam = nconc(planstate->chgParam,
236-
listCopy(subplan->parParam));
223+
int paramid = lfirsti(lst);
224+
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
225+
226+
Assert(pvar != NIL);
227+
prm->value = ExecEvalExprSwitchContext((ExprState *) lfirst(pvar),
228+
econtext,
229+
&(prm->isnull),
230+
NULL);
231+
pvar = lnext(pvar);
232+
planstate->chgParam = bms_add_member(planstate->chgParam, paramid);
237233
}
238234
Assert(pvar == NIL);
239235

@@ -686,24 +682,24 @@ ExecInitSubPlan(SubPlanState *node, EState *estate)
686682

687683
/*
688684
* If this plan is un-correlated or undirect correlated one and want
689-
* to set params for parent plan then prepare parameters.
685+
* to set params for parent plan then mark parameters as needing
686+
* evaluation.
687+
*
688+
* Note that in the case of un-correlated subqueries we don't care
689+
* about setting parent->chgParam here: indices take care about
690+
* it, for others - it doesn't matter...
690691
*/
691692
if (subplan->setParam != NIL)
692693
{
693694
List *lst;
694695

695696
foreach(lst, subplan->setParam)
696697
{
697-
ParamExecData *prm = &(estate->es_param_exec_vals[lfirsti(lst)]);
698+
int paramid = lfirsti(lst);
699+
ParamExecData *prm = &(estate->es_param_exec_vals[paramid]);
698700

699701
prm->execPlan = node;
700702
}
701-
702-
/*
703-
* Note that in the case of un-correlated subqueries we don't care
704-
* about setting parent->chgParam here: indices take care about
705-
* it, for others - it doesn't matter...
706-
*/
707703
}
708704

709705
/*
@@ -884,7 +880,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
884880

885881
if (subLinkType == EXISTS_SUBLINK)
886882
{
887-
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[lfirsti(subplan->setParam)]);
883+
/* There can be only one param... */
884+
int paramid = lfirsti(subplan->setParam);
885+
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
888886

889887
prm->execPlan = NULL;
890888
prm->value = BoolGetDatum(true);
@@ -914,9 +912,13 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
914912
node->curTuple = tup;
915913
MemoryContextSwitchTo(node->sub_estate->es_query_cxt);
916914

915+
/*
916+
* Now set all the setParam params from the columns of the tuple
917+
*/
917918
foreach(lst, subplan->setParam)
918919
{
919-
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[lfirsti(lst)]);
920+
int paramid = lfirsti(lst);
921+
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
920922

921923
prm->execPlan = NULL;
922924
prm->value = heap_getattr(tup, i, tdesc, &(prm->isnull));
@@ -928,7 +930,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
928930
{
929931
if (subLinkType == EXISTS_SUBLINK)
930932
{
931-
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[lfirsti(subplan->setParam)]);
933+
/* There can be only one param... */
934+
int paramid = lfirsti(subplan->setParam);
935+
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
932936

933937
prm->execPlan = NULL;
934938
prm->value = BoolGetDatum(false);
@@ -938,7 +942,8 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
938942
{
939943
foreach(lst, subplan->setParam)
940944
{
941-
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[lfirsti(lst)]);
945+
int paramid = lfirsti(lst);
946+
ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
942947

943948
prm->execPlan = NULL;
944949
prm->value = (Datum) 0;
@@ -979,12 +984,12 @@ ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent)
979984
EState *estate = parent->state;
980985
List *lst;
981986

982-
if (subplan->parParam != NULL)
987+
if (subplan->parParam != NIL)
983988
elog(ERROR, "ExecReScanSetParamPlan: direct correlated subquery unsupported, yet");
984-
if (subplan->setParam == NULL)
985-
elog(ERROR, "ExecReScanSetParamPlan: setParam list is NULL");
986-
if (planstate->plan->extParam == NULL)
987-
elog(ERROR, "ExecReScanSetParamPlan: extParam list of plan is NULL");
989+
if (subplan->setParam == NIL)
990+
elog(ERROR, "ExecReScanSetParamPlan: setParam list is empty");
991+
if (bms_is_empty(planstate->plan->extParam))
992+
elog(ERROR, "ExecReScanSetParamPlan: extParam set of plan is empty");
988993

989994
/*
990995
* Don't actually re-scan: ExecSetParamPlan does it if needed.
@@ -995,10 +1000,10 @@ ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent)
9951000
*/
9961001
foreach(lst, subplan->setParam)
9971002
{
998-
ParamExecData *prm = &(estate->es_param_exec_vals[lfirsti(lst)]);
1003+
int paramid = lfirsti(lst);
1004+
ParamExecData *prm = &(estate->es_param_exec_vals[paramid]);
9991005

10001006
prm->execPlan = node;
1007+
parent->chgParam = bms_add_member(parent->chgParam, paramid);
10011008
}
1002-
1003-
parent->chgParam = nconc(parent->chgParam, listCopy(subplan->setParam));
10041009
}

src/backend/executor/nodeSubqueryscan.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.17 2003/01/12 22:01:38 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.18 2003/02/09 00:30:39 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -261,10 +261,10 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
261261
* ExecReScan doesn't know about my subplan, so I have to do
262262
* changed-parameter signaling myself. This is just as well,
263263
* because the subplan has its own memory context in which its
264-
* chgParam lists live.
264+
* chgParam state lives.
265265
*/
266266
if (node->ss.ps.chgParam != NULL)
267-
SetChangedParamList(node->subplan, node->ss.ps.chgParam);
267+
UpdateChangedParamSet(node->subplan, node->ss.ps.chgParam);
268268

269269
/*
270270
* if chgParam of subnode is not null then plan will be re-scanned by

0 commit comments

Comments
 (0)