From fb958b5da86da69651f6fb9f540c2cfb1346cdc5 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 2 Dec 2022 10:35:55 +0100 Subject: 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 Discussion: https://postgr.es/m/CA+HiwqEYUhDXSK5BTvG_xk=eaAEJCD4GS3C6uH7ybBvv+Z_Tmg@mail.gmail.com --- src/backend/access/common/tupconvert.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/backend/access') diff --git a/src/backend/access/common/tupconvert.c b/src/backend/access/common/tupconvert.c index b2f892d2fdf..4023f533d74 100644 --- a/src/backend/access/common/tupconvert.c +++ b/src/backend/access/common/tupconvert.c @@ -102,9 +102,7 @@ TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc) { - TupleConversionMap *map; AttrMap *attrMap; - int n = outdesc->natts; /* Verify compatibility and prepare attribute-number map */ attrMap = build_attrmap_by_name_if_req(indesc, outdesc, false); @@ -115,6 +113,23 @@ convert_tuples_by_name(TupleDesc indesc, return NULL; } + return convert_tuples_by_name_attrmap(indesc, outdesc, attrMap); +} + +/* + * Set up tuple conversion for input and output TupleDescs using the given + * AttrMap. + */ +TupleConversionMap * +convert_tuples_by_name_attrmap(TupleDesc indesc, + TupleDesc outdesc, + AttrMap *attrMap) +{ + int n = outdesc->natts; + TupleConversionMap *map; + + Assert(attrMap != NULL); + /* Prepare the map structure */ map = (TupleConversionMap *) palloc(sizeof(TupleConversionMap)); map->indesc = indesc; -- cgit v1.2.3