aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2014-01-20 17:22:38 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2014-01-20 17:22:38 +0000
commit4d1e2aeb1a162770683a8d1e13fc13ac2d95d810 (patch)
treeab15a5f2a9213e2235f0bb8d3237448dbe43cec4 /src/backend/commands/copy.c
parent74a72ec208671f3ff301b4f6ef703f4957deccea (diff)
downloadpostgresql-4d1e2aeb1a162770683a8d1e13fc13ac2d95d810.tar.gz
postgresql-4d1e2aeb1a162770683a8d1e13fc13ac2d95d810.zip
Speed up COPY into tables with DEFAULT nextval()
Previously the presence of a nextval() prevented the use of batch-mode COPY. This patch introduces a special case just for nextval() functions. In future we will introduce a general case solution for labelling volatile functions as safe for use.
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index f91f1646dac..7c4039cb7ff 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2519,9 +2519,20 @@ BeginCopyFrom(Relation rel,
defmap[num_defaults] = attnum - 1;
num_defaults++;
- /* Check to see if we have any volatile expressions */
+ /*
+ * If a default expression looks at the table being loaded, then
+ * it could give the wrong answer when using multi-insert. Since
+ * database access can be dynamic this is hard to test for
+ * exactly, so we use the much wider test of whether the
+ * default expression is volatile. We allow for the special case
+ * of when the default expression is the nextval() of a sequence
+ * which in this specific case is known to be safe for use with
+ * the multi-insert optimisation. Hence we use this special case
+ * function checker rather than the standard check for
+ * contain_volatile_functions().
+ */
if (!volatile_defexprs)
- volatile_defexprs = contain_volatile_functions((Node *) defexpr);
+ volatile_defexprs = contain_volatile_functions_not_nextval((Node *)defexpr);
}
}
}