PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeSubplan.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeSubplan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SubPlanStateExecInitSubPlan (SubPlan *subplan, PlanState *parent)
 
Datum ExecSubPlan (SubPlanState *node, ExprContext *econtext, bool *isNull)
 
Size EstimateSubplanHashTableSpace (double nentries, Size tupleWidth, bool unknownEqFalse)
 
void ExecReScanSetParamPlan (SubPlanState *node, PlanState *parent)
 
void ExecSetParamPlan (SubPlanState *node, ExprContext *econtext)
 
void ExecSetParamPlanMulti (const Bitmapset *params, ExprContext *econtext)
 

Function Documentation

◆ EstimateSubplanHashTableSpace()

Size EstimateSubplanHashTableSpace ( double  nentries,
Size  tupleWidth,
bool  unknownEqFalse 
)
extern

Definition at line 636 of file nodeSubplan.c.

639{
641 tab2space;
642
643 /* Estimate size of main hashtable */
646 0 /* no additional data */ );
647
648 /* Give up if that's already too big */
649 if (tab1space >= SIZE_MAX)
650 return tab1space;
651
652 /* Done if we don't need a hashnulls table */
653 if (unknownEqFalse)
654 return tab1space;
655
656 /*
657 * Adjust the rowcount estimate in the same way that buildSubPlanHash
658 * will, except that we don't bother with the special case for a single
659 * hash column. (We skip that detail because it'd be notationally painful
660 * for our caller to provide the column count, and this table has
661 * relatively little impact on the total estimate anyway.)
662 */
663 nentries /= 16;
664 if (nentries < 1)
665 nentries = 1;
666
667 /*
668 * It might be sane to also reduce the tupleWidth, but on the other hand
669 * we are not accounting for the space taken by the tuples' null bitmaps.
670 * Leave it alone for now.
671 */
674 0 /* no additional data */ );
675
676 /* Guard against overflow */
678 return SIZE_MAX;
679
680 return tab1space + tab2space;
681}
size_t Size
Definition c.h:619
Size EstimateTupleHashTableSpace(double nentries, Size tupleWidth, Size additionalsize)
static int fb(int x)

References EstimateTupleHashTableSpace(), and fb().

Referenced by subpath_is_hashable(), and subplan_is_hashable().

◆ ExecInitSubPlan()

SubPlanState * ExecInitSubPlan ( SubPlan subplan,
PlanState parent 
)
extern

Definition at line 850 of file nodeSubplan.c.

