aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-11-30 14:38:00 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-11-30 14:38:00 -0500
commit942e441ee8f444bcc877ee7cdae00d5ecd312feb (patch)
treee34f8cee8f34dac9c150499dd52ac0a7dee4cb4d
parentcaecab229abdcac05bdeb8ac94e78194dfc71f5c (diff)
downloadpostgresql-942e441ee8f444bcc877ee7cdae00d5ecd312feb.tar.gz
postgresql-942e441ee8f444bcc877ee7cdae00d5ecd312feb.zip
Prevent parallel index build in a standalone backend.
This can't work if there's no postmaster, and indeed the code got an assertion failure trying. There should be a check on IsUnderPostmaster gating the use of parallelism, as the planner has for ordinary parallel queries. Commit 40d964ec9 got this right, so follow its model of checking IsUnderPostmaster at the same place where we check for max_parallel_maintenance_workers == 0. In general, new code implementing parallel utility operations should do the same. Report and patch by Yulin Pei, cosmetically adjusted by me. Back-patch to v11 where this code came in. Discussion: https://postgr.es/m/HK0PR01MB22747D839F77142D7E76A45DF4F50@HK0PR01MB2274.apcprd01.prod.exchangelabs.com
-rw-r--r--src/backend/optimizer/plan/planner.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 8e152078c59..a10bb89dcb6 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -6090,8 +6090,12 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
double reltuples;
double allvisfrac;
- /* Return immediately when parallelism disabled */
- if (dynamic_shared_memory_type == DSM_IMPL_NONE ||
+ /*
+ * We don't allow performing parallel operation in standalone backend or
+ * when parallelism is disabled.
+ */
+ if (!IsUnderPostmaster ||
+ dynamic_shared_memory_type == DSM_IMPL_NONE ||
max_parallel_maintenance_workers == 0)
return 0;