7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -80,7 +80,7 @@ ExecHashSubPlan(SubPlanState *node,
80
80
* If first time through or we need to rescan the subplan, build
81
81
* the hash table.
82
82
*/
83
- if (node -> hashtable == NULL || planstate -> chgParam != NIL )
83
+ if (node -> hashtable == NULL || planstate -> chgParam != NULL )
84
84
buildSubPlanHash (node );
85
85
86
86
/*
@@ -218,22 +218,18 @@ ExecScanSubPlan(SubPlanState *node,
218
218
* Set Params of this plan from parent plan correlation Vars
219
219
*/
220
220
pvar = node -> args ;
221
- if ( subplan -> parParam != NIL )
221
+ foreach ( lst , subplan -> parParam )
222
222
{
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 );
237
233
}
238
234
Assert (pvar == NIL );
239
235
@@ -686,24 +682,24 @@ ExecInitSubPlan(SubPlanState *node, EState *estate)
686
682
687
683
/*
688
684
* 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...
690
691
*/
691
692
if (subplan -> setParam != NIL )
692
693
{
693
694
List * lst ;
694
695
695
696
foreach (lst , subplan -> setParam )
696
697
{
697
- ParamExecData * prm = & (estate -> es_param_exec_vals [lfirsti (lst )]);
698
+ int paramid = lfirsti (lst );
699
+ ParamExecData * prm = & (estate -> es_param_exec_vals [paramid ]);
698
700
699
701
prm -> execPlan = node ;
700
702
}
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
- */
707
703
}
708
704
709
705
/*
@@ -884,7 +880,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
884
880
885
881
if (subLinkType == EXISTS_SUBLINK )
886
882
{
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 ]);
888
886
889
887
prm -> execPlan = NULL ;
890
888
prm -> value = BoolGetDatum (true);
@@ -914,9 +912,13 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
914
912
node -> curTuple = tup ;
915
913
MemoryContextSwitchTo (node -> sub_estate -> es_query_cxt );
916
914
915
+ /*
916
+ * Now set all the setParam params from the columns of the tuple
917
+ */
917
918
foreach (lst , subplan -> setParam )
918
919
{
919
- ParamExecData * prm = & (econtext -> ecxt_param_exec_vals [lfirsti (lst )]);
920
+ int paramid = lfirsti (lst );
921
+ ParamExecData * prm = & (econtext -> ecxt_param_exec_vals [paramid ]);
920
922
921
923
prm -> execPlan = NULL ;
922
924
prm -> value = heap_getattr (tup , i , tdesc , & (prm -> isnull ));
@@ -928,7 +930,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
928
930
{
929
931
if (subLinkType == EXISTS_SUBLINK )
930
932
{
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 ]);
932
936
933
937
prm -> execPlan = NULL ;
934
938
prm -> value = BoolGetDatum (false);
@@ -938,7 +942,8 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
938
942
{
939
943
foreach (lst , subplan -> setParam )
940
944
{
941
- ParamExecData * prm = & (econtext -> ecxt_param_exec_vals [lfirsti (lst )]);
945
+ int paramid = lfirsti (lst );
946
+ ParamExecData * prm = & (econtext -> ecxt_param_exec_vals [paramid ]);
942
947
943
948
prm -> execPlan = NULL ;
944
949
prm -> value = (Datum ) 0 ;
@@ -979,12 +984,12 @@ ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent)
979
984
EState * estate = parent -> state ;
980
985
List * lst ;
981
986
982
- if (subplan -> parParam != NULL )
987
+ if (subplan -> parParam != NIL )
983
988
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 " );
988
993
989
994
/*
990
995
* Don't actually re-scan: ExecSetParamPlan does it if needed.
@@ -995,10 +1000,10 @@ ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent)
995
1000
*/
996
1001
foreach (lst , subplan -> setParam )
997
1002
{
998
- ParamExecData * prm = & (estate -> es_param_exec_vals [lfirsti (lst )]);
1003
+ int paramid = lfirsti (lst );
1004
+ ParamExecData * prm = & (estate -> es_param_exec_vals [paramid ]);
999
1005
1000
1006
prm -> execPlan = node ;
1007
+ parent -> chgParam = bms_add_member (parent -> chgParam , paramid );
1001
1008
}
1002
-
1003
- parent -> chgParam = nconc (parent -> chgParam , listCopy (subplan -> setParam ));
1004
1009
}
0 commit comments