851{
853 EState *estate = parent->state;
854
855 sstate->subplan = subplan;
856
857 /* Link the SubPlanState to already-initialized subplan */
858 sstate->planstate = (PlanState *) list_nth(estate->es_subplanstates,
859 subplan->plan_id - 1);
860
861 /*
862 * This check can fail if the planner mistakenly puts a parallel-unsafe
863 * subplan into a parallelized subquery; see ExecSerializePlan.
864 */
865 if (sstate->planstate == NULL)
866 elog(ERROR, "subplan \"%s\" was not initialized",
867 subplan->plan_name);
868
869 /* Link to parent's state, too */
870 sstate->parent = parent;
871
872 /* Initialize subexpressions */
873 sstate->testexpr = ExecInitExpr((Expr *) subplan->testexpr, parent);
874
875 /*
876 * initialize my state
877 */
878 sstate->curTuple = NULL;
879 sstate->curArray = PointerGetDatum(NULL);
880 sstate->projLeft = NULL;
881 sstate->projRight = NULL;
882 sstate->hashtable = NULL;
883 sstate->hashnulls = NULL;
884 sstate->tuplesContext = NULL;
885 sstate->innerecontext = NULL;
886 sstate->keyColIdx = NULL;
887 sstate->tab_eq_funcoids = NULL;
888 sstate->tab_hash_funcs = NULL;
889 sstate->tab_collations = NULL;
890 sstate->cur_eq_funcs = NULL;
891
892 /*
893 * If this is an initplan, it has output parameters that the parent plan
894 * will use, so mark those parameters as needing evaluation. We don't
895 * actually run the subplan until we first need one of its outputs.
896 *
897 * A CTE subplan's output parameter is never to be evaluated in the normal
898 * way, so skip this in that case.
899 *
900 * Note that we don't set parent->chgParam here: the parent plan hasn't
901 * been run yet, so no need to force it to re-run.
902 */
903 if (subplan->setParam != NIL && subplan->parParam == NIL &&
904 subplan->subLinkType != CTE_SUBLINK)
905 {
906 ListCell *lst;
907
908 foreach(lst, subplan->setParam)
909 {
910 int paramid = lfirst_int(lst);
911 ParamExecData *prm = &(estate->es_param_exec_vals[paramid]);
912
913 prm->execPlan = sstate;
914 }
915 }
916
917 /*
918 * If we are going to hash the subquery output, initialize relevant stuff.
919 * (We don't create the hashtable until needed, though.)
920 */
921 if (subplan->useHashTable)
922 {
923 int ncols,
924 i;
928 TupleTableSlot *slot;
930 List *oplist,
931 *lefttlist,
932 *righttlist;
933 ListCell *l;
934
935 /* We need a memory context to hold the hash table(s)' tuples */
936 sstate->tuplesContext =
938 "SubPlan hashed tuples",
940 /* and a short-lived exprcontext for function evaluation */
941 sstate->innerecontext = CreateExprContext(estate);
942
943 /*
944 * We use ExecProject to evaluate the lefthand and righthand
945 * expression lists and form tuples. (You might think that we could
946 * use the sub-select's output tuples directly, but that is not the
947 * case if we had to insert any run-time coercions of the sub-select's
948 * output datatypes; anyway this avoids storing any resjunk columns
949 * that might be in the sub-select's output.) Run through the
950 * combining expressions to build tlists for the lefthand and
951 * righthand sides.
952 *
953 * We also extract the combining operators themselves to initialize
954 * the equality and hashing functions for the hash tables.
955 */
956 if (IsA(subplan->testexpr, OpExpr))
957 {
958 /* single combining operator */
959 oplist = list_make1(subplan->testexpr);
960 }
961 else if (is_andclause(subplan->testexpr))
962 {
963 /* multiple combining operators */
964 oplist = castNode(BoolExpr, subplan->testexpr)->args;
965 }
966 else
967 {
968 /* shouldn't see anything else in a hashable subplan */
969 elog(ERROR, "unrecognized testexpr type: %d",
970 (int) nodeTag(subplan->testexpr));
971 oplist = NIL; /* keep compiler quiet */
972 }
973 ncols = list_length(oplist);
974
976 sstate->numCols = ncols;
977 sstate->keyColIdx = (AttrNumber *) palloc(ncols * sizeof(AttrNumber));
978 sstate->tab_eq_funcoids = (Oid *) palloc(ncols * sizeof(Oid));
979 sstate->tab_collations = (Oid *) palloc(ncols * sizeof(Oid));
980 sstate->tab_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
981 lhs_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
982 sstate->cur_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
983 /* we'll need the cross-type equality fns below, but not in sstate */
984 cross_eq_funcoids = (Oid *) palloc(ncols * sizeof(Oid));
985
986 i = 1;
987 foreach(l, oplist)
988 {
989 OpExpr *opexpr = lfirst_node(OpExpr, l);
990 Expr *expr;
995
996 Assert(list_length(opexpr->args) == 2);
997
998 /* Process lefthand argument */
999 expr = (Expr *) linitial(opexpr->args);
1000 tle = makeTargetEntry(expr,
1001 i,
1002 NULL,
1003 false);
1005
1006 /* Process righthand argument */
1007 expr = (Expr *) lsecond(opexpr->args);
1008 tle = makeTargetEntry(expr,
1009 i,
1010 NULL,
1011 false);
1013
1014 /* Lookup the equality function (potentially cross-type) */
1015 cross_eq_funcoids[i - 1] = opexpr->opfuncid;
1016 fmgr_info(opexpr->opfuncid, &sstate->cur_eq_funcs[i - 1]);
1017 fmgr_info_set_expr((Node *) opexpr, &sstate->cur_eq_funcs[i - 1]);
1018
1019 /* Look up the equality function for the RHS type */
1021 NULL, &rhs_eq_oper))
1022 elog(ERROR, "could not find compatible hash operator for operator %u",
1023 opexpr->opno);
1024 sstate->tab_eq_funcoids[i - 1] = get_opcode(rhs_eq_oper);
1025
1026 /* Lookup the associated hash functions */
1027 if (!get_op_hash_functions(opexpr->opno,
1029 elog(ERROR, "could not find hash function for hash operator %u",
1030 opexpr->opno);
1032 fmgr_info(right_hashfn, &sstate->tab_hash_funcs[i - 1]);
1033
1034 /* Set collation */
1035 sstate->tab_collations[i - 1] = opexpr->inputcollid;
1036
1037 /* keyColIdx is just column numbers 1..n */
1038 sstate->keyColIdx[i - 1] = i;
1039
1040 i++;
1041 }
1042
1043 /*
1044 * Construct tupdescs, slots and projection nodes for left and right
1045 * sides. The lefthand expressions will be evaluated in the parent
1046 * plan node's exprcontext, which we don't have access to here.
1047 * Fortunately we can just pass NULL for now and fill it in later
1048 * (hack alert!). The righthand expressions will be evaluated in our
1049 * own innerecontext.
1050 */
1054 NULL,
1055 slot,
1056 parent,
1057 NULL);
1058
1062 sstate->innerecontext,
1063 slot,
1064 sstate->planstate,
1065 NULL);
1066
1067 /* Build the ExprState for generating hash values */
1071 sstate->tab_collations,
1072 sstate->numCols,
1073 sstate->keyColIdx,
1074 parent,
1075 0);
1076
1077 /*
1078 * Create comparator for lookups of rows in the table (potentially
1079 * cross-type comparisons).
1080 */
1083 ncols,
1084 sstate->keyColIdx,
1086 sstate->tab_collations,
1087 parent);
1088 }
1089
1090 return sstate;
1091}
int16 AttrNumber
Definition attnum.h:21
MemoryContext BumpContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition bump.c:133
#define Assert(condition)
Definition c.h:873
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
ExprState * ExecBuildHash32FromAttrs(TupleDesc desc, const TupleTableSlotOps *ops, FmgrInfo *hashfunctions, Oid *collations, int numCols, AttrNumber *keyColIdx, PlanState *parent, uint32 init_value)
Definition execExpr.c:4135
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition execExpr.c:143
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition execExpr.c:370
ExprState * ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc, const TupleTableSlotOps *lops, const TupleTableSlotOps *rops, int numCols, const AttrNumber *keyColIdx, const Oid *eqfunctions, const Oid *collations, PlanState *parent)
Definition execExpr.c:4459
const TupleTableSlotOps TTSOpsVirtual
Definition execTuples.c:84
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
const TupleTableSlotOps TTSOpsMinimalTuple
Definition execTuples.c:86
TupleDesc ExecTypeFromTL(List *targetList)
ExprContext * CreateExprContext(EState *estate)
Definition execUtils.c:307
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition fmgr.c:128
#define fmgr_info_set_expr(expr, finfo)
Definition fmgr.h:135
int i
Definition isn.c:77
List * lappend(List *list, void *datum)
Definition list.c:339
bool get_compatible_hash_operators(Oid opno, Oid *lhs_opno, Oid *rhs_opno)
Definition lsyscache.c:475
RegProcedure get_opcode(Oid opno)
Definition lsyscache.c:1435
bool get_op_hash_functions(Oid opno, RegProcedure *lhs_procno, RegProcedure *rhs_procno)
Definition lsyscache.c:575
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition makefuncs.c:289
void * palloc(Size size)
Definition mcxt.c:1387
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
static bool is_andclause(const void *clause)
Definition nodeFuncs.h:107
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define nodeTag(nodeptr)
Definition nodes.h:139
#define makeNode(_type_)
Definition nodes.h:161
#define castNode(_type_, nodeptr)
Definition nodes.h:182
#define lfirst_node(type, lc)
Definition pg_list.h:176
static int list_length(const List *l)
Definition pg_list.h:152
#define NIL
Definition pg_list.h:68
#define lfirst_int(lc)
Definition pg_list.h:173
#define list_make1(x1)
Definition pg_list.h:212
static void * list_nth(const List *list, int n)
Definition pg_list.h:299
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
unsigned int Oid
@ CTE_SUBLINK
Definition primnodes.h:1036
ParamExecData * es_param_exec_vals
Definition execnodes.h:707
List * es_subplanstates
Definition execnodes.h:727
Definition pg_list.h:54
Definition nodes.h:135
Oid opno
Definition primnodes.h:850
List * args
Definition primnodes.h:868
void * execPlan
Definition params.h:147
EState * state
Definition execnodes.h:1169
TupleHashTable hashtable
Definition execnodes.h:1024
ExprState * lhs_hash_expr
Definition execnodes.h:1037
PlanState * parent
Definition execnodes.h:1016
ExprState * cur_eq_comp
Definition execnodes.h:1039
Oid * tab_eq_funcoids
Definition execnodes.h:1033
ExprContext * innerecontext
Definition execnodes.h:1029
FmgrInfo * tab_hash_funcs
Definition execnodes.h:1036
FmgrInfo * cur_eq_funcs
Definition execnodes.h:1038
PlanState * planstate
Definition execnodes.h:1015
HeapTuple curTuple
Definition execnodes.h:1018
AttrNumber * keyColIdx
Definition execnodes.h:1032
TupleDesc descRight
Definition execnodes.h:1021
SubPlan * subplan
Definition execnodes.h:1014
ProjectionInfo * projLeft
Definition execnodes.h:1022
ProjectionInfo * projRight
Definition execnodes.h:1023
ExprState * testexpr
Definition execnodes.h:1017
MemoryContext tuplesContext
Definition execnodes.h:1028
Oid * tab_collations
Definition execnodes.h:1035
TupleHashTable hashnulls
Definition execnodes.h:1025
int plan_id
Definition primnodes.h:1102
char * plan_name
Definition primnodes.h:1104
bool useHashTable
Definition primnodes.h:1112
Node * testexpr
Definition primnodes.h:1099
List * parParam
Definition primnodes.h:1123
List * setParam
Definition primnodes.h:1121
SubLinkType subLinkType
Definition primnodes.h:1097

