mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Refactor partition tuple routing code to reduce duplication.
Amit Langote
This commit is contained in:
@ -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;
|
||||
PartitionDispatch *partition_dispatch_info;
|
||||
ResultRelInfo *partitions;
|
||||
TupleConversionMap **partition_tupconv_maps;
|
||||
int num_parted,
|
||||
num_partitions;
|
||||
|
||||
/* Get the tuple-routing information and lock partitions */
|
||||
cstate->partition_dispatch_info =
|
||||
RelationGetPartitionDispatchInfo(rel, RowExclusiveLock,
|
||||
&num_parted,
|
||||
&leaf_parts);
|
||||
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
|
||||
|
Reference in New Issue
Block a user