mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +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:
@ -1144,7 +1144,9 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
|
||||
Expr *leftop; /* expr on lhs of operator */
|
||||
Expr *rightop; /* expr on rhs ... */
|
||||
AttrNumber varattno; /* att number used in scan */
|
||||
int indnkeyatts;
|
||||
|
||||
indnkeyatts = IndexRelationGetNumberOfKeyAttributes(index);
|
||||
if (IsA(clause, OpExpr))
|
||||
{
|
||||
/* indexkey op const or indexkey op expression */
|
||||
@ -1169,7 +1171,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
|
||||
elog(ERROR, "indexqual doesn't have key on left side");
|
||||
|
||||
varattno = ((Var *) leftop)->varattno;
|
||||
if (varattno < 1 || varattno > index->rd_index->indnatts)
|
||||
if (varattno < 1 || varattno > indnkeyatts)
|
||||
elog(ERROR, "bogus index qualification");
|
||||
|
||||
/*
|
||||
@ -1292,7 +1294,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
|
||||
opnos_cell = lnext(opnos_cell);
|
||||
|
||||
if (index->rd_rel->relam != BTREE_AM_OID ||
|
||||
varattno < 1 || varattno > index->rd_index->indnatts)
|
||||
varattno < 1 || varattno > indnkeyatts)
|
||||
elog(ERROR, "bogus RowCompare index qualification");
|
||||
opfamily = index->rd_opfamily[varattno - 1];
|
||||
|
||||
@ -1413,7 +1415,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
|
||||
elog(ERROR, "indexqual doesn't have key on left side");
|
||||
|
||||
varattno = ((Var *) leftop)->varattno;
|
||||
if (varattno < 1 || varattno > index->rd_index->indnatts)
|
||||
if (varattno < 1 || varattno > indnkeyatts)
|
||||
elog(ERROR, "bogus index qualification");
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user