diff options
Diffstat (limited to 'src/backend/access/common/indextuple.c')
-rw-r--r-- | src/backend/access/common/indextuple.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index f7103e53bcc..a9c0b620ec0 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -19,6 +19,7 @@ #include "access/heapam.h" #include "access/itup.h" #include "access/tuptoaster.h" +#include "utils/rel.h" /* ---------------------------------------------------------------- @@ -445,3 +446,33 @@ CopyIndexTuple(IndexTuple source) memcpy(result, source, size); return result; } + +/* + * Truncate tailing attributes from given index tuple leaving it with + * new_indnatts number of attributes. + */ +IndexTuple +index_truncate_tuple(TupleDesc tupleDescriptor, IndexTuple olditup, + int new_indnatts) +{ + TupleDesc itupdesc = CreateTupleDescCopyConstr(tupleDescriptor); + Datum values[INDEX_MAX_KEYS]; + bool isnull[INDEX_MAX_KEYS]; + IndexTuple newitup; + int indnatts = tupleDescriptor->natts; + + Assert(indnatts <= INDEX_MAX_KEYS); + Assert(new_indnatts > 0); + Assert(new_indnatts < indnatts); + + index_deform_tuple(olditup, tupleDescriptor, values, isnull); + + /* form new tuple that will contain only key attributes */ + itupdesc->natts = new_indnatts; + newitup = index_form_tuple(itupdesc, values, isnull); + newitup->t_tid = olditup->t_tid; + + FreeTupleDesc(itupdesc); + Assert(IndexTupleSize(newitup) <= IndexTupleSize(olditup)); + return newitup; +} |