@@ -35,6 +35,9 @@ extern PGDLLIMPORT bool synchronize_seqscans;
35
35
36
36
struct BulkInsertStateData ;
37
37
struct IndexInfo ;
38
+ struct ParallelContext ;
39
+ struct ParallelVacuumState ;
40
+ struct ParallelWorkerContext ;
38
41
struct SampleScanState ;
39
42
struct VacuumParams ;
40
43
struct ValidateIndexState ;
@@ -648,6 +651,81 @@ typedef struct TableAmRoutine
648
651
struct VacuumParams * params ,
649
652
BufferAccessStrategy bstrategy );
650
653
654
+ /* ------------------------------------------------------------------------
655
+ * Callbacks for parallel table vacuum.
656
+ * ------------------------------------------------------------------------
657
+ */
658
+
659
+ /*
660
+ * Compute the number of parallel workers for parallel table vacuum. The
661
+ * parallel degree for parallel vacuum is further limited by
662
+ * max_parallel_maintenance_workers. The function must return 0 to disable
663
+ * parallel table vacuum.
664
+ *
665
+ * 'nworkers_requested' is a >=0 number and the requested number of
666
+ * workers. This comes from the PARALLEL option. 0 means to choose the
667
+ * parallel degree based on the table AM specific factors such as table
668
+ * size.
669
+ */
670
+ int (* parallel_vacuum_compute_workers ) (Relation rel ,
671
+ int nworkers_requested ,
672
+ void * state );
673
+
674
+ /*
675
+ * Estimate the size of shared memory needed for a parallel table vacuum
676
+ * of this relation.
677
+ *
678
+ * Not called if parallel table vacuum is disabled.
679
+ *
680
+ * Optional callback, but either all other parallel vacuum callbacks need
681
+ * to exist, or neither.
682
+ */
683
+ void (* parallel_vacuum_estimate ) (Relation rel ,
684
+ struct ParallelContext * pcxt ,
685
+ int nworkers ,
686
+ void * state );
687
+
688
+ /*
689
+ * Initialize DSM space for parallel table vacuum.
690
+ *
691
+ * Not called if parallel table vacuum is disabled.
692
+ *
693
+ * Optional callback, but either all other parallel vacuum callbacks need
694
+ * to exist, or neither.
695
+ */
696
+ void (* parallel_vacuum_initialize ) (Relation rel ,
697
+ struct ParallelContext * pctx ,
698
+ int nworkers ,
699
+ void * state );
700
+
701
+ /*
702
+ * Initialize AM-specific vacuum state for worker processes.
703
+ *
704
+ * The state_out is the output parameter so that arbitrary data can be
705
+ * passed to the subsequent callback, parallel_vacuum_remove_dead_items.
706
+ *
707
+ * Not called if parallel table vacuum is disabled.
708
+ *
709
+ * Optional callback, but either all other parallel vacuum callbacks need
710
+ * to exist, or neither.
711
+ */
712
+ void (* parallel_vacuum_initialize_worker ) (Relation rel ,
713
+ struct ParallelVacuumState * pvs ,
714
+ struct ParallelWorkerContext * pwcxt ,
715
+ void * * state_out );
716
+
717
+ /*
718
+ * Execute a parallel scan to collect dead items.
719
+ *
720
+ * Not called if parallel table vacuum is disabled.
721
+ *
722
+ * Optional callback, but either all other parallel vacuum callbacks need
723
+ * to exist, or neither.
724
+ */
725
+ void (* parallel_vacuum_collect_dead_items ) (Relation rel ,
726
+ struct ParallelVacuumState * pvs ,
727
+ void * state );
728
+
651
729
/*
652
730
* Prepare to analyze block `blockno` of `scan`. The scan has been started
653
731
* with table_beginscan_analyze(). See also
@@ -1670,6 +1748,68 @@ table_relation_vacuum(Relation rel, struct VacuumParams *params,
1670
1748
rel -> rd_tableam -> relation_vacuum (rel , params , bstrategy );
1671
1749
}
1672
1750
1751
+ /* ----------------------------------------------------------------------------
1752
+ * Parallel vacuum related functions.
1753
+ * ----------------------------------------------------------------------------
1754
+ */
1755
+
1756
+ /*
1757
+ * Compute the number of parallel workers for a parallel vacuum scan of this
1758
+ * relation.
1759
+ */
1760
+ static inline int
1761
+ table_parallel_vacuum_compute_workers (Relation rel , int nworkers_requested ,
1762
+ void * state )
1763
+ {
1764
+ return rel -> rd_tableam -> parallel_vacuum_compute_workers (rel ,
1765
+ nworkers_requested ,
1766
+ state );
1767
+ }
1768
+
1769
+ /*
1770
+ * Estimate the size of shared memory needed for a parallel vacuum scan of this
1771
+ * of this relation.
1772
+ */
1773
+ static inline void
1774
+ table_parallel_vacuum_estimate (Relation rel , struct ParallelContext * pcxt ,
1775
+ int nworkers , void * state )
1776
+ {
1777
+ Assert (nworkers > 0 );
1778
+ rel -> rd_tableam -> parallel_vacuum_estimate (rel , pcxt , nworkers , state );
1779
+ }
1780
+
1781
+ /*
1782
+ * Initialize shared memory area for a parallel vacuum scan of this relation.
1783
+ */
1784
+ static inline void
1785
+ table_parallel_vacuum_initialize (Relation rel , struct ParallelContext * pcxt ,
1786
+ int nworkers , void * state )
1787
+ {
1788
+ Assert (nworkers > 0 );
1789
+ rel -> rd_tableam -> parallel_vacuum_initialize (rel , pcxt , nworkers , state );
1790
+ }
1791
+
1792
+ /*
1793
+ * Initialize AM-specific vacuum state for worker processes.
1794
+ */
1795
+ static inline void
1796
+ table_parallel_vacuum_initialize_worker (Relation rel , struct ParallelVacuumState * pvs ,
1797
+ struct ParallelWorkerContext * pwcxt ,
1798
+ void * * state_out )
1799
+ {
1800
+ rel -> rd_tableam -> parallel_vacuum_initialize_worker (rel , pvs , pwcxt , state_out );
1801
+ }
1802
+
1803
+ /*
1804
+ * Execute a parallel vacuum scan to collect dead items.
1805
+ */
1806
+ static inline void
1807
+ table_parallel_vacuum_collect_dead_items (Relation rel , struct ParallelVacuumState * pvs ,
1808
+ void * state )
1809
+ {
1810
+ rel -> rd_tableam -> parallel_vacuum_collect_dead_items (rel , pvs , state );
1811
+ }
1812
+
1673
1813
/*
1674
1814
* Prepare to analyze the next block in the read stream. The scan needs to
1675
1815
* have been started with table_beginscan_analyze(). Note that this routine
0 commit comments