mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +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:
@@ -129,6 +129,8 @@ Cost disable_cost = 1.0e10;
|
||||
|
||||
int max_parallel_workers_per_gather = 2;
|
||||
|
||||
bool enable_parallel_insert = true;
|
||||
|
||||
bool enable_seqscan = true;
|
||||
bool enable_indexscan = true;
|
||||
bool enable_indexonlyscan = true;
|
||||
|
@@ -1265,8 +1265,10 @@ target_rel_chk_constr_max_parallel_hazard(Relation rel,
|
||||
*
|
||||
* It's not possible in the following cases:
|
||||
*
|
||||
* 1) INSERT...ON CONFLICT...DO UPDATE
|
||||
* 2) INSERT without SELECT
|
||||
* 1) enable_parallel_insert is off
|
||||
* 2) INSERT...ON CONFLICT...DO UPDATE
|
||||
* 3) INSERT without SELECT
|
||||
* 4) the reloption parallel_insert_enabled is set to off
|
||||
*
|
||||
* (Note: we don't do in-depth parallel-safety checks here, we do only the
|
||||
* cheaper tests that can quickly exclude obvious cases for which
|
||||
@@ -1277,12 +1279,17 @@ bool
|
||||
is_parallel_allowed_for_modify(Query *parse)
|
||||
{
|
||||
bool hasSubQuery;
|
||||
bool parallel_enabled;
|
||||
RangeTblEntry *rte;
|
||||
ListCell *lc;
|
||||
Relation rel;
|
||||
|
||||
if (!IsModifySupportedInParallelMode(parse->commandType))
|
||||
return false;
|
||||
|
||||
if (!enable_parallel_insert)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* UPDATE is not currently supported in parallel-mode, so prohibit
|
||||
* INSERT...ON CONFLICT...DO UPDATE...
|
||||
@@ -1313,7 +1320,28 @@ is_parallel_allowed_for_modify(Query *parse)
|
||||
}
|
||||
}
|
||||
|
||||
return hasSubQuery;
|
||||
if (!hasSubQuery)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Check if parallel_insert_enabled is enabled for the target table, if
|
||||
* not, skip the safety checks.
|
||||
*
|
||||
* (Note: if the target table is partitioned, the parallel_insert_enabled
|
||||
* option setting of the partitions are ignored).
|
||||
*/
|
||||
rte = rt_fetch(parse->resultRelation, parse->rtable);
|
||||
|
||||
/*
|
||||
* The target table is already locked by the caller (this is done in the
|
||||
* parse/analyze phase), and remains locked until end-of-transaction.
|
||||
*/
|
||||
rel = table_open(rte->relid, NoLock);
|
||||
|
||||
parallel_enabled = RelationGetParallelInsert(rel, true);
|
||||
table_close(rel, NoLock);
|
||||
|
||||
return parallel_enabled;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
Reference in New Issue
Block a user