diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-12-21 11:36:10 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-12-21 11:36:10 -0500 |
commit | 1fc5c4945047e8e8c7aa1644b52dd0187b729181 (patch) | |
tree | 0340c42210feb31c93a37c284521a90202dc00ee /src/backend/commands/copy.c | |
parent | 3b790d256f8489d0765c3389d6860f1c6b4a9b2d (diff) | |
download | postgresql-1fc5c4945047e8e8c7aa1644b52dd0187b729181.tar.gz postgresql-1fc5c4945047e8e8c7aa1644b52dd0187b729181.zip |
Refactor partition tuple routing code to reduce duplication.
Amit Langote
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 72 |
1 files changed, 15 insertions, 57 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 7a8da338f07..d5901651db1 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1406,64 +1406,22 @@ BeginCopy(ParseState *pstate, /* Initialize state for CopyFrom tuple routing. */ if (is_from && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) { - List *leaf_parts; - ListCell *cell; - int i, - num_parted; - ResultRelInfo *leaf_part_rri; - - /* Get the tuple-routing information and lock partitions */ - cstate->partition_dispatch_info = - RelationGetPartitionDispatchInfo(rel, RowExclusiveLock, - &num_parted, - &leaf_parts); + PartitionDispatch *partition_dispatch_info; + ResultRelInfo *partitions; + TupleConversionMap **partition_tupconv_maps; + int num_parted, + num_partitions; + + ExecSetupPartitionTupleRouting(rel, + &partition_dispatch_info, + &partitions, + &partition_tupconv_maps, + &num_parted, &num_partitions); + cstate->partition_dispatch_info = partition_dispatch_info; cstate->num_dispatch = num_parted; - cstate->num_partitions = list_length(leaf_parts); - cstate->partitions = (ResultRelInfo *) - palloc(cstate->num_partitions * - sizeof(ResultRelInfo)); - cstate->partition_tupconv_maps = (TupleConversionMap **) - palloc0(cstate->num_partitions * - sizeof(TupleConversionMap *)); - - leaf_part_rri = cstate->partitions; - i = 0; - foreach(cell, leaf_parts) - { - Relation partrel; - - /* - * We locked all the partitions above including the leaf - * partitions. Note that each of the relations in - * cstate->partitions will be closed by CopyFrom() after it's - * finished with its processing. - */ - partrel = heap_open(lfirst_oid(cell), NoLock); - - /* - * Verify result relation is a valid target for the current - * operation. - */ - CheckValidResultRel(partrel, CMD_INSERT); - - InitResultRelInfo(leaf_part_rri, - partrel, - 1, /* dummy */ - false, /* no partition constraint - * check */ - 0); - - /* Open partition indices */ - ExecOpenIndices(leaf_part_rri, false); - - if (!equalTupleDescs(tupDesc, RelationGetDescr(partrel))) - cstate->partition_tupconv_maps[i] = - convert_tuples_by_name(tupDesc, - RelationGetDescr(partrel), - gettext_noop("could not convert row type")); - leaf_part_rri++; - i++; - } + cstate->partitions = partitions; + cstate->num_partitions = num_partitions; + cstate->partition_tupconv_maps = partition_tupconv_maps; } } else |