mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Use slots more widely in tuple mapping code and make naming more consistent.
It's inefficient to use a single slot for mapping between tuple descriptors for multiple tuples, as previously done when using ConvertPartitionTupleSlot(), as that means the slot's tuple descriptors change for every tuple. Previously we also, via ConvertPartitionTupleSlot(), built new tuples after the mapping even in cases where we, immediately afterwards, access individual columns again. Refactor the code so one slot, on demand, is used for each partition. That avoids having to change the descriptor (and allows to use the more efficient "fixed" tuple slots). Then use slot->slot mapping, to avoid unnecessarily forming a tuple. As the naming between the tuple and slot mapping functions wasn't consistent, rename them to execute_attr_map_{tuple,slot}. It's likely that we'll also rename convert_tuples_by_* to denote that these functions "only" build a map, but that's left for later. Author: Amit Khandekar and Amit Langote, editorialized by me Reviewed-By: Amit Langote, Amit Khandekar, Andres Freund Discussion: https://postgr.es/m/CAJ3gD9fR0wRNeAE8VqffNTyONS_UfFPRpqxhnD9Q42vZB+Jvpg@mail.gmail.com https://postgr.es/m/e4f9d743-cd4b-efb0-7574-da21d86a7f36%40lab.ntt.co.jp Backpatch: -
This commit is contained in:
@ -1955,21 +1955,22 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
|
||||
*/
|
||||
if (resultRelInfo->ri_PartitionRoot)
|
||||
{
|
||||
HeapTuple tuple = ExecFetchSlotTuple(slot);
|
||||
TupleDesc old_tupdesc = RelationGetDescr(rel);
|
||||
TupleConversionMap *map;
|
||||
AttrNumber *map;
|
||||
|
||||
rel = resultRelInfo->ri_PartitionRoot;
|
||||
tupdesc = RelationGetDescr(rel);
|
||||
/* a reverse map */
|
||||
map = convert_tuples_by_name(old_tupdesc, tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
map = convert_tuples_by_name_map_if_req(old_tupdesc, tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
|
||||
/*
|
||||
* Partition-specific slot's tupdesc can't be changed, so allocate a
|
||||
* new one.
|
||||
*/
|
||||
if (map != NULL)
|
||||
{
|
||||
tuple = do_convert_tuple(tuple, map);
|
||||
ExecSetSlotDescriptor(slot, tupdesc);
|
||||
ExecStoreHeapTuple(tuple, slot, false);
|
||||
}
|
||||
slot = execute_attr_map_slot(map, slot,
|
||||
MakeTupleTableSlot(tupdesc));
|
||||
}
|
||||
|
||||
insertedCols = GetInsertedColumns(resultRelInfo, estate);
|
||||
@ -2035,20 +2036,22 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
|
||||
*/
|
||||
if (resultRelInfo->ri_PartitionRoot)
|
||||
{
|
||||
HeapTuple tuple = ExecFetchSlotTuple(slot);
|
||||
TupleConversionMap *map;
|
||||
AttrNumber *map;
|
||||
|
||||
rel = resultRelInfo->ri_PartitionRoot;
|
||||
tupdesc = RelationGetDescr(rel);
|
||||
/* a reverse map */
|
||||
map = convert_tuples_by_name(orig_tupdesc, tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
map = convert_tuples_by_name_map_if_req(orig_tupdesc,
|
||||
tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
|
||||
/*
|
||||
* Partition-specific slot's tupdesc can't be changed, so
|
||||
* allocate a new one.
|
||||
*/
|
||||
if (map != NULL)
|
||||
{
|
||||
tuple = do_convert_tuple(tuple, map);
|
||||
ExecSetSlotDescriptor(slot, tupdesc);
|
||||
ExecStoreHeapTuple(tuple, slot, false);
|
||||
}
|
||||
slot = execute_attr_map_slot(map, slot,
|
||||
MakeTupleTableSlot(tupdesc));
|
||||
}
|
||||
|
||||
insertedCols = GetInsertedColumns(resultRelInfo, estate);
|
||||
@ -2082,21 +2085,23 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
|
||||
/* See the comment above. */
|
||||
if (resultRelInfo->ri_PartitionRoot)
|
||||
{
|
||||
HeapTuple tuple = ExecFetchSlotTuple(slot);
|
||||
TupleDesc old_tupdesc = RelationGetDescr(rel);
|
||||
TupleConversionMap *map;
|
||||
AttrNumber *map;
|
||||
|
||||
rel = resultRelInfo->ri_PartitionRoot;
|
||||
tupdesc = RelationGetDescr(rel);
|
||||
/* a reverse map */
|
||||
map = convert_tuples_by_name(old_tupdesc, tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
map = convert_tuples_by_name_map_if_req(old_tupdesc,
|
||||
tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
|
||||
/*
|
||||
* Partition-specific slot's tupdesc can't be changed, so
|
||||
* allocate a new one.
|
||||
*/
|
||||
if (map != NULL)
|
||||
{
|
||||
tuple = do_convert_tuple(tuple, map);
|
||||
ExecSetSlotDescriptor(slot, tupdesc);
|
||||
ExecStoreHeapTuple(tuple, slot, false);
|
||||
}
|
||||
slot = execute_attr_map_slot(map, slot,
|
||||
MakeTupleTableSlot(tupdesc));
|
||||
}
|
||||
|
||||
insertedCols = GetInsertedColumns(resultRelInfo, estate);
|
||||
@ -2188,21 +2193,23 @@ ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
|
||||
/* See the comment in ExecConstraints(). */
|
||||
if (resultRelInfo->ri_PartitionRoot)
|
||||
{
|
||||
HeapTuple tuple = ExecFetchSlotTuple(slot);
|
||||
TupleDesc old_tupdesc = RelationGetDescr(rel);
|
||||
TupleConversionMap *map;
|
||||
AttrNumber *map;
|
||||
|
||||
rel = resultRelInfo->ri_PartitionRoot;
|
||||
tupdesc = RelationGetDescr(rel);
|
||||
/* a reverse map */
|
||||
map = convert_tuples_by_name(old_tupdesc, tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
map = convert_tuples_by_name_map_if_req(old_tupdesc,
|
||||
tupdesc,
|
||||
gettext_noop("could not convert row type"));
|
||||
|
||||
/*
|
||||
* Partition-specific slot's tupdesc can't be changed,
|
||||
* so allocate a new one.
|
||||
*/
|
||||
if (map != NULL)
|
||||
{
|
||||
tuple = do_convert_tuple(tuple, map);
|
||||
ExecSetSlotDescriptor(slot, tupdesc);
|
||||
ExecStoreHeapTuple(tuple, slot, false);
|
||||
}
|
||||
slot = execute_attr_map_slot(map, slot,
|
||||
MakeTupleTableSlot(tupdesc));
|
||||
}
|
||||
|
||||
insertedCols = GetInsertedColumns(resultRelInfo, estate);
|
||||
|
Reference in New Issue
Block a user