diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2018-11-19 11:16:28 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2018-11-19 11:16:28 -0300 |
commit | a4db7fe0f71463eb7256d3c42b7a582d3943d604 (patch) | |
tree | 3986e674275a63bc3c568eea9fdc2e6d0fdfbd25 /src/backend | |
parent | 6534d544cd77e14a93f5c779fa8addee8d916a66 (diff) | |
download | postgresql-a4db7fe0f71463eb7256d3c42b7a582d3943d604.tar.gz postgresql-a4db7fe0f71463eb7256d3c42b7a582d3943d604.zip |
Disallow COPY FREEZE on partitioned tables
This didn't actually work: COPY would fail to flush the right files, and
instead would try to flush a non-existing file, causing the whole
transaction to fail.
Cope by raising an error as soon as the command is sent instead, to
avoid a nasty later surprise. Of course, it would be much better to
make it work, but we don't have a patch for that yet, and we don't know
if we'll want to backpatch one when we do.
Reported-by: Tomas Vondra
Author: David Rowley
Reviewed-by: Amit Langote, Steve Singer, Tomas Vondra
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/copy.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 3a66cb5025f..7fa29531cce 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2397,11 +2397,20 @@ CopyFrom(CopyState cstate) * go into pages containing tuples from any other transactions --- but this * must be the case if we have a new table or new relfilenode, so we need * no additional work to enforce that. + * + * We currently don't support this optimization if the COPY target is a + * partitioned table as we currently only lazily initialize partition + * information when routing the first tuple to the partition. We cannot + * know at this stage if we can perform this optimization. It should be + * possible to improve on this, but it does mean maintaining heap insert + * option flags per partition and setting them when we first open the + * partition. *---------- */ /* createSubid is creation check, newRelfilenodeSubid is truncation check */ - if (cstate->rel->rd_createSubid != InvalidSubTransactionId || - cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId) + if (cstate->rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE && + (cstate->rel->rd_createSubid != InvalidSubTransactionId || + cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId)) { hi_options |= HEAP_INSERT_SKIP_FSM; if (!XLogIsNeeded()) @@ -2422,6 +2431,22 @@ CopyFrom(CopyState cstate) if (cstate->freeze) { /* + * We currently disallow COPY FREEZE on partitioned tables. The + * reason for this is that we've simply not yet opened the partitions + * to determine if the optimization can be applied to them. We could + * go and open them all here, but doing so may be quite a costly + * overhead for small copies. In any case, we may just end up routing + * tuples to a small number of partitions. It seems better just to + * raise an ERROR for partitioned tables. + */ + if (cstate->rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot perform FREEZE on a partitioned table"))); + } + + /* * Tolerate one registration for the benefit of FirstXactSnapshot. * Scan-bearing queries generally create at least two registrations, * though relying on that is fragile, as is ignoring ActiveSnapshot. |