Rename IndexInfo.ii_KeyAttrNumbers array

Rename ii_KeyAttrNumbers to ii_IndexAttrNumbers to prevent confusion with
ii_NumIndexAttrs/ii_NumIndexKeyAttrs. ii_IndexAttrNumbers contains
all attributes including "including" columns, not only key attribute.

Discussion: https://www.postgresql.org/message-id/13123421-1d52-d0e4-c95c-6d69011e0595%40sigaev.ru
This commit is contained in:
Teodor Sigaev 2018-04-12 13:02:45 +03:00
parent 9e9befac4a
commit c9c875a28f
7 changed files with 29 additions and 29 deletions

View File

@ -239,7 +239,7 @@ index_check_primary_key(Relation heapRel,
cmds = NIL;
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
{
AttrNumber attnum = indexInfo->ii_KeyAttrNumbers[i];
AttrNumber attnum = indexInfo->ii_IndexAttrNumbers[i];
HeapTuple atttuple;
Form_pg_attribute attform;
@ -324,7 +324,7 @@ ConstructTupleDescriptor(Relation heapRelation,
*/
for (i = 0; i < numatts; i++)
{
AttrNumber atnum = indexInfo->ii_KeyAttrNumbers[i];
AttrNumber atnum = indexInfo->ii_IndexAttrNumbers[i];
Form_pg_attribute to = TupleDescAttr(indexTupDesc, i);
HeapTuple tuple;
Form_pg_type typeTup;
@ -607,7 +607,7 @@ UpdateIndexRelation(Oid indexoid,
*/
indkey = buildint2vector(NULL, indexInfo->ii_NumIndexAttrs);
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
indkey->values[i] = indexInfo->ii_KeyAttrNumbers[i];
indkey->values[i] = indexInfo->ii_IndexAttrNumbers[i];
indcollation = buildoidvector(collationOids, indexInfo->ii_NumIndexAttrs);
indclass = buildoidvector(classOids, indexInfo->ii_NumIndexKeyAttrs);
indoption = buildint2vector(coloptions, indexInfo->ii_NumIndexAttrs);
@ -1041,11 +1041,11 @@ index_create(Relation heapRelation,
/* Create auto dependencies on simply-referenced columns */
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
if (indexInfo->ii_KeyAttrNumbers[i] != 0)
if (indexInfo->ii_IndexAttrNumbers[i] != 0)
{
referenced.classId = RelationRelationId;
referenced.objectId = heapRelationId;
referenced.objectSubId = indexInfo->ii_KeyAttrNumbers[i];
referenced.objectSubId = indexInfo->ii_IndexAttrNumbers[i];
recordDependencyOn(&myself, &referenced, deptype);
@ -1297,7 +1297,7 @@ index_constraint_create(Relation heapRelation,
true,
parentConstraintId,
RelationGetRelid(heapRelation),
indexInfo->ii_KeyAttrNumbers,
indexInfo->ii_IndexAttrNumbers,
indexInfo->ii_NumIndexKeyAttrs,
indexInfo->ii_NumIndexAttrs,
InvalidOid, /* no domain */
@ -1757,7 +1757,7 @@ BuildIndexInfo(Relation index)
Assert(ii->ii_NumIndexKeyAttrs <= ii->ii_NumIndexAttrs);
for (i = 0; i < numAtts; i++)
ii->ii_KeyAttrNumbers[i] = indexStruct->indkey.values[i];
ii->ii_IndexAttrNumbers[i] = indexStruct->indkey.values[i];
/* fetch any expressions needed for expressional indexes */
ii->ii_Expressions = RelationGetIndexExpressions(index);
@ -1840,13 +1840,13 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
*/
for (i = 0; i < info1->ii_NumIndexAttrs; i++)
{
if (maplen < info2->ii_KeyAttrNumbers[i])
if (maplen < info2->ii_IndexAttrNumbers[i])
elog(ERROR, "incorrect attribute map");
/* ignore expressions at this stage */
if ((info1->ii_KeyAttrNumbers[i] != InvalidAttrNumber) &&
(attmap[info2->ii_KeyAttrNumbers[i] - 1] !=
info1->ii_KeyAttrNumbers[i]))
if ((info1->ii_IndexAttrNumbers[i] != InvalidAttrNumber) &&
(attmap[info2->ii_IndexAttrNumbers[i] - 1] !=
info1->ii_IndexAttrNumbers[i]))
return false;
if (collations1[i] != collations2[i])
@ -2007,7 +2007,7 @@ FormIndexDatum(IndexInfo *indexInfo,
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
int keycol = indexInfo->ii_KeyAttrNumbers[i];
int keycol = indexInfo->ii_IndexAttrNumbers[i];
Datum iDatum;
bool isNull;

View File

@ -304,8 +304,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
indexInfo = makeNode(IndexInfo);
indexInfo->ii_NumIndexAttrs = 2;
indexInfo->ii_NumIndexKeyAttrs = 2;
indexInfo->ii_KeyAttrNumbers[0] = 1;
indexInfo->ii_KeyAttrNumbers[1] = 2;
indexInfo->ii_IndexAttrNumbers[0] = 1;
indexInfo->ii_IndexAttrNumbers[1] = 2;
indexInfo->ii_Expressions = NIL;
indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_Predicate = NIL;

View File

@ -495,7 +495,7 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
tcnt = 0;
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
int keycol = indexInfo->ii_KeyAttrNumbers[i];
int keycol = indexInfo->ii_IndexAttrNumbers[i];
if (keycol == 0)
{

View File

@ -724,7 +724,7 @@ DefineIndex(Oid relationId,
for (j = 0; j < indexInfo->ii_NumIndexAttrs; j++)
{
if (key->partattrs[i] == indexInfo->ii_KeyAttrNumbers[j])
if (key->partattrs[i] == indexInfo->ii_IndexAttrNumbers[j])
{
found = true;
break;
@ -753,7 +753,7 @@ DefineIndex(Oid relationId,
*/
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
AttrNumber attno = indexInfo->ii_KeyAttrNumbers[i];
AttrNumber attno = indexInfo->ii_IndexAttrNumbers[i];
if (attno < 0 && attno != ObjectIdAttributeNumber)
ereport(ERROR,
@ -1428,7 +1428,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
attribute->name)));
}
attform = (Form_pg_attribute) GETSTRUCT(atttuple);
indexInfo->ii_KeyAttrNumbers[attn] = attform->attnum;
indexInfo->ii_IndexAttrNumbers[attn] = attform->attnum;
atttype = attform->atttypid;
attcollation = attform->attcollation;
ReleaseSysCache(atttuple);
@ -1461,11 +1461,11 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
* User wrote "(column)" or "(column COLLATE something)".
* Treat it like simple attribute anyway.
*/
indexInfo->ii_KeyAttrNumbers[attn] = ((Var *) expr)->varattno;
indexInfo->ii_IndexAttrNumbers[attn] = ((Var *) expr)->varattno;
}
else
{
indexInfo->ii_KeyAttrNumbers[attn] = 0; /* marks expression */
indexInfo->ii_IndexAttrNumbers[attn] = 0; /* marks expression */
indexInfo->ii_Expressions = lappend(indexInfo->ii_Expressions,
expr);

View File

@ -5065,7 +5065,7 @@ restart:
/* Collect simple attribute references */
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
int attrnum = indexInfo->ii_KeyAttrNumbers[i];
int attrnum = indexInfo->ii_IndexAttrNumbers[i];
/*
* Since we have covering indexes with non-key columns, we must

View File

@ -3718,7 +3718,7 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
datum2;
bool isnull1,
isnull2;
AttrNumber leading = state->indexInfo->ii_KeyAttrNumbers[0];
AttrNumber leading = state->indexInfo->ii_IndexAttrNumbers[0];
/* Be prepared to compare additional sort keys */
ltup = (HeapTuple) a->tuple;
@ -3761,7 +3761,7 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
for (; nkey < state->nKeys; nkey++, sortKey++)
{
AttrNumber attno = state->indexInfo->ii_KeyAttrNumbers[nkey];
AttrNumber attno = state->indexInfo->ii_IndexAttrNumbers[nkey];
datum1 = heap_getattr(ltup, attno, tupDesc, &isnull1);
datum2 = heap_getattr(rtup, attno, tupDesc, &isnull2);
@ -3833,11 +3833,11 @@ copytup_cluster(Tuplesortstate *state, SortTuple *stup, void *tup)
* set up first-column key value, and potentially abbreviate, if it's a
* simple column
*/
if (state->indexInfo->ii_KeyAttrNumbers[0] == 0)
if (state->indexInfo->ii_IndexAttrNumbers[0] == 0)
return;
original = heap_getattr(tuple,
state->indexInfo->ii_KeyAttrNumbers[0],
state->indexInfo->ii_IndexAttrNumbers[0],
state->tupDesc,
&stup->isnull1);
@ -3881,7 +3881,7 @@ copytup_cluster(Tuplesortstate *state, SortTuple *stup, void *tup)
tuple = (HeapTuple) mtup->tuple;
mtup->datum1 = heap_getattr(tuple,
state->indexInfo->ii_KeyAttrNumbers[0],
state->indexInfo->ii_IndexAttrNumbers[0],
state->tupDesc,
&mtup->isnull1);
}
@ -3935,9 +3935,9 @@ readtup_cluster(Tuplesortstate *state, SortTuple *stup,
&tuplen, sizeof(tuplen));
stup->tuple = (void *) tuple;
/* set up first-column key value, if it's a simple column */
if (state->indexInfo->ii_KeyAttrNumbers[0] != 0)
if (state->indexInfo->ii_IndexAttrNumbers[0] != 0)
stup->datum1 = heap_getattr(tuple,
state->indexInfo->ii_KeyAttrNumbers[0],
state->indexInfo->ii_IndexAttrNumbers[0],
state->tupDesc,
&stup->isnull1);
}

View File

@ -150,7 +150,7 @@ typedef struct IndexInfo
NodeTag type;
int ii_NumIndexAttrs; /* total number of columns in index */
int ii_NumIndexKeyAttrs; /* number of key columns in index */
AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS];
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS];
List *ii_Expressions; /* list of Expr */
List *ii_ExpressionsState; /* list of ExprState */
List *ii_Predicate; /* list of Expr */