From 15729ba70e900450f60286721c00b5a209c8f7f1 Mon Sep 17 00:00:00 2001
From: houzj <houzj.fnst@cn.fujitsu.com>
Date: Mon, 1 Feb 2021 11:24:43 +0800
Subject: [PATCH 2/2] reloption parallel_dml_enabled test and doc

Test and document for reloption parallel_dml_enabled

---
 doc/src/sgml/ref/alter_table.sgml             |  2 +-
 doc/src/sgml/ref/create_table.sgml            | 22 ++++++++++++++++++++++
 src/test/regress/expected/insert_parallel.out | 24 +++++++++++++++++++++---
 src/test/regress/sql/insert_parallel.sql      | 19 ++++++++++++++++---
 4 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index c25ef5a..ecb0470 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -722,7 +722,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
      <para>
       <literal>SHARE UPDATE EXCLUSIVE</literal> lock will be taken for
       fillfactor, toast and autovacuum storage parameters, as well as the
-      planner parameter <varname>parallel_workers</varname>.
+      planner parameter <varname>parallel_workers</varname> and <varname>parallel_dml_enabled</varname>.
      </para>
     </listitem>
    </varlistentry>
diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml
index 569f4c9..4380184 100644
--- a/doc/src/sgml/ref/create_table.sgml
+++ b/doc/src/sgml/ref/create_table.sgml
@@ -1408,6 +1408,28 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
     </listitem>
    </varlistentry>
 
+   <varlistentry id="reloption-parallel-dml-enabled" xreflabel="parallel_dml_enabled">
+    <term><literal>parallel_dml_enabled</literal> (<type>boolean</type>)
+     <indexterm>
+     <primary><varname>parallel_dml_enabled</varname> storage parameter</primary>
+    </indexterm>
+    </term>
+    <listitem>
+     <para>
+      Enables or disables the parallel table-modification on a particular table.
+      if set it to true, planner will check parallel safety of the target table
+      to determine if it’s safe to execute parallel. (Note: If target is
+      partitioned table, it will check all its partitions and indexes, then
+      the check overhead can become prohibitively high if the number of
+      partitions is large, Especially when the parallelism is not chosen in
+      the end.) To avoid the overhead, the default is <literal>false</literal>.
+      Parallel_dml_enabled will not work if <xref linkend="guc-enable-parallel-dml"/>
+      is not set. If target table is parent table(partitioned), only the option
+      of the parent table works, the option values of its child will be ignored.
+     </para>
+    </listitem>
+   </varlistentry>
+
    <varlistentry id="reloption-autovacuum-enabled" xreflabel="autovacuum_enabled">
     <term><literal>autovacuum_enabled</literal>, <literal>toast.autovacuum_enabled</literal> (<type>boolean</type>)
     <indexterm>
diff --git a/src/test/regress/expected/insert_parallel.out b/src/test/regress/expected/insert_parallel.out
index f98d1ae..641a5cc 100644
--- a/src/test/regress/expected/insert_parallel.out
+++ b/src/test/regress/expected/insert_parallel.out
@@ -70,13 +70,13 @@ set max_parallel_workers_per_gather=4;
 create table para_insert_p1 (
 	unique1		int4	PRIMARY KEY,
 	stringu1	name
-);
+) with (parallel_dml_enabled = off);
 create table para_insert_f1 (
 	unique1		int4	REFERENCES para_insert_p1(unique1),
 	stringu1	name
 );
 --
--- Test INSERT with underlying query when enable_parallel_dml=off.
+-- Test INSERT with underlying query when enable_parallel_dml=off and reloption.parallel_dml_enabled=off.
 -- (should create plan with serial INSERT + SELECT)
 --
 explain(costs off) insert into para_insert_p1 select unique1, stringu1 from tenk1;
@@ -88,10 +88,28 @@ explain(costs off) insert into para_insert_p1 select unique1, stringu1 from tenk
 
 insert into para_insert_p1 select unique1, stringu1 from tenk1;
 --
--- Enable parallel dml
+-- Enable guc option enable_parallel_dml
 --
 set enable_parallel_dml = on;
 --
+-- Test INSERT with underlying query when enable_parallel_dml=on and reloption.parallel_dml_enabled=off.
+-- (should create plan with serial INSERT + SELECT)
+--
+truncate para_insert_p1 cascade;
+NOTICE:  truncate cascades to table "para_insert_f1"
+explain(costs off) insert into para_insert_p1 select unique1, stringu1 from tenk1;
+        QUERY PLAN        
+--------------------------
+ Insert on para_insert_p1
+   ->  Seq Scan on tenk1
+(2 rows)
+
+insert into para_insert_p1 select unique1, stringu1 from tenk1;
+--
+-- Enable reloption parallel_dml_enabled
+--
+alter table para_insert_p1 set (parallel_dml_enabled = on);
+--
 -- Test INSERT with underlying query.
 -- (should create plan with parallel INSERT+SELECT, Gather parent node)
 --
diff --git a/src/test/regress/sql/insert_parallel.sql b/src/test/regress/sql/insert_parallel.sql
index 5317313..4c6b352 100644
--- a/src/test/regress/sql/insert_parallel.sql
+++ b/src/test/regress/sql/insert_parallel.sql
@@ -87,7 +87,7 @@ set max_parallel_workers_per_gather=4;
 create table para_insert_p1 (
 	unique1		int4	PRIMARY KEY,
 	stringu1	name
-);
+) with (parallel_dml_enabled = off);
 
 create table para_insert_f1 (
 	unique1		int4	REFERENCES para_insert_p1(unique1),
@@ -95,18 +95,31 @@ create table para_insert_f1 (
 );
 
 --
--- Test INSERT with underlying query when enable_parallel_dml=off.
+-- Test INSERT with underlying query when enable_parallel_dml=off and reloption.parallel_dml_enabled=off.
 -- (should create plan with serial INSERT + SELECT)
 --
 explain(costs off) insert into para_insert_p1 select unique1, stringu1 from tenk1;
 insert into para_insert_p1 select unique1, stringu1 from tenk1;
 
 --
--- Enable parallel dml
+-- Enable guc option enable_parallel_dml
 --
 set enable_parallel_dml = on;
 
 --
+-- Test INSERT with underlying query when enable_parallel_dml=on and reloption.parallel_dml_enabled=off.
+-- (should create plan with serial INSERT + SELECT)
+--
+truncate para_insert_p1 cascade;
+explain(costs off) insert into para_insert_p1 select unique1, stringu1 from tenk1;
+insert into para_insert_p1 select unique1, stringu1 from tenk1;
+
+--
+-- Enable reloption parallel_dml_enabled
+--
+alter table para_insert_p1 set (parallel_dml_enabled = on);
+
+--
 -- Test INSERT with underlying query.
 -- (should create plan with parallel INSERT+SELECT, Gather parent node)
 --
-- 
2.7.2.windows.1

