From c8f78b616167bf8e24bc5dc69112c37755ed3058 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Thu, 18 Mar 2021 07:25:27 +0530 Subject: 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 --- src/include/utils/rel.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/include/utils') diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 10b63982c0a..5375a37dd19 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -306,6 +306,8 @@ typedef struct StdRdOptions int parallel_workers; /* max number of parallel workers */ bool vacuum_index_cleanup; /* enables index vacuuming and cleanup */ bool vacuum_truncate; /* enables vacuum to truncate a relation */ + bool parallel_insert_enabled; /* enables planner's use of + * parallel insert */ } StdRdOptions; #define HEAP_MIN_FILLFACTOR 10 @@ -423,6 +425,29 @@ typedef struct ViewOptions ((ViewOptions *) (relation)->rd_options)->check_option == \ VIEW_OPTION_CHECK_OPTION_CASCADED) +/* + * PartitionedTableRdOptions + * Contents of rd_options for partitioned tables + */ +typedef struct PartitionedTableRdOptions +{ + int32 vl_len_; /* varlena header (do not touch directly!) */ + bool parallel_insert_enabled; /* enables planner's use of + * parallel insert */ +} PartitionedTableRdOptions; + +/* + * RelationGetParallelInsert + * Returns the relation's parallel_insert_enabled reloption setting. + * Note multiple eval of argument! + */ +#define RelationGetParallelInsert(relation, defaultpd) \ + ((relation)->rd_options ? \ + (relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE ? \ + ((PartitionedTableRdOptions *) (relation)->rd_options)->parallel_insert_enabled : \ + ((StdRdOptions *) (relation)->rd_options)->parallel_insert_enabled) : \ + (defaultpd)) + /* * RelationIsValid * True iff relation descriptor is valid. -- cgit v1.2.3