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