From 76a811086b11eb2d3d0b1131bbc94f5619e95c63 Mon Sep 17 00:00:00 2001 From: Greg Nancarrow Date: Mon, 1 Feb 2021 14:54:26 +1100 Subject: [PATCH v3 1/2] Add new GUC option: enable_parallel_dml (boolean) The current implementation of parallel "INSERT ... SELECT ..." may incur non-negligible overhead in the additional parallel-safety checks that it performs, even when, in the end, those checks determine that parallelism can't be used. This is normally only ever a problem for large complex tables, particularly in the case of when the target table has a large number of partitions. To address this potential isse, a new GUC option "enable_parallel_dml" is added, to allow parallel DML to be enabled/disabled. The default is false. --- src/backend/optimizer/path/costsize.c | 2 ++ src/backend/optimizer/plan/planner.c | 3 ++- src/backend/utils/misc/guc.c | 11 +++++++++++ src/backend/utils/misc/postgresql.conf.sample | 1 + src/include/optimizer/cost.h | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index f7c13bed7a..778f71b98a 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -129,6 +129,8 @@ Cost disable_cost = 1.0e10; int max_parallel_workers_per_gather = 2; +bool enable_parallel_dml = false; + bool enable_seqscan = true; bool enable_indexscan = true; bool enable_indexonlyscan = true; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 6efce22a1a..3fb108d120 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -339,7 +339,8 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions, if ((cursorOptions & CURSOR_OPT_PARALLEL_OK) != 0 && IsUnderPostmaster && (parse->commandType == CMD_SELECT || - IsModifySupportedInParallelMode(parse->commandType)) && + (enable_parallel_dml && + IsModifySupportedInParallelMode(parse->commandType))) && !parse->hasModifyingCTE && max_parallel_workers_per_gather > 0 && !IsParallelWorker()) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index eafdb1118e..6fdb991a26 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2048,6 +2048,17 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, + { + {"enable_parallel_dml", PGC_USERSET, QUERY_TUNING_METHOD, + gettext_noop("Enables the planner's use of parallel plans for table-modification commands."), + NULL, + GUC_EXPLAIN + }, + &enable_parallel_dml, + false, + NULL, NULL, NULL + }, + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index bd57e917e1..1f699b0f2d 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -370,6 +370,7 @@ #enable_partitionwise_aggregate = off #enable_parallel_hash = on #enable_partition_pruning = on +#enable_parallel_dml = off # - Planner Cost Constants - diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h index 9f15fcb240..4af0beb9c8 100644 --- a/src/include/optimizer/cost.h +++ b/src/include/optimizer/cost.h @@ -47,6 +47,7 @@ typedef enum /* parameter variables and flags (see also optimizer.h) */ extern PGDLLIMPORT Cost disable_cost; extern PGDLLIMPORT int max_parallel_workers_per_gather; +extern PGDLLIMPORT bool enable_parallel_dml; extern PGDLLIMPORT bool enable_seqscan; extern PGDLLIMPORT bool enable_indexscan; extern PGDLLIMPORT bool enable_indexonlyscan; -- 2.27.0