References ALLOCSET_DEFAULT_SIZES, OpExpr::args, Assert, BumpContextCreate(), castNode, CreateExprContext(), CTE_SUBLINK, SubPlanState::cur_eq_comp, SubPlanState::cur_eq_funcs, SubPlanState::curArray, CurrentMemoryContext, SubPlanState::curTuple, SubPlanState::descRight, elog, ERROR, EState::es_param_exec_vals, EState::es_subplanstates, ExecBuildGroupingEqual(), ExecBuildHash32FromAttrs(), ExecBuildProjectionInfo(), ExecInitExpr(), ExecInitExtraTupleSlot(), ParamExecData::execPlan, ExecTypeFromTL(), fb(), fmgr_info(), fmgr_info_set_expr, get_compatible_hash_operators(), get_op_hash_functions(), get_opcode(), SubPlanState::hashnulls, SubPlanState::hashtable, i, SubPlanState::innerecontext, is_andclause(), IsA, SubPlanState::keyColIdx, lappend(), lfirst_int, lfirst_node, SubPlanState::lhs_hash_expr, linitial, list_length(), list_make1, list_nth(), lsecond, makeNode, makeTargetEntry(), NIL, nodeTag, SubPlanState::numCols, OpExpr::opno, palloc(), SubPlanState::parent, SubPlan::parParam, SubPlan::plan_id, SubPlan::plan_name, SubPlanState::planstate, PointerGetDatum(), SubPlanState::projLeft, SubPlanState::projRight, SubPlan::setParam, PlanState::state, SubPlan::subLinkType, SubPlanState::subplan, SubPlanState::tab_collations, SubPlanState::tab_eq_funcoids, SubPlanState::tab_hash_funcs, SubPlanState::testexpr, SubPlan::testexpr, TTSOpsMinimalTuple, TTSOpsVirtual, SubPlanState::tuplesContext, and SubPlan::useHashTable.

