mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
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
This commit is contained in:
@@ -174,13 +174,15 @@ BuildIndexValueDescription(Relation indexRelation,
|
||||
StringInfoData buf;
|
||||
Form_pg_index idxrec;
|
||||
HeapTuple ht_idx;
|
||||
int natts = indexRelation->rd_rel->relnatts;
|
||||
int indnkeyatts;
|
||||
int i;
|
||||
int keyno;
|
||||
Oid indexrelid = RelationGetRelid(indexRelation);
|
||||
Oid indrelid;
|
||||
AclResult aclresult;
|
||||
|
||||
indnkeyatts = IndexRelationGetNumberOfKeyAttributes(indexRelation);
|
||||
|
||||
/*
|
||||
* Check permissions- if the user does not have access to view all of the
|
||||
* key columns then return NULL to avoid leaking data.
|
||||
@@ -218,7 +220,7 @@ BuildIndexValueDescription(Relation indexRelation,
|
||||
* No table-level access, so step through the columns in the index and
|
||||
* make sure the user has SELECT rights on all of them.
|
||||
*/
|
||||
for (keyno = 0; keyno < idxrec->indnatts; keyno++)
|
||||
for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
|
||||
{
|
||||
AttrNumber attnum = idxrec->indkey.values[keyno];
|
||||
|
||||
@@ -244,7 +246,7 @@ BuildIndexValueDescription(Relation indexRelation,
|
||||
appendStringInfo(&buf, "(%s)=(",
|
||||
pg_get_indexdef_columns(indexrelid, true));
|
||||
|
||||
for (i = 0; i < natts; i++)
|
||||
for (i = 0; i < indnkeyatts; i++)
|
||||
{
|
||||
char *val;
|
||||
|
||||
@@ -362,7 +364,7 @@ systable_beginscan(Relation heapRelation,
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < irel->rd_index->indnatts; j++)
|
||||
for (j = 0; j < IndexRelationGetNumberOfAttributes(irel); j++)
|
||||
{
|
||||
if (key[i].sk_attno == irel->rd_index->indkey.values[j])
|
||||
{
|
||||
@@ -370,7 +372,7 @@ systable_beginscan(Relation heapRelation,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == irel->rd_index->indnatts)
|
||||
if (j == IndexRelationGetNumberOfAttributes(irel))
|
||||
elog(ERROR, "column is not in index");
|
||||
}
|
||||
|
||||
@@ -564,7 +566,7 @@ systable_beginscan_ordered(Relation heapRelation,
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < indexRelation->rd_index->indnatts; j++)
|
||||
for (j = 0; j < IndexRelationGetNumberOfAttributes(indexRelation); j++)
|
||||
{
|
||||
if (key[i].sk_attno == indexRelation->rd_index->indkey.values[j])
|
||||
{
|
||||
@@ -572,7 +574,7 @@ systable_beginscan_ordered(Relation heapRelation,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == indexRelation->rd_index->indnatts)
|
||||
if (j == IndexRelationGetNumberOfAttributes(indexRelation))
|
||||
elog(ERROR, "column is not in index");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user