2828#include "executor/nodeBitmapHeapscan.h"
2929#include "executor/nodeCustom.h"
3030#include "executor/nodeForeignscan.h"
31- #include "executor/nodeSeqscan.h"
3231#include "executor/nodeIndexscan.h"
3332#include "executor/nodeIndexonlyscan.h"
33+ #include "executor/nodeSeqscan.h"
34+ #include "executor/nodeSort.h"
3435#include "executor/tqueue.h"
3536#include "nodes/nodeFuncs.h"
3637#include "optimizer/planmain.h"
@@ -202,10 +203,10 @@ ExecSerializePlan(Plan *plan, EState *estate)
202203}
203204
204205/*
205- * Ordinary plan nodes won't do anything here, but parallel-aware plan nodes
206- * may need some state which is shared across all parallel workers. Before
207- * we size the DSM, give them a chance to call shm_toc_estimate_chunk or
208- * shm_toc_estimate_keys on &pcxt->estimator.
206+ * Parallel-aware plan nodes (and occasionally others) may need some state
207+ * which is shared across all parallel workers. Before we size the DSM, give
208+ * them a chance to call shm_toc_estimate_chunk or shm_toc_estimate_keys on
209+ * &pcxt->estimator.
209210 *
210211 * While we're at it, count the number of PlanState nodes in the tree, so
211212 * we know how many SharedPlanStateInstrumentation structures we need.
@@ -219,38 +220,43 @@ ExecParallelEstimate(PlanState *planstate, ExecParallelEstimateContext *e)
219220 /* Count this node. */
220221 e -> nnodes ++ ;
221222
222- /* Call estimators for parallel-aware nodes. */
223- if (planstate -> plan -> parallel_aware )
223+ switch (nodeTag (planstate ))
224224 {
225- switch (nodeTag (planstate ))
226- {
227- case T_SeqScanState :
225+ case T_SeqScanState :
226+ if (planstate -> plan -> parallel_aware )
228227 ExecSeqScanEstimate ((SeqScanState * ) planstate ,
229228 e -> pcxt );
230- break ;
231- case T_IndexScanState :
229+ break ;
230+ case T_IndexScanState :
231+ if (planstate -> plan -> parallel_aware )
232232 ExecIndexScanEstimate ((IndexScanState * ) planstate ,
233233 e -> pcxt );
234- break ;
235- case T_IndexOnlyScanState :
234+ break ;
235+ case T_IndexOnlyScanState :
236+ if (planstate -> plan -> parallel_aware )
236237 ExecIndexOnlyScanEstimate ((IndexOnlyScanState * ) planstate ,
237238 e -> pcxt );
238- break ;
239- case T_ForeignScanState :
239+ break ;
240+ case T_ForeignScanState :
241+ if (planstate -> plan -> parallel_aware )
240242 ExecForeignScanEstimate ((ForeignScanState * ) planstate ,
241243 e -> pcxt );
242- break ;
243- case T_CustomScanState :
244+ break ;
245+ case T_CustomScanState :
246+ if (planstate -> plan -> parallel_aware )
244247 ExecCustomScanEstimate ((CustomScanState * ) planstate ,
245248 e -> pcxt );
246- break ;
247- case T_BitmapHeapScanState :
249+ break ;
250+ case T_BitmapHeapScanState :
251+ if (planstate -> plan -> parallel_aware )
248252 ExecBitmapHeapEstimate ((BitmapHeapScanState * ) planstate ,
249253 e -> pcxt );
250- break ;
251- default :
252- break ;
253- }
254+ break ;
255+ case T_SortState :
256+ /* even when not parallel-aware */
257+ ExecSortEstimate ((SortState * ) planstate , e -> pcxt );
258+ default :
259+ break ;
254260 }
255261
256262 return planstate_tree_walker (planstate , ExecParallelEstimate , e );
@@ -276,46 +282,51 @@ ExecParallelInitializeDSM(PlanState *planstate,
276282 d -> nnodes ++ ;
277283
278284 /*
279- * Call initializers for parallel-aware plan nodes.
285+ * Call initializers for DSM-using plan nodes.
280286 *
281- * Ordinary plan nodes won't do anything here, but parallel-aware plan
282- * nodes may need to initialize shared state in the DSM before parallel
283- * workers are available . They can allocate the space they previously
287+ * Most plan nodes won't do anything here, but plan nodes that allocated
288+ * DSM may need to initialize shared state in the DSM before parallel
289+ * workers are launched . They can allocate the space they previously
284290 * estimated using shm_toc_allocate, and add the keys they previously
285291 * estimated using shm_toc_insert, in each case targeting pcxt->toc.
286292 */
287- if ( planstate -> plan -> parallel_aware )
293+ switch ( nodeTag ( planstate ) )
288294 {
289- switch (nodeTag (planstate ))
290- {
291- case T_SeqScanState :
295+ case T_SeqScanState :
296+ if (planstate -> plan -> parallel_aware )
292297 ExecSeqScanInitializeDSM ((SeqScanState * ) planstate ,
293298 d -> pcxt );
294- break ;
295- case T_IndexScanState :
299+ break ;
300+ case T_IndexScanState :
301+ if (planstate -> plan -> parallel_aware )
296302 ExecIndexScanInitializeDSM ((IndexScanState * ) planstate ,
297303 d -> pcxt );
298- break ;
299- case T_IndexOnlyScanState :
304+ break ;
305+ case T_IndexOnlyScanState :
306+ if (planstate -> plan -> parallel_aware )
300307 ExecIndexOnlyScanInitializeDSM ((IndexOnlyScanState * ) planstate ,
301308 d -> pcxt );
302- break ;
303- case T_ForeignScanState :
309+ break ;
310+ case T_ForeignScanState :
311+ if (planstate -> plan -> parallel_aware )
304312 ExecForeignScanInitializeDSM ((ForeignScanState * ) planstate ,
305313 d -> pcxt );
306- break ;
307- case T_CustomScanState :
314+ break ;
315+ case T_CustomScanState :
316+ if (planstate -> plan -> parallel_aware )
308317 ExecCustomScanInitializeDSM ((CustomScanState * ) planstate ,
309318 d -> pcxt );
310- break ;
311- case T_BitmapHeapScanState :
319+ break ;
320+ case T_BitmapHeapScanState :
321+ if (planstate -> plan -> parallel_aware )
312322 ExecBitmapHeapInitializeDSM ((BitmapHeapScanState * ) planstate ,
313323 d -> pcxt );
314- break ;
315-
316- default :
317- break ;
318- }
324+ break ;
325+ case T_SortState :
326+ /* even when not parallel-aware */
327+ ExecSortInitializeDSM ((SortState * ) planstate , d -> pcxt );
328+ default :
329+ break ;
319330 }
320331
321332 return planstate_tree_walker (planstate , ExecParallelInitializeDSM , d );
@@ -642,6 +653,13 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate,
642653 planstate -> worker_instrument -> num_workers = instrumentation -> num_workers ;
643654 memcpy (& planstate -> worker_instrument -> instrument , instrument , ibytes );
644655
656+ /*
657+ * Perform any node-type-specific work that needs to be done. Currently,
658+ * only Sort nodes need to do anything here.
659+ */
660+ if (IsA (planstate , SortState ))
661+ ExecSortRetrieveInstrumentation ((SortState * ) planstate );
662+
645663 return planstate_tree_walker (planstate , ExecParallelRetrieveInstrumentation ,
646664 instrumentation );
647665}
@@ -801,35 +819,40 @@ ExecParallelInitializeWorker(PlanState *planstate, shm_toc *toc)
801819 if (planstate == NULL )
802820 return false;
803821
804- /* Call initializers for parallel-aware plan nodes. */
805- if (planstate -> plan -> parallel_aware )
822+ switch (nodeTag (planstate ))
806823 {
807- switch (nodeTag (planstate ))
808- {
809- case T_SeqScanState :
824+ case T_SeqScanState :
825+ if (planstate -> plan -> parallel_aware )
810826 ExecSeqScanInitializeWorker ((SeqScanState * ) planstate , toc );
811- break ;
812- case T_IndexScanState :
827+ break ;
828+ case T_IndexScanState :
829+ if (planstate -> plan -> parallel_aware )
813830 ExecIndexScanInitializeWorker ((IndexScanState * ) planstate , toc );
814- break ;
815- case T_IndexOnlyScanState :
831+ break ;
832+ case T_IndexOnlyScanState :
833+ if (planstate -> plan -> parallel_aware )
816834 ExecIndexOnlyScanInitializeWorker ((IndexOnlyScanState * ) planstate , toc );
817- break ;
818- case T_ForeignScanState :
835+ break ;
836+ case T_ForeignScanState :
837+ if (planstate -> plan -> parallel_aware )
819838 ExecForeignScanInitializeWorker ((ForeignScanState * ) planstate ,
820839 toc );
821- break ;
822- case T_CustomScanState :
840+ break ;
841+ case T_CustomScanState :
842+ if (planstate -> plan -> parallel_aware )
823843 ExecCustomScanInitializeWorker ((CustomScanState * ) planstate ,
824844 toc );
825- break ;
826- case T_BitmapHeapScanState :
845+ break ;
846+ case T_BitmapHeapScanState :
847+ if (planstate -> plan -> parallel_aware )
827848 ExecBitmapHeapInitializeWorker (
828849 (BitmapHeapScanState * ) planstate , toc );
829- break ;
830- default :
831- break ;
832- }
850+ break ;
851+ case T_SortState :
852+ /* even when not parallel-aware */
853+ ExecSortInitializeWorker ((SortState * ) planstate , toc );
854+ default :
855+ break ;
833856 }
834857
835858 return planstate_tree_walker (planstate , ExecParallelInitializeWorker , toc );
0 commit comments