mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +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:
@ -31,6 +31,7 @@
|
||||
#include "commands/trigger.h"
|
||||
#include "executor/execPartition.h"
|
||||
#include "executor/executor.h"
|
||||
#include "executor/tuptable.h"
|
||||
#include "foreign/fdwapi.h"
|
||||
#include "libpq/libpq.h"
|
||||
#include "libpq/pqformat.h"
|
||||
@ -2691,6 +2692,7 @@ CopyFrom(CopyState cstate)
|
||||
if (proute)
|
||||
{
|
||||
int leaf_part_index;
|
||||
TupleConversionMap *map;
|
||||
|
||||
/*
|
||||
* Away we go ... If we end up not finding a partition after all,
|
||||
@ -2862,14 +2864,27 @@ CopyFrom(CopyState cstate)
|
||||
|
||||
/*
|
||||
* We might need to convert from the parent rowtype to the
|
||||
* partition rowtype. Don't free the already stored tuple as it
|
||||
* may still be required for a multi-insert batch.
|
||||
* partition rowtype.
|
||||
*/
|
||||
tuple = ConvertPartitionTupleSlot(proute->parent_child_tupconv_maps[leaf_part_index],
|
||||
tuple,
|
||||
proute->partition_tuple_slot,
|
||||
&slot,
|
||||
false);
|
||||
map = proute->parent_child_tupconv_maps[leaf_part_index];
|
||||
if (map != NULL)
|
||||
{
|
||||
TupleTableSlot *new_slot;
|
||||
MemoryContext oldcontext;
|
||||
|
||||
Assert(proute->partition_tuple_slots != NULL &&
|
||||
proute->partition_tuple_slots[leaf_part_index] != NULL);
|
||||
new_slot = proute->partition_tuple_slots[leaf_part_index];
|
||||
slot = execute_attr_map_slot(map->attrMap, slot, new_slot);
|
||||
|
||||
/*
|
||||
* Get the tuple in the per-tuple context, so that it will be
|
||||
* freed after each batch insert.
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
|
||||
tuple = ExecCopySlotTuple(slot);
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
}
|
||||
|
||||
tuple->t_tableOid = RelationGetRelid(resultRelInfo->ri_RelationDesc);
|
||||
}
|
||||
|
Reference in New Issue
Block a user