Referenced by ExecInitNode(), and ExecInitSubPlanExpr().

◆ ExecReScanSetParamPlan()

void ExecReScanSetParamPlan ( SubPlanState node,
PlanState parent 
)
extern

Definition at line 1317 of file nodeSubplan.c.

1318{
1319 PlanState *planstate = node->planstate;
1320 SubPlan *subplan = node->subplan;
1321 EState *estate = parent->state;
1322 ListCell *l;
1323
1324 /* sanity checks */
1325 if (subplan->parParam != NIL)
1326 elog(ERROR, "direct correlated subquery unsupported as initplan");
1327 if (subplan->setParam == NIL)
1328 elog(ERROR, "setParam list of initplan is empty");
1329 if (bms_is_empty(planstate->plan->extParam))
1330 elog(ERROR, "extParam set of initplan is empty");
1331
1332 /*
1333 * Don't actually re-scan: it'll happen inside ExecSetParamPlan if needed.
1334 */
1335
1336 /*
1337 * Mark this subplan's output parameters as needing recalculation.
1338 *
1339 * CTE subplans are never executed via parameter recalculation; instead
1340 * they get run when called by nodeCtescan.c. So don't mark the output
1341 * parameter of a CTE subplan as dirty, but do set the chgParam bit for it
1342 * so that dependent plan nodes will get told to rescan.
1343 */
1344 foreach(l, subplan->setParam)
1345 {
1346 int paramid = lfirst_int(l);
1347 ParamExecData *prm = &(estate->es_param_exec_vals[paramid]);
1348
1349 if (subplan->subLinkType != CTE_SUBLINK)
1350 prm->execPlan = node;
1351
1352 parent->chgParam = bms_add_member(parent->chgParam, paramid);
1353 }
1354}
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:814
#define bms_is_empty(a)
Definition bitmapset.h:118
Plan * plan
Definition execnodes.h:1167
Bitmapset * chgParam
Definition execnodes.h:1199
Bitmapset * extParam
Definition plannodes.h:249

