|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* tupconvert.c
|
|
|
|
|
* Tuple conversion support.
|
|
|
|
|
*
|
|
|
|
|
* These functions provide conversion between rowtypes that are logically
|
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: -
7 years ago
|
|
|
* equivalent but might have columns in a different order or different sets of
|
|
|
|
|
* dropped columns.
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
|
|
|
|
* src/backend/access/common/tupconvert.c
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
|
#include "access/tupconvert.h"
|
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: -
7 years ago
|
|
|
#include "executor/tuptable.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The conversion setup routines have the following common API:
|
|
|
|
|
*
|
|
|
|
|
* The setup routine checks using attmap.c whether the given source and
|
|
|
|
|
* destination tuple descriptors are logically compatible. If not, it throws
|
|
|
|
|
* an error. If so, it returns NULL if they are physically compatible (ie, no
|
|
|
|
|
* conversion is needed), else a TupleConversionMap that can be used by
|
|
|
|
|
* execute_attr_map_tuple or execute_attr_map_slot to perform the conversion.
|
|
|
|
|
*
|
|
|
|
|
* The TupleConversionMap, if needed, is palloc'd in the caller's memory
|
|
|
|
|
* context. Also, the given tuple descriptors are referenced by the map,
|
|
|
|
|
* so they must survive as long as the map is needed.
|
|
|
|
|
*
|
|
|
|
|
* The caller must supply a suitable primary error message to be used if
|
|
|
|
|
* a compatibility error is thrown. Recommended coding practice is to use
|
|
|
|
|
* gettext_noop() on this string, so that it is translatable but won't
|
|
|
|
|
* actually be translated unless the error gets thrown.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Implementation notes:
|
|
|
|
|
*
|
|
|
|
|
* The key component of a TupleConversionMap is an attrMap[] array with
|
|
|
|
|
* one entry per output column. This entry contains the 1-based index of
|
|
|
|
|
* the corresponding input column, or zero to force a NULL value (for
|
|
|
|
|
* a dropped output column). The TupleConversionMap also contains workspace
|
|
|
|
|
* arrays.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set up for tuple conversion, matching input and output columns by
|
|
|
|
|
* position. (Dropped columns are ignored in both input and output.)
|
|
|
|
|
*/
|
|
|
|
|
TupleConversionMap *
|
|
|
|
|
convert_tuples_by_position(TupleDesc indesc,
|
|
|
|
|
TupleDesc outdesc,
|
|
|
|
|
const char *msg)
|
|
|
|
|
{
|
|
|
|
|
TupleConversionMap *map;
|
|
|
|
|
int n;
|
|
|
|
|
AttrMap *attrMap;
|
|
|
|
|
|
|
|
|
|
/* Verify compatibility and prepare attribute-number map */
|
|
|
|
|
attrMap = build_attrmap_by_position(indesc, outdesc, msg);
|
|
|
|
|
|
|
|
|
|
if (attrMap == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* runtime conversion is not needed */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Prepare the map structure */
|
|
|
|
|
map = (TupleConversionMap *) palloc(sizeof(TupleConversionMap));
|
|
|
|
|
map->indesc = indesc;
|
|
|
|
|
map->outdesc = outdesc;
|
|
|
|
|
map->attrMap = attrMap;
|
|
|
|
|
/* preallocate workspace for Datum arrays */
|
|
|
|
|
n = outdesc->natts + 1; /* +1 for NULL */
|
|
|
|
|
map->outvalues = (Datum *) palloc(n * sizeof(Datum));
|
|
|
|
|
map->outisnull = (bool *) palloc(n * sizeof(bool));
|
|
|
|
|
n = indesc->natts + 1; /* +1 for NULL */
|
|
|
|
|
map->invalues = (Datum *) palloc(n * sizeof(Datum));
|
|
|
|
|
map->inisnull = (bool *) palloc(n * sizeof(bool));
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
9 years ago
|
|
|
map->invalues[0] = (Datum) 0; /* set up the NULL entry */
|
|
|
|
|
map->inisnull[0] = true;
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set up for tuple conversion, matching input and output columns by name.
|
|
|
|
|
* (Dropped columns are ignored in both input and output.) This is intended
|
|
|
|
|
* for use when the rowtypes are related by inheritance, so we expect an exact
|
|
|
|
|
* match of both type and typmod. The error messages will be a bit unhelpful
|
|
|
|
|
* unless both rowtypes are named composite types.
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
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: -
7 years ago
|
|
|
if (attrMap == NULL)
|
|
|
|
|
{
|
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: -
7 years ago
|
|
|
/* runtime conversion is not needed */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Prepare the map structure */
|
|
|
|
|
map = (TupleConversionMap *) palloc(sizeof(TupleConversionMap));
|
|
|
|
|
map->indesc = indesc;
|
|
|
|
|
map->outdesc = outdesc;
|
|
|
|
|
map->attrMap = attrMap;
|
|
|
|
|
/* preallocate workspace for Datum arrays */
|
|
|
|
|
map->outvalues = (Datum *) palloc(n * sizeof(Datum));
|
|
|
|
|
map->outisnull = (bool *) palloc(n * sizeof(bool));
|
|
|
|
|
n = indesc->natts + 1; /* +1 for NULL */
|
|
|
|
|
map->invalues = (Datum *) palloc(n * sizeof(Datum));
|
|
|
|
|
map->inisnull = (bool *) palloc(n * sizeof(bool));
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
9 years ago
|
|
|
map->invalues[0] = (Datum) 0; /* set up the NULL entry */
|
|
|
|
|
map->inisnull[0] = true;
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Perform conversion of a tuple according to the map.
|
|
|
|
|
*/
|
|
|
|
|
HeapTuple
|
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: -
7 years ago
|
|
|
execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
|
|
|
|
|
{
|
|
|
|
|
AttrMap *attrMap = map->attrMap;
|
|
|
|
|
Datum *invalues = map->invalues;
|
|
|
|
|
bool *inisnull = map->inisnull;
|
|
|
|
|
Datum *outvalues = map->outvalues;
|
|
|
|
|
bool *outisnull = map->outisnull;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Extract all the values of the old tuple, offsetting the arrays so that
|
|
|
|
|
* invalues[0] is left NULL and invalues[1] is the first source attribute;
|
|
|
|
|
* this exactly matches the numbering convention in attrMap.
|
|
|
|
|
*/
|
|
|
|
|
heap_deform_tuple(tuple, map->indesc, invalues + 1, inisnull + 1);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Transpose into proper fields of the new tuple.
|
|
|
|
|
*/
|
|
|
|
|
Assert(attrMap->maplen == map->outdesc->natts);
|
|
|
|
|
for (i = 0; i < attrMap->maplen; i++)
|
|
|
|
|
{
|
|
|
|
|
int j = attrMap->attnums[i];
|
|
|
|
|
|
|
|
|
|
outvalues[i] = invalues[j];
|
|
|
|
|
outisnull[i] = inisnull[j];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now form the new tuple.
|
|
|
|
|
*/
|
|
|
|
|
return heap_form_tuple(map->outdesc, outvalues, outisnull);
|
|
|
|
|
}
|
|
|
|
|
|
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: -
7 years ago
|
|
|
/*
|
|
|
|
|
* Perform conversion of a tuple slot according to the map.
|
|
|
|
|
*/
|
|
|
|
|
TupleTableSlot *
|
|
|
|
|
execute_attr_map_slot(AttrMap *attrMap,
|
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: -
7 years ago
|
|
|
TupleTableSlot *in_slot,
|
|
|
|
|
TupleTableSlot *out_slot)
|
|
|
|
|
{
|
|
|
|
|
Datum *invalues;
|
|
|
|
|
bool *inisnull;
|
|
|
|
|
Datum *outvalues;
|
|
|
|
|
bool *outisnull;
|
|
|
|
|
int outnatts;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
Assert(in_slot->tts_tupleDescriptor != NULL &&
|
|
|
|
|
out_slot->tts_tupleDescriptor != NULL);
|
|
|
|
|
Assert(in_slot->tts_values != NULL && out_slot->tts_values != NULL);
|
|
|
|
|
|
|
|
|
|
outnatts = out_slot->tts_tupleDescriptor->natts;
|
|
|
|
|
|
|
|
|
|
/* Extract all the values of the in slot. */
|
|
|
|
|
slot_getallattrs(in_slot);
|
|
|
|
|
|
|
|
|
|
/* Before doing the mapping, clear any old contents from the out slot */
|
|
|
|
|
ExecClearTuple(out_slot);
|
|
|
|
|
|
|
|
|
|
invalues = in_slot->tts_values;
|
|
|
|
|
inisnull = in_slot->tts_isnull;
|
|
|
|
|
outvalues = out_slot->tts_values;
|
|
|
|
|
outisnull = out_slot->tts_isnull;
|
|
|
|
|
|
|
|
|
|
/* Transpose into proper fields of the out slot. */
|
|
|
|
|
for (i = 0; i < outnatts; i++)
|
|
|
|
|
{
|
|
|
|
|
int j = attrMap->attnums[i] - 1;
|
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: -
7 years ago
|
|
|
|
|
|
|
|
/* attrMap->attnums[i] == 0 means it's a NULL datum. */
|
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: -
7 years ago
|
|
|
if (j == -1)
|
|
|
|
|
{
|
|
|
|
|
outvalues[i] = (Datum) 0;
|
|
|
|
|
outisnull[i] = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
outvalues[i] = invalues[j];
|
|
|
|
|
outisnull[i] = inisnull[j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExecStoreVirtualTuple(out_slot);
|
|
|
|
|
|
|
|
|
|
return out_slot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Free a TupleConversionMap structure.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
free_conversion_map(TupleConversionMap *map)
|
|
|
|
|
{
|
|
|
|
|
/* indesc and outdesc are not ours to free */
|
|
|
|
|
free_attrmap(map->attrMap);
|
|
|
|
|
pfree(map->invalues);
|
|
|
|
|
pfree(map->inisnull);
|
|
|
|
|
pfree(map->outvalues);
|
|
|
|
|
pfree(map->outisnull);
|
|
|
|
|
pfree(map);
|
|
|
|
|
}
|