postgresql/src/include/optimizer
Amit Kapila 05c8482f7f Enable parallel SELECT for "INSERT INTO ... SELECT ...".
Parallel SELECT can't be utilized for INSERT in the following cases:
- INSERT statement uses the ON CONFLICT DO UPDATE clause
- Target table has a parallel-unsafe: trigger, index expression or
  predicate, column default expression or check constraint
- Target table has a parallel-unsafe domain constraint on any column
- Target table is a partitioned table with a parallel-unsafe partition key
  expression or support function

The planner is updated to perform additional parallel-safety checks for
the cases listed above, for determining whether it is safe to run INSERT
in parallel-mode with an underlying parallel SELECT. The planner will
consider using parallel SELECT for "INSERT INTO ... SELECT ...", provided
nothing unsafe is found from the additional parallel-safety checks, or
from the existing parallel-safety checks for SELECT.

While checking parallel-safety, we need to check it for all the partitions
on the table which can be costly especially when we decide not to use a
parallel plan. So, in a separate patch, we will introduce a GUC and or a
reloption to enable/disable parallelism for Insert statements.

Prior to entering parallel-mode for the execution of INSERT with parallel
SELECT, a TransactionId is acquired and assigned to the current
transaction state. This is necessary to prevent the INSERT from attempting
to assign the TransactionId whilst in parallel-mode, which is not allowed.
This approach has a disadvantage in that if the underlying SELECT does not
return any rows, then the TransactionId is not used, however that
shouldn't happen in practice in many cases.

Author: Greg Nancarrow, Amit Langote, Amit Kapila
Reviewed-by: Amit Langote, Hou Zhijie, Takayuki Tsunakawa, Antonin Houska, Bharath Rupireddy, Dilip Kumar, Vignesh C, Zhihong Yu, Amit Kapila
Tested-by: Tang, Haiying
Discussion: https://postgr.es/m/CAJcOf-cXnB5cnMKqWEp2E2z7Mvcd04iLVmV=qpFJrR3AcrTS3g@mail.gmail.com
Discussion: https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com
2021-03-10 07:38:58 +05:30
..
appendinfo.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
clauses.h Enable parallel SELECT for "INSERT INTO ... SELECT ...". 2021-03-10 07:38:58 +05:30
cost.h Add TID Range Scans to support efficient scanning ranges of TIDs 2021-02-27 22:59:36 +13:00
geqo.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_copy.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_gene.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_misc.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_mutation.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_pool.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_random.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_recombination.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
geqo_selection.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
inherit.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
joininfo.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
optimizer.h Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar. 2021-01-21 15:37:23 -05:00
orclauses.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
paramassign.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pathnode.h Add TID Range Scans to support efficient scanning ranges of TIDs 2021-02-27 22:59:36 +13:00
paths.h Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar. 2021-01-21 15:37:23 -05:00
placeholder.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
plancat.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
planmain.h Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar. 2021-01-21 15:37:23 -05:00
planner.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
prep.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
restrictinfo.h Fix pull_varnos' miscomputation of relids set for a PlaceHolderVar. 2021-01-21 15:37:23 -05:00
subselect.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
tlist.h Update copyright for 2021 2021-01-02 13:06:25 -05:00