References bms_add_member(), bms_is_empty, PlanState::chgParam, CTE_SUBLINK, elog, ERROR, EState::es_param_exec_vals, ParamExecData::execPlan, Plan::extParam, fb(), lfirst_int, NIL, SubPlan::parParam, PlanState::plan, SubPlanState::planstate, SubPlan::setParam, PlanState::state, SubPlan::subLinkType, and SubPlanState::subplan.

Referenced by ExecReScan().

◆ ExecSetParamPlan()

void ExecSetParamPlan ( SubPlanState node,
ExprContext econtext 
)
extern

Definition at line 1118 of file nodeSubplan.c.

1119{
1120 SubPlan *subplan = node->subplan;
1121 PlanState *planstate = node->planstate;
1122 SubLinkType subLinkType = subplan->subLinkType;
1123 EState *estate = planstate->state;
1124 ScanDirection dir = estate->es_direction;
1125 MemoryContext oldcontext;
1126 TupleTableSlot *slot;
1127 ListCell *l;
1128 bool found = false;
1129 ArrayBuildStateAny *astate = NULL;
1130
1131 if (subLinkType == ANY_SUBLINK ||
1132 subLinkType == ALL_SUBLINK)
1133 elog(ERROR, "ANY/ALL subselect unsupported as initplan");
1134 if (subLinkType == CTE_SUBLINK)
1135 elog(ERROR, "CTE subplans should not be executed via ExecSetParamPlan");
1136 if (subplan->parParam || subplan->args)
1137 elog(ERROR, "correlated subplans should not be executed via ExecSetParamPlan");
1138
1139 /*
1140 * Enforce forward scan direction regardless of caller. It's hard but not
1141 * impossible to get here in backward scan, so make it work anyway.
1142 */
1144
1145 /* Initialize ArrayBuildStateAny in caller's context, if needed */
1146 if (subLinkType == ARRAY_SUBLINK)
1147 astate = initArrayResultAny(subplan->firstColType,
1148 CurrentMemoryContext, true);
1149
1150 /*
1151 * Must switch to per-query memory context.
1152 */
1153 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
1154
1155 /*
1156 * Run the plan. (If it needs to be rescanned, the first ExecProcNode
1157 * call will take care of that.)
1158 */
1159 for (slot = ExecProcNode(planstate);
1160 !TupIsNull(slot);
1161 slot = ExecProcNode(planstate))
1162 {
1164 int i = 1;
1165
1166 if (subLinkType == EXISTS_SUBLINK)
1167 {
1168 /* There can be only one setParam... */
1169 int paramid = linitial_int(subplan->setParam);
1170 ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
1171
1172 prm->execPlan = NULL;
1173 prm->value = BoolGetDatum(true);
1174 prm->isnull = false;
1175 found = true;
1176 break;
1177 }
1178
1179 if (subLinkType == ARRAY_SUBLINK)
1180 {
1181 Datum dvalue;
1182 bool disnull;
1183
1184 found = true;
1185 /* stash away current value */
1187 dvalue = slot_getattr(slot, 1, &disnull);
1188 astate = accumArrayResultAny(astate, dvalue, disnull,
1189 subplan->firstColType, oldcontext);
1190 /* keep scanning subplan to collect all values */
1191 continue;
1192 }
1193
1194 if (found &&
1195 (subLinkType == EXPR_SUBLINK ||
1196 subLinkType == MULTIEXPR_SUBLINK ||
1197 subLinkType == ROWCOMPARE_SUBLINK))
1198 ereport(ERROR,
1200 errmsg("more than one row returned by a subquery used as an expression")));
1201
1202 found = true;
1203
1204 /*
1205 * We need to copy the subplan's tuple into our own context, in case
1206 * any of the params are pass-by-ref type --- the pointers stored in
1207 * the param structs will point at this copied tuple! node->curTuple
1208 * keeps track of the copied tuple for eventual freeing.
1209 */
1210 if (node->curTuple)
1211 heap_freetuple(node->curTuple);
1212 node->curTuple = ExecCopySlotHeapTuple(slot);
1213
1214 /*
1215 * Now set all the setParam params from the columns of the tuple
1216 */
1217 foreach(l, subplan->setParam)
1218 {
1219 int paramid = lfirst_int(l);
1220 ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
1221
1222 prm->execPlan = NULL;
1223 prm->value = heap_getattr(node->curTuple, i, tdesc,
1224 &(prm->isnull));
1225 i++;
1226 }
1227 }
1228
1229 if (subLinkType == ARRAY_SUBLINK)
1230 {
1231 /* There can be only one setParam... */
1232 int paramid = linitial_int(subplan->setParam);
1233 ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
1234
1235 /*
1236 * We build the result array in query context so it won't disappear;
1237 * to avoid leaking memory across repeated calls, we have to remember
1238 * the latest value, much as for curTuple above.
1239 */
1240 if (node->curArray != PointerGetDatum(NULL))
1242 node->curArray = makeArrayResultAny(astate,
1243 econtext->ecxt_per_query_memory,
1244 true);
1245 prm->execPlan = NULL;
1246 prm->value = node->curArray;
1247 prm->isnull = false;
1248 }
1249 else if (!found)
1250 {
1251 if (subLinkType == EXISTS_SUBLINK)
1252 {
1253 /* There can be only one setParam... */
1254 int paramid = linitial_int(subplan->setParam);
1255 ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
1256
1257 prm->execPlan = NULL;
1258 prm->value = BoolGetDatum(false);
1259 prm->isnull = false;
1260 }
1261 else
1262 {
1263 /* For other sublink types, set all the output params to NULL */
1264 foreach(l, subplan->setParam)
1265 {
1266 int paramid = lfirst_int(l);
1267 ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
1268
1269 prm->execPlan = NULL;
1270 prm->value = (Datum) 0;
1271 prm->isnull = true;
1272 }
1273 }
1274 }
1275
1276 MemoryContextSwitchTo(oldcontext);
1277
1278 /* restore scan direction */
1279 estate->es_direction = dir;
1280}
ArrayBuildStateAny * initArrayResultAny(Oid input_type, MemoryContext rcontext, bool subcontext)
ArrayBuildStateAny * accumArrayResultAny(ArrayBuildStateAny *astate, Datum dvalue, bool disnull, Oid input_type, MemoryContext rcontext)
Datum makeArrayResultAny(ArrayBuildStateAny *astate, MemoryContext rcontext, bool release)
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
static TupleTableSlot * ExecProcNode(PlanState *node)
Definition executor.h:314
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
void pfree(void *pointer)
Definition mcxt.c:1616
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define linitial_int(l)
Definition pg_list.h:179
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
uint64_t Datum
Definition postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:342
SubLinkType
Definition primnodes.h:1028
@ ARRAY_SUBLINK
Definition primnodes.h:1035
@ ANY_SUBLINK
Definition primnodes.h:1031
@ MULTIEXPR_SUBLINK
Definition primnodes.h:1034
@ EXPR_SUBLINK
Definition primnodes.h:1033
@ ROWCOMPARE_SUBLINK
Definition primnodes.h:1032
@ ALL_SUBLINK
Definition primnodes.h:1030
@ EXISTS_SUBLINK
Definition primnodes.h:1029
ScanDirection
Definition sdir.h:25
@ ForwardScanDirection
Definition sdir.h:28
ScanDirection es_direction
Definition execnodes.h:661
ParamExecData * ecxt_param_exec_vals
Definition execnodes.h:286
MemoryContext ecxt_per_query_memory
Definition execnodes.h:282
List * args
Definition primnodes.h:1124
Oid firstColType
Definition primnodes.h:1106
TupleDesc tts_tupleDescriptor
Definition tuptable.h:122
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:160
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition tuptable.h:484
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:398
#define TupIsNull(slot)
Definition tuptable.h:309

