diff options
author | Peter Eisentraut | 2018-10-17 18:31:20 +0000 |
---|---|---|
committer | Peter Eisentraut | 2018-10-17 18:31:20 +0000 |
commit | a7a1b44516e7db89104c06440f759c2831fcb0ff (patch) | |
tree | a7fa2029dbaf83e70236b885d76d915aa6b2d409 /src/backend/commands/copy.c | |
parent | d8cc1616b5547d49d899be7b68713272ce334708 (diff) |
Fix crash in multi-insert COPY
A bug introduced in 0d5f05cde011512e605bb2688d9b1fbb5b3ae152
considered the *previous* partition's triggers when deciding whether
multi-insert can be used. Rearrange the code so that the current
partition is considered.
Author: Ashutosh Sharma <[email protected]>
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 86b0fb300ff..b58a74f4e3d 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2783,21 +2783,7 @@ CopyFrom(CopyState cstate) lastPartitionSampleLineNo = cstate->cur_lineno; nPartitionChanges = 0; } - - /* - * Tests have shown that using multi-inserts when the - * partition changes on every tuple slightly decreases the - * performance, however, there are benefits even when only - * some batches have just 2 tuples, so let's enable - * multi-inserts even when the average is quite low. - */ - leafpart_use_multi_insert = avgTuplesPerPartChange >= 1.3 && - !has_before_insert_row_trig && - !has_instead_insert_row_trig && - resultRelInfo->ri_FdwRoutine == NULL; } - else - leafpart_use_multi_insert = false; /* * Overwrite resultRelInfo with the corresponding partition's @@ -2822,6 +2808,19 @@ CopyFrom(CopyState cstate) resultRelInfo->ri_TrigDesc->trig_insert_instead_row); /* + * Tests have shown that using multi-inserts when the + * partition changes on every tuple slightly decreases the + * performance, however, there are benefits even when only + * some batches have just 2 tuples, so let's enable + * multi-inserts even when the average is quite low. + */ + leafpart_use_multi_insert = insertMethod == CIM_MULTI_CONDITIONAL && + avgTuplesPerPartChange >= 1.3 && + !has_before_insert_row_trig && + !has_instead_insert_row_trig && + resultRelInfo->ri_FdwRoutine == NULL; + + /* * We'd better make the bulk insert mechanism gets a new * buffer when the partition being inserted into changes. */ |