1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add a new GUC and a reloption to enable inserts in parallel-mode.

Commit 05c8482f7f added the implementation of parallel SELECT for
"INSERT INTO ... SELECT ..." which 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 in the case of when the target table has a
large number of partitions.

A new GUC option "enable_parallel_insert" is added, to allow insert in
parallel-mode. The default is on.

In addition to the GUC option, the user may want a mechanism to allow
inserts in parallel-mode with finer granularity at table level. The new
table option "parallel_insert_enabled" allows this. The default is true.

Author: "Hou, Zhijie"
Reviewed-by: Greg Nancarrow, Amit Langote, Takayuki Tsunakawa, Amit Kapila
Discussion: https://postgr.es/m/CAA4eK1K-cW7svLC2D7DHoGHxdAdg3P37BLgebqBOC2ZLc9a6QQ%40mail.gmail.com
Discussion: https://postgr.es/m/CAJcOf-cXnB5cnMKqWEp2E2z7Mvcd04iLVmV=qpFJrR3AcrTS3g@mail.gmail.com
This commit is contained in:
Amit Kapila
2021-03-18 07:25:27 +05:30
parent 5f79580ad6
commit c8f78b6161
15 changed files with 240 additions and 15 deletions

View File

@ -5072,6 +5072,29 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
</listitem>
</varlistentry>
<varlistentry id="guc-enable-parallel-insert" xreflabel="enable_parallel_insert">
<term><varname>enable_parallel_insert</varname> (<type>boolean</type>)
<indexterm>
<primary><varname>enable_parallel_insert</varname> configuration parameter</primary>
</indexterm>
</term>
<listitem>
<para>
Enables or disables the query planner's use of parallel plans for
<command>INSERT</command> commands. The default is <literal>on</literal>.
When enabled, the planner performs additional parallel-safety checks
on the target table's attributes and indexes, in order to determine
if it's safe to use a parallel plan for <command>INSERT</command>. In
cases such as when the target table has a large number of partitions,
and particularly also when that table uses something parallel-unsafe
that prevents parallelism, the overhead of these checks may become
prohibitively high. To address this potential overhead in these cases,
this option can be used to disable the use of parallel plans for
<command>INSERT</command>.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="runtime-config-query-constants">

View File

@ -722,7 +722,8 @@ 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_insert_enabled</varname>.
</para>
</listitem>
</varlistentry>

View File

@ -1409,6 +1409,32 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
</listitem>
</varlistentry>
<varlistentry id="reloption-parallel-insert-enabled" xreflabel="parallel_insert_enabled">
<term><literal>parallel_insert_enabled</literal> (<type>boolean</type>)
<indexterm>
<primary><varname>parallel_insert_enabled</varname> storage parameter</primary>
</indexterm>
</term>
<listitem>
<para>
Enables or disables the query planner's use of parallel insert for
this table. When enabled (and provided that
<xref linkend="guc-enable-parallel-insert"/> is also <literal>true</literal>),
the planner performs additional parallel-safety checks on the table's
attributes and indexes, in order to determine if it's safe to use a
parallel plan for <command>INSERT</command>. The default is
<literal>true</literal>. In cases such as when the table has a large
number of partitions, and particularly also when that table uses a
parallel-unsafe feature that prevents parallelism, the overhead of these
checks may become prohibitively high. To address this potential overhead
in these cases, this option can be used to disable the use of parallel
insert for this table. Note that if the target table of the parallel
insert is partitioned, the <literal>parallel_insert_enabled</literal>
option values of the partitions are 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>