commit b9308a8474cee6c71e16acae59d969f7266bad25 Author: Mahendra Singh Thalor Date: Tue Nov 5 16:27:31 2019 +0530 Use parallel vacuum if force_parallel_mode is setted as regress When force_parallel_mode is setted as regress and there is no parallel option given with vacuum(or parallel option is given without degree), then if there is 1 index, then launch 1 parallel worker and if more than one index, then use leader as one worker and launch workers for remaining indexes. diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index a9d9f31..ac798a5 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -67,6 +67,7 @@ #include "commands/progress.h" #include "commands/vacuum.h" #include "miscadmin.h" +#include "optimizer/optimizer.h" #include "pgstat.h" #include "portability/instr_time.h" #include "postmaster/autovacuum.h" @@ -2943,6 +2944,15 @@ compute_parallel_workers(Relation *Irel, int nindexes, int nrequested) leaderparticipates = false; #endif + /* + * If there is only one index and force_parallel_mode is setted as regress, + * but number of parallel workers are not given with vacuum command, then + * we will always lanuch one workers for vacuum. + */ + if (force_parallel_mode == FORCE_PARALLEL_REGRESS && nrequested == 0 && + nindexes_to_vacuum == 1) + leaderparticipates = false; + /* The leader process takes one index */ if (leaderparticipates) nindexes_to_vacuum--; diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 905d173..ca53f25 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -40,6 +40,7 @@ #include "commands/vacuum.h" #include "miscadmin.h" #include "nodes/makefuncs.h" +#include "optimizer/optimizer.h" #include "pgstat.h" #include "postmaster/autovacuum.h" #include "postmaster/bgworker_internals.h" @@ -170,6 +171,14 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel) (full ? VACOPT_FULL : 0) | (disable_page_skipping ? VACOPT_DISABLE_PAGE_SKIPPING : 0); + /* + * If force_parallel_mode is setted as regress and there is no parallel + * option is speified with vacuum, then enable parallel vacuum. + */ + if (params.nworkers == -1 && !(params.options & VACOPT_FULL) && + force_parallel_mode == FORCE_PARALLEL_REGRESS) + params.nworkers = 0; + /* sanity checks on options */ Assert(params.options & (VACOPT_VACUUM | VACOPT_ANALYZE)); Assert((params.options & VACOPT_VACUUM) ||