@@ -250,9 +250,13 @@ TidRangeNext(TidRangeScanState *node)
250250 }
251251 else
252252 {
253- /* rescan with the updated TID range */
254- table_rescan_tidrange (scandesc , & node -> trss_mintid ,
255- & node -> trss_maxtid );
253+ /* rescan with the updated TID range only in non-parallel mode */
254+ if (scandesc -> rs_parallel == NULL )
255+ {
256+ /* rescan with the updated TID range */
257+ table_rescan_tidrange (scandesc , & node -> trss_mintid ,
258+ & node -> trss_maxtid );
259+ }
256260 }
257261
258262 node -> trss_inScan = true;
@@ -415,3 +419,107 @@ ExecInitTidRangeScan(TidRangeScan *node, EState *estate, int eflags)
415419 */
416420 return tidrangestate ;
417421}
422+ /* ----------------------------------------------------------------
423+ * Parallel Scan Support
424+ * ----------------------------------------------------------------
425+ */
426+
427+ /* ----------------------------------------------------------------
428+ * ExecTidRangeScanEstimate
429+ *
430+ * Compute the amount of space we'll need in the parallel
431+ * query DSM, and inform pcxt->estimator about our needs.
432+ * ----------------------------------------------------------------
433+ */
434+ void
435+ ExecTidRangeScanEstimate (TidRangeScanState * node , ParallelContext * pcxt )
436+ {
437+ EState * estate = node -> ss .ps .state ;
438+
439+ node -> trss_pscanlen =
440+ table_parallelscan_estimate (node -> ss .ss_currentRelation ,
441+ estate -> es_snapshot );
442+ shm_toc_estimate_chunk (& pcxt -> estimator , node -> trss_pscanlen );
443+ shm_toc_estimate_keys (& pcxt -> estimator , 1 );
444+ }
445+
446+ /* ----------------------------------------------------------------
447+ * ExecTidRangeScanInitializeDSM
448+ *
449+ * Set up a parallel TID scan descriptor.
450+ * ----------------------------------------------------------------
451+ */
452+ void
453+ ExecTidRangeScanInitializeDSM (TidRangeScanState * node , ParallelContext * pcxt )
454+ {
455+ EState * estate = node -> ss .ps .state ;
456+ ParallelTableScanDesc pscan ;
457+
458+ pscan = shm_toc_allocate (pcxt -> toc , node -> trss_pscanlen );
459+ table_parallelscan_initialize (node -> ss .ss_currentRelation ,
460+ pscan ,
461+ estate -> es_snapshot );
462+ shm_toc_insert (pcxt -> toc , node -> ss .ps .plan -> plan_node_id , pscan );
463+
464+ /*
465+ * Initialize parallel scan descriptor with given TID range if it can be
466+ * evaluated successfully.
467+ */
468+ if (TidRangeEval (node ))
469+ node -> ss .ss_currentScanDesc =
470+ table_beginscan_parallel_tidrange (node -> ss .ss_currentRelation , pscan ,
471+ & node -> trss_mintid , & node -> trss_maxtid );
472+ else
473+ node -> ss .ss_currentScanDesc =
474+ table_beginscan_parallel_tidrange (node -> ss .ss_currentRelation , pscan ,
475+ NULL , NULL );
476+ }
477+
478+ /* ----------------------------------------------------------------
479+ * ExecTidRangeScanReInitializeDSM
480+ *
481+ * Reset shared state before beginning a fresh scan.
482+ * ----------------------------------------------------------------
483+ */
484+ void
485+ ExecTidRangeScanReInitializeDSM (TidRangeScanState * node ,
486+ ParallelContext * pcxt )
487+ {
488+ ParallelTableScanDesc pscan ;
489+
490+ pscan = node -> ss .ss_currentScanDesc -> rs_parallel ;
491+ table_parallelscan_reinitialize (node -> ss .ss_currentRelation , pscan );
492+
493+ /* Set the new TID range if it can be evaluated successfully */
494+ if (TidRangeEval (node ))
495+ node -> ss .ss_currentRelation -> rd_tableam -> scan_set_tidrange (
496+ node -> ss .ss_currentScanDesc , & node -> trss_mintid ,
497+ & node -> trss_maxtid );
498+ else
499+ node -> ss .ss_currentRelation -> rd_tableam -> scan_set_tidrange (
500+ node -> ss .ss_currentScanDesc , NULL , NULL );
501+ }
502+
503+ /* ----------------------------------------------------------------
504+ * ExecTidRangeScanInitializeWorker
505+ *
506+ * Copy relevant information from TOC into planstate.
507+ * ----------------------------------------------------------------
508+ */
509+ void
510+ ExecTidRangeScanInitializeWorker (TidRangeScanState * node ,
511+ ParallelWorkerContext * pwcxt )
512+ {
513+ ParallelTableScanDesc pscan ;
514+
515+ pscan = shm_toc_lookup (pwcxt -> toc , node -> ss .ps .plan -> plan_node_id , false);
516+
517+ if (TidRangeEval (node ))
518+ node -> ss .ss_currentScanDesc =
519+ table_beginscan_parallel_tidrange (node -> ss .ss_currentRelation , pscan ,
520+ & node -> trss_mintid , & node -> trss_maxtid );
521+ else
522+ node -> ss .ss_currentScanDesc =
523+ table_beginscan_parallel_tidrange (node -> ss .ss_currentRelation , pscan ,
524+ NULL , NULL );
525+ }
0 commit comments