@@ -36,7 +36,11 @@ static void ConstructPostProcessingPhase(CoordinatorLevelOperator *coordOp, Mult
3636
3737
3838
39- /* QueryExecutor */
39+ /*
40+ * QueryExecutor drives a distributed query end-to-end: runs every planned
41+ * strategy via RunQueryExecutor(), then stitches the resulting per-strategy
42+ * tasks into the single SQL statement returned as a GeneralScan.
43+ */
4044extern GeneralScan *
4145QueryExecutor (DistributedSpatiotemporalQueryPlan * distPlan , bool explain )
4246{
@@ -45,7 +49,15 @@ QueryExecutor(DistributedSpatiotemporalQueryPlan *distPlan, bool explain)
4549 return generalScan ;
4650}
4751
48- /* RunQueryExecutor */
52+ /*
53+ * RunQueryExecutor walks distPlan's chosen PlanTask strategies in order and
54+ * materializes each into ExecutorTasks: NonColocation triggers a reshuffle
55+ * of one side into a temporary colocated table followed by a neighbor scan,
56+ * Colocation performs a direct self-tiling (tile-key equi-join) scan, and
57+ * PredicatePushDown runs the predicate as-is on the worker. `explain`
58+ * suppresses the actual reshuffle/data-modifying SPI calls so EXPLAIN can
59+ * describe the plan without side effects.
60+ */
4961extern MultiPhaseExecutor *
5062RunQueryExecutor (DistributedSpatiotemporalQueryPlan * distPlan , bool explain )
5163{
@@ -102,7 +114,13 @@ RunQueryExecutor(DistributedSpatiotemporalQueryPlan *distPlan, bool explain)
102114}
103115
104116
105- /* Executor Job: Colocation */
117+ /*
118+ * ColocateRte makes a plain Citus-distributed `other` table colocated with
119+ * `base`: it materializes other's data into a fresh reshuffled table
120+ * distributed on base's distribution column/shard count, then rebalances
121+ * base's tiles into it so both sides can be scanned tile-by-tile without
122+ * cross-node data movement. Returns false if `other` is not a CitusRte.
123+ */
106124extern bool
107125ColocateRte (STMultirelation * base , Rte * other )
108126{
@@ -142,7 +160,12 @@ ColocateRte(STMultirelation *base, Rte *other)
142160
143161}
144162
145- /* Executor Job: Create the reshuffling table */
163+ /*
164+ * createReshuffledTable is the STRte counterpart of ColocateRte(): it
165+ * materializes `other`'s data into a fresh table distributed to match
166+ * `base`'s shard count, then rebalances base's tiles into it so both
167+ * spatiotemporal relations can be joined tile-by-tile.
168+ */
146169extern bool
147170createReshuffledTable (STMultirelation * base , STMultirelation * other )
148171{
@@ -175,7 +198,13 @@ createReshuffledTable(STMultirelation *base, STMultirelation *other)
175198 return true;
176199}
177200
178- /* Executor Job: Drop the reshuffled table if exists */
201+ /*
202+ * DropReshuffledTableIfExists drops the temporary per-query reshuffled
203+ * table from the extension's schema. The surrounding
204+ * commit/start-transaction pair runs the DDL in its own transaction so it
205+ * takes effect immediately and is visible to the CREATE that follows it,
206+ * rather than staying pending inside the planner's outer transaction.
207+ */
179208extern void
180209DropReshuffledTableIfExists (char * reshuffled_table )
181210{
@@ -192,7 +221,13 @@ DropReshuffledTableIfExists(char * reshuffled_table)
192221 PushActiveSnapshot (GetTransactionSnapshot ());
193222}
194223
195- /* Executor Job: Create the reshuffled table if not exists */
224+ /*
225+ * CreateReshuffledTableIfNotExists creates reshuffled_table as a `LIKE
226+ * org_table` copy in the extension's schema, optionally adding the tile-key
227+ * column (for tables that will be reshuffled/rebalanced across tiles). Runs
228+ * in its own commit/start-transaction bracket for the same reason as
229+ * DropReshuffledTableIfExists.
230+ */
196231extern void
197232CreateReshuffledTableIfNotExists (char * reshuffled_table , char * org_table , bool tile_key )
198233{
@@ -212,7 +247,12 @@ CreateReshuffledTableIfNotExists(char * reshuffled_table, char * org_table, bool
212247 PushActiveSnapshot (GetTransactionSnapshot ());
213248}
214249
215- /* Executor Job: Construct the neighbor scan */
250+ /*
251+ * ConstructNeighborScanQuery builds the task that scans `tbl` (the
252+ * reshuffled/colocated side) tile-by-tile against `base`'s tiling scheme,
253+ * widening the tile set searched (catalog_filtered) whenever the catalog
254+ * filter found more matching candidates than there are tiles.
255+ */
216256static void
217257ConstructNeighborScanQuery (Rte * tbl , char * query_string , STMultirelation * base ,MultiPhaseExecutor * multiPhaseExecutor )
218258{
@@ -243,7 +283,13 @@ ConstructNeighborScanQuery(Rte *tbl, char * query_string, STMultirelation *base,
243283 multiPhaseExecutor -> tasks = lappend (multiPhaseExecutor -> tasks , task );
244284}
245285
246- /* Executor Job: Construct the self tiling scan */
286+ /*
287+ * ConstructSelfTilingScanQuery builds the task for a Colocation-strategy
288+ * join: since both tables share the same tiling, the join reduces to
289+ * adding a `tile_key = tile_key` equality (replacing the query's `WHERE`)
290+ * so each tile only ever matches its own counterpart tile, avoiding any
291+ * cross-tile data transfer.
292+ */
247293static void
248294ConstructSelfTilingScanQuery (PlanTask * plan , char * query_string , MultiPhaseExecutor * multiPhaseExecutor )
249295{
@@ -269,7 +315,11 @@ ConstructSelfTilingScanQuery(PlanTask *plan, char * query_string, MultiPhaseExec
269315 multiPhaseExecutor -> tasks = lappend (multiPhaseExecutor -> tasks , task );
270316}
271317
272- /* Executor Job: Execute the reshuffling query */
318+ /*
319+ * ReshuffleData runs the INSERT ... SELECT that copies base's rows into the
320+ * reshuffled/colocated table (see createReshuffledTable/ColocateRte),
321+ * recording success in multiPhaseExecutor->dataReshuffled.
322+ */
273323static void
274324ReshuffleData (char * query_string , MultiPhaseExecutor * multiPhaseExecutor )
275325{
@@ -293,7 +343,11 @@ ReshuffleData(char *query_string, MultiPhaseExecutor *multiPhaseExecutor)
293343 }
294344}
295345
296- /* Executor Job: Index the reshuffled data */
346+ /*
347+ * IndexReshuffledData creates the spatiotemporal (GIST) index on the newly
348+ * reshuffled table's distribution column, needed before it can be scanned
349+ * efficiently in the neighbor-scan phase.
350+ */
297351static void
298352IndexReshuffledData (Rte * reshuffledTable , MultiPhaseExecutor * multiPhaseExecutor )
299353{
@@ -339,7 +393,14 @@ IndexReshuffledData(Rte *reshuffledTable, MultiPhaseExecutor *multiPhaseExecutor
339393
340394}
341395
342- /* Executor Job: GeneralScan */
396+ /*
397+ * ConstructGeneralQuery assembles the final SQL text to execute: it unions
398+ * together the worker-phase task query for each strategy used in the plan
399+ * (NonColocation -> neighbor scan, Colocation -> self-tiling scan,
400+ * PredicatePushDown -> push-down scan), then, if a coordinator-phase
401+ * (FINALScan) task exists, splices that union in as its `intermediate`
402+ * subquery so the coordinator can post-process the combined worker output.
403+ */
343404static GeneralScan *
344405ConstructGeneralQuery (DistributedSpatiotemporalQueryPlan * distPlan , MultiPhaseExecutor * multiPhaseExecutor )
345406{
@@ -400,7 +461,12 @@ ConstructGeneralQuery(DistributedSpatiotemporalQueryPlan *distPlan, MultiPhaseEx
400461 return generalScan ;
401462}
402463
403- /* Executor Job: Construct the self tiling scan */
464+ /*
465+ * ConstructPredicatePushDownQuery builds the task for the PredicatePushDown
466+ * strategy: the original query text is run as-is (no rewriting), since the
467+ * predicate can be fully evaluated on the worker without any coordinator
468+ * merge step.
469+ */
404470static void
405471ConstructPredicatePushDownQuery (PlanTask * plan , char * query_string , MultiPhaseExecutor * multiPhaseExecutor )
406472{
@@ -413,6 +479,7 @@ ConstructPredicatePushDownQuery(PlanTask *plan, char * query_string, MultiPhaseE
413479 multiPhaseExecutor -> tasks = lappend (multiPhaseExecutor -> tasks , task );
414480}
415481
482+ /* GetTaskType renders task's ExecTaskType as a human-readable label for EXPLAIN output. */
416483extern Datum
417484GetTaskType (ExecutorTask * task )
418485{
@@ -422,6 +489,12 @@ GetTaskType(ExecutorTask *task)
422489 return CStringGetDatum ("Self Tiling Scan" );
423490}
424491
492+ /*
493+ * ConstructPostProcessingPhase builds the coordinator-phase tasks (see
494+ * ProcessIntermediateTasks/ProcessFinalTasks) for any distributed
495+ * aggregates recorded in coordOp, so they get merged into the final query
496+ * by ConstructGeneralQuery().
497+ */
425498static void
426499ConstructPostProcessingPhase (CoordinatorLevelOperator * coordOp , MultiPhaseExecutor * multiPhaseExecutor )
427500{
0 commit comments