aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/common
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2016-04-08 19:31:49 +0300
committerTeodor Sigaev <teodor@sigaev.ru>2016-04-08 19:45:59 +0300
commit386e3d7609c49505e079c40c65919d99feb82505 (patch)
treedd8f434e5401588c2b4f9e2068f396c5ce198cf6 /src/backend/access/common
parent339025c68f95d3cb2c42478109cafeaf414c7fe0 (diff)
downloadpostgresql-386e3d7609c49505e079c40c65919d99feb82505.tar.gz
postgresql-386e3d7609c49505e079c40c65919d99feb82505.zip
CREATE INDEX ... INCLUDING (column[, ...])
Now indexes (but only B-tree for now) can contain "extra" column(s) which doesn't participate in index structure, they are just stored in leaf tuples. It allows to use index only scan by using single index instead of two or more indexes. Author: Anastasia Lubennikova with minor editorializing by me Reviewers: David Rowley, Peter Geoghegan, Jeff Janes
Diffstat (limited to 'src/backend/access/common')
-rw-r--r--src/backend/access/common/indextuple.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index 274a6c2e702..8884c1e56c4 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"
/* ----------------------------------------------------------------
@@ -441,3 +442,33 @@ CopyIndexTuple(IndexTuple source)
memcpy(result, source, size);
return result;
}
+
+/*
+ * Reform index tuple. Truncate nonkey (INCLUDING) attributes.
+ */
+IndexTuple
+index_truncate_tuple(Relation idxrel, IndexTuple olditup)
+{
+ TupleDesc itupdesc = RelationGetDescr(idxrel);
+ Datum values[INDEX_MAX_KEYS];
+ bool isnull[INDEX_MAX_KEYS];
+ IndexTuple newitup;
+ int indnatts = IndexRelationGetNumberOfAttributes(idxrel);
+ int indnkeyatts = IndexRelationGetNumberOfKeyAttributes(idxrel);
+
+ Assert(indnatts <= INDEX_MAX_KEYS);
+ Assert(indnkeyatts > 0);
+ Assert(indnkeyatts < indnatts);
+
+ index_deform_tuple(olditup, itupdesc, values, isnull);
+
+ /* form new tuple that will contain only key attributes */
+ itupdesc->natts = indnkeyatts;
+ newitup = index_form_tuple(itupdesc, values, isnull);
+ newitup->t_tid = olditup->t_tid;
+
+ itupdesc->natts = indnatts;
+
+ Assert(IndexTupleSize(newitup) <= IndexTupleSize(olditup));
+ return newitup;
+}