MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecSerializePlan

Function ExecSerializePlan

src/backend/executor/execParallel.c:147–221  ·  view source on GitHub ↗

* Create a serialized representation of the plan to be sent to each worker. */

Source from the content-addressed store, hash-verified

145 * Create a serialized representation of the plan to be sent to each worker.
146 */
147static char *
148ExecSerializePlan(Plan *plan, EState *estate)
149{
150 PlannedStmt *pstmt;
151 ListCell *lc;
152
153 /* We can't scribble on the original plan, so make a copy. */
154 plan = copyObject(plan);
155
156 /*
157 * The worker will start its own copy of the executor, and that copy will
158 * insert a junk filter if the toplevel node has any resjunk entries. We
159 * don't want that to happen, because while resjunk columns shouldn't be
160 * sent back to the user, here the tuples are coming back to another
161 * backend which may very well need them. So mutate the target list
162 * accordingly. This is sort of a hack; there might be better ways to do
163 * this...
164 */
165 foreach(lc, plan->targetlist)
166 {
167 TargetEntry *tle = lfirst_node(TargetEntry, lc);
168
169 tle->resjunk = false;
170 }
171
172 /*
173 * Create a dummy PlannedStmt. Most of the fields don't need to be valid
174 * for our purposes, but the worker will need at least a minimal
175 * PlannedStmt to start the executor.
176 */
177 pstmt = makeNode(PlannedStmt);
178 pstmt->commandType = CMD_SELECT;
179 pstmt->queryId = pgstat_get_my_query_id();
180 pstmt->hasReturning = false;
181 pstmt->hasModifyingCTE = false;
182 pstmt->canSetTag = true;
183 pstmt->transientPlan = false;
184 pstmt->dependsOnRole = false;
185 pstmt->parallelModeNeeded = false;
186 pstmt->planTree = plan;
187 pstmt->rtable = estate->es_range_table;
188 pstmt->resultRelations = NIL;
189 pstmt->appendRelations = NIL;
190
191 /*
192 * Transfer only parallel-safe subplans, leaving a NULL "hole" in the list
193 * for unsafe ones (so that the list indexes of the safe ones are
194 * preserved). This positively ensures that the worker won't try to run,
195 * or even do ExecInitNode on, an unsafe subplan. That's important to
196 * protect, eg, non-parallel-aware FDWs from getting into trouble.
197 */
198 pstmt->subplans = NIL;
199 foreach(lc, estate->es_plannedstmt->subplans)
200 {
201 Plan *subplan = (Plan *) lfirst(lc);
202
203 if (subplan && !subplan->parallel_safe)
204 subplan = NULL;

Callers 1

ExecInitParallelPlanFunction · 0.85

Calls 4

pgstat_get_my_query_idFunction · 0.85
lappendFunction · 0.85
nodeToStringFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected