diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-12-02 10:35:55 +0100 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-12-02 10:35:55 +0100 |
commit | fb958b5da86da69651f6fb9f540c2cfb1346cdc5 (patch) | |
tree | a059d6e4ceab797bc94f2212a5d748f5e1b3fa6d /src/backend/executor/execPartition.c | |
parent | 40b1491357a4a092ea054176944cf76e2fe3eff8 (diff) | |
download | postgresql-fb958b5da86da69651f6fb9f540c2cfb1346cdc5.tar.gz postgresql-fb958b5da86da69651f6fb9f540c2cfb1346cdc5.zip |
Generalize ri_RootToPartitionMap to use for non-partition children
ri_RootToPartitionMap is currently only initialized for tuple routing
target partitions, though a future commit will need the ability to use
it even for the non-partition child tables, so make adjustments to the
decouple it from the partitioning code.
Also, make it lazily initialized via ExecGetRootToChildMap(), making
that function its preferred access path. Existing third-party code
accessing it directly should no longer do so; consequently, it's been
renamed to ri_RootToChildMap, which also makes it consistent with
ri_ChildToRootMap.
ExecGetRootToChildMap() houses the logic of setting the map appropriately
depending on whether a given child relation is partition or not.
To support this, also add a separate entry point for TupleConversionMap
creation that receives an AttrMap. No new code here, just split an
existing function in two.
Author: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CA+HiwqEYUhDXSK5BTvG_xk=eaAEJCD4GS3C6uH7ybBvv+Z_Tmg@mail.gmail.com
Diffstat (limited to 'src/backend/executor/execPartition.c')
-rw-r--r-- | src/backend/executor/execPartition.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 8e6453aec2a..88d0ea3adb1 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -463,7 +463,7 @@ ExecFindPartition(ModifyTableState *mtstate, */ if (is_leaf) { - TupleConversionMap *map = rri->ri_RootToPartitionMap; + TupleConversionMap *map = ExecGetRootToChildMap(rri, estate); if (map) slot = execute_attr_map_slot(map->attrMap, rootslot, @@ -727,7 +727,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate, OnConflictSetState *onconfl = makeNode(OnConflictSetState); TupleConversionMap *map; - map = leaf_part_rri->ri_RootToPartitionMap; + map = ExecGetRootToChildMap(leaf_part_rri, estate); Assert(node->onConflictSet != NIL); Assert(rootResultRelInfo->ri_onConflict != NULL); @@ -977,33 +977,24 @@ ExecInitRoutingInfo(ModifyTableState *mtstate, int partidx, bool is_borrowed_rel) { - ResultRelInfo *rootRelInfo = partRelInfo->ri_RootResultRelInfo; MemoryContext oldcxt; int rri_index; oldcxt = MemoryContextSwitchTo(proute->memcxt); /* - * Set up a tuple conversion map to convert a tuple routed to the - * partition from the parent's type to the partition's. + * Set up tuple conversion between root parent and the partition if the + * two have different rowtypes. If conversion is indeed required, also + * initialize a slot dedicated to storing this partition's converted + * tuples. Various operations that are applied to tuples after routing, + * such as checking constraints, will refer to this slot. */ - partRelInfo->ri_RootToPartitionMap = - convert_tuples_by_name(RelationGetDescr(rootRelInfo->ri_RelationDesc), - RelationGetDescr(partRelInfo->ri_RelationDesc)); - - /* - * If a partition has a different rowtype than the root parent, initialize - * a slot dedicated to storing this partition's tuples. The slot is used - * for various operations that are applied to tuples after routing, such - * as checking constraints. - */ - if (partRelInfo->ri_RootToPartitionMap != NULL) + if (ExecGetRootToChildMap(partRelInfo, estate) != NULL) { Relation partrel = partRelInfo->ri_RelationDesc; /* - * Initialize the slot itself setting its descriptor to this - * partition's TupleDesc; TupleDesc reference will be released at the + * This pins the partition's TupleDesc, which will be released at the * end of the command. */ partRelInfo->ri_PartitionTupleSlot = |