References accumArrayResultAny(), ALL_SUBLINK, ANY_SUBLINK, SubPlan::args, ARRAY_SUBLINK, Assert, BoolGetDatum(), CTE_SUBLINK, SubPlanState::curArray, CurrentMemoryContext, SubPlanState::curTuple, DatumGetPointer(), ExprContext::ecxt_param_exec_vals, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, EState::es_direction, ExecCopySlotHeapTuple(), ParamExecData::execPlan, ExecProcNode(), EXISTS_SUBLINK, EXPR_SUBLINK, fb(), SubPlan::firstColType, ForwardScanDirection, heap_freetuple(), heap_getattr(), i, initArrayResultAny(), lfirst_int, linitial_int, makeArrayResultAny(), MemoryContextSwitchTo(), MULTIEXPR_SUBLINK, SubPlan::parParam, pfree(), SubPlanState::planstate, PointerGetDatum(), ROWCOMPARE_SUBLINK, SubPlan::setParam, slot_getattr(), PlanState::state, SubPlan::subLinkType, SubPlanState::subplan, TupleTableSlot::tts_tupleDescriptor, TupIsNull, and TupleDescAttr().

Referenced by ExecEvalParamExec(), and ExecSetParamPlanMulti().

◆ ExecSetParamPlanMulti()

void ExecSetParamPlanMulti ( const Bitmapset params,
ExprContext econtext 
)
extern

Definition at line 1294 of file nodeSubplan.c.

1295{
1296 int paramid;
1297
1298 paramid = -1;
1299 while ((paramid = bms_next_member(params, paramid)) >= 0)
1300 {
1301 ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
1302
1303 if (prm->execPlan != NULL)
1304 {
1305 /* Parameter not evaluated yet, so go do it */
1306 ExecSetParamPlan(prm->execPlan, econtext);
1307 /* ExecSetParamPlan should have processed this param... */
1308 Assert(prm->execPlan == NULL);
1309 }
1310 }
1311}
int bms_next_member(const Bitmapset *a, int prevbit)
Definition bitmapset.c:1305
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)

References Assert, bms_next_member(), ExprContext::ecxt_param_exec_vals, ExecSetParamPlan(), and fb().

Referenced by EvalPlanQualBegin(), EvalPlanQualStart(), ExecInitParallelPlan(), and ExecParallelReinitialize().

◆ ExecSubPlan()

Datum ExecSubPlan ( SubPlanState node,
ExprContext econtext,
bool isNull 
)
extern

Definition at line 59 of file nodeSubplan.c.

62{
63 SubPlan *subplan = node->subplan;
64 EState *estate = node->planstate->state;
65 ScanDirection dir = estate->es_direction;
66 Datum retval;
67
69
70 /* Set non-null as default */
71 *isNull = false;
72
73 /* Sanity checks */
74 if (subplan->subLinkType == CTE_SUBLINK)
75 elog(ERROR, "CTE subplans should not be executed via ExecSubPlan");
76 if (subplan->setParam != NIL && subplan->subLinkType != MULTIEXPR_SUBLINK)
77 elog(ERROR, "cannot set parent params from subquery");
78
79 /* Force forward-scan mode for evaluation */
81
82 /* Select appropriate evaluation strategy */
83 if (subplan->useHashTable)
84 retval = ExecHashSubPlan(node, econtext, isNull);
85 else
86 retval = ExecScanSubPlan(node, econtext, isNull);
87
88 /* restore scan direction */
89 estate->es_direction = dir;
90
91 return retval;
92}
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
static Datum ExecHashSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition nodeSubplan.c:98
static Datum ExecScanSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)

References CHECK_FOR_INTERRUPTS, CTE_SUBLINK, elog, ERROR, EState::es_direction, ExecHashSubPlan(), ExecScanSubPlan(), ForwardScanDirection, MULTIEXPR_SUBLINK, NIL, SubPlanState::planstate, SubPlan::setParam, PlanState::state, SubPlan::subLinkType, SubPlanState::subplan, and SubPlan::useHashTable.

Referenced by ExecEvalSubPlan().