mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
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:
parent
9e9befac4a
commit
c9c875a28f
@ -239,7 +239,7 @@ index_check_primary_key(Relation heapRel,
|
|||||||
cmds = NIL;
|
cmds = NIL;
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
|
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
|
||||||
{
|
{
|
||||||
AttrNumber attnum = indexInfo->ii_KeyAttrNumbers[i];
|
AttrNumber attnum = indexInfo->ii_IndexAttrNumbers[i];
|
||||||
HeapTuple atttuple;
|
HeapTuple atttuple;
|
||||||
Form_pg_attribute attform;
|
Form_pg_attribute attform;
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ ConstructTupleDescriptor(Relation heapRelation,
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < numatts; i++)
|
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);
|
Form_pg_attribute to = TupleDescAttr(indexTupDesc, i);
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
Form_pg_type typeTup;
|
Form_pg_type typeTup;
|
||||||
@ -607,7 +607,7 @@ UpdateIndexRelation(Oid indexoid,
|
|||||||
*/
|
*/
|
||||||
indkey = buildint2vector(NULL, indexInfo->ii_NumIndexAttrs);
|
indkey = buildint2vector(NULL, indexInfo->ii_NumIndexAttrs);
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
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);
|
indcollation = buildoidvector(collationOids, indexInfo->ii_NumIndexAttrs);
|
||||||
indclass = buildoidvector(classOids, indexInfo->ii_NumIndexKeyAttrs);
|
indclass = buildoidvector(classOids, indexInfo->ii_NumIndexKeyAttrs);
|
||||||
indoption = buildint2vector(coloptions, indexInfo->ii_NumIndexAttrs);
|
indoption = buildint2vector(coloptions, indexInfo->ii_NumIndexAttrs);
|
||||||
@ -1041,11 +1041,11 @@ index_create(Relation heapRelation,
|
|||||||
/* Create auto dependencies on simply-referenced columns */
|
/* Create auto dependencies on simply-referenced columns */
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
||||||
{
|
{
|
||||||
if (indexInfo->ii_KeyAttrNumbers[i] != 0)
|
if (indexInfo->ii_IndexAttrNumbers[i] != 0)
|
||||||
{
|
{
|
||||||
referenced.classId = RelationRelationId;
|
referenced.classId = RelationRelationId;
|
||||||
referenced.objectId = heapRelationId;
|
referenced.objectId = heapRelationId;
|
||||||
referenced.objectSubId = indexInfo->ii_KeyAttrNumbers[i];
|
referenced.objectSubId = indexInfo->ii_IndexAttrNumbers[i];
|
||||||
|
|
||||||
recordDependencyOn(&myself, &referenced, deptype);
|
recordDependencyOn(&myself, &referenced, deptype);
|
||||||
|
|
||||||
@ -1297,7 +1297,7 @@ index_constraint_create(Relation heapRelation,
|
|||||||
true,
|
true,
|
||||||
parentConstraintId,
|
parentConstraintId,
|
||||||
RelationGetRelid(heapRelation),
|
RelationGetRelid(heapRelation),
|
||||||
indexInfo->ii_KeyAttrNumbers,
|
indexInfo->ii_IndexAttrNumbers,
|
||||||
indexInfo->ii_NumIndexKeyAttrs,
|
indexInfo->ii_NumIndexKeyAttrs,
|
||||||
indexInfo->ii_NumIndexAttrs,
|
indexInfo->ii_NumIndexAttrs,
|
||||||
InvalidOid, /* no domain */
|
InvalidOid, /* no domain */
|
||||||
@ -1757,7 +1757,7 @@ BuildIndexInfo(Relation index)
|
|||||||
Assert(ii->ii_NumIndexKeyAttrs <= ii->ii_NumIndexAttrs);
|
Assert(ii->ii_NumIndexKeyAttrs <= ii->ii_NumIndexAttrs);
|
||||||
|
|
||||||
for (i = 0; i < numAtts; i++)
|
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 */
|
/* fetch any expressions needed for expressional indexes */
|
||||||
ii->ii_Expressions = RelationGetIndexExpressions(index);
|
ii->ii_Expressions = RelationGetIndexExpressions(index);
|
||||||
@ -1840,13 +1840,13 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < info1->ii_NumIndexAttrs; i++)
|
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");
|
elog(ERROR, "incorrect attribute map");
|
||||||
|
|
||||||
/* ignore expressions at this stage */
|
/* ignore expressions at this stage */
|
||||||
if ((info1->ii_KeyAttrNumbers[i] != InvalidAttrNumber) &&
|
if ((info1->ii_IndexAttrNumbers[i] != InvalidAttrNumber) &&
|
||||||
(attmap[info2->ii_KeyAttrNumbers[i] - 1] !=
|
(attmap[info2->ii_IndexAttrNumbers[i] - 1] !=
|
||||||
info1->ii_KeyAttrNumbers[i]))
|
info1->ii_IndexAttrNumbers[i]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (collations1[i] != collations2[i])
|
if (collations1[i] != collations2[i])
|
||||||
@ -2007,7 +2007,7 @@ FormIndexDatum(IndexInfo *indexInfo,
|
|||||||
|
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
||||||
{
|
{
|
||||||
int keycol = indexInfo->ii_KeyAttrNumbers[i];
|
int keycol = indexInfo->ii_IndexAttrNumbers[i];
|
||||||
Datum iDatum;
|
Datum iDatum;
|
||||||
bool isNull;
|
bool isNull;
|
||||||
|
|
||||||
|
@ -304,8 +304,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
|
|||||||
indexInfo = makeNode(IndexInfo);
|
indexInfo = makeNode(IndexInfo);
|
||||||
indexInfo->ii_NumIndexAttrs = 2;
|
indexInfo->ii_NumIndexAttrs = 2;
|
||||||
indexInfo->ii_NumIndexKeyAttrs = 2;
|
indexInfo->ii_NumIndexKeyAttrs = 2;
|
||||||
indexInfo->ii_KeyAttrNumbers[0] = 1;
|
indexInfo->ii_IndexAttrNumbers[0] = 1;
|
||||||
indexInfo->ii_KeyAttrNumbers[1] = 2;
|
indexInfo->ii_IndexAttrNumbers[1] = 2;
|
||||||
indexInfo->ii_Expressions = NIL;
|
indexInfo->ii_Expressions = NIL;
|
||||||
indexInfo->ii_ExpressionsState = NIL;
|
indexInfo->ii_ExpressionsState = NIL;
|
||||||
indexInfo->ii_Predicate = NIL;
|
indexInfo->ii_Predicate = NIL;
|
||||||
|
@ -495,7 +495,7 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
|
|||||||
tcnt = 0;
|
tcnt = 0;
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
||||||
{
|
{
|
||||||
int keycol = indexInfo->ii_KeyAttrNumbers[i];
|
int keycol = indexInfo->ii_IndexAttrNumbers[i];
|
||||||
|
|
||||||
if (keycol == 0)
|
if (keycol == 0)
|
||||||
{
|
{
|
||||||
|
@ -724,7 +724,7 @@ DefineIndex(Oid relationId,
|
|||||||
|
|
||||||
for (j = 0; j < indexInfo->ii_NumIndexAttrs; j++)
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@ -753,7 +753,7 @@ DefineIndex(Oid relationId,
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
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)
|
if (attno < 0 && attno != ObjectIdAttributeNumber)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -1428,7 +1428,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
|
|||||||
attribute->name)));
|
attribute->name)));
|
||||||
}
|
}
|
||||||
attform = (Form_pg_attribute) GETSTRUCT(atttuple);
|
attform = (Form_pg_attribute) GETSTRUCT(atttuple);
|
||||||
indexInfo->ii_KeyAttrNumbers[attn] = attform->attnum;
|
indexInfo->ii_IndexAttrNumbers[attn] = attform->attnum;
|
||||||
atttype = attform->atttypid;
|
atttype = attform->atttypid;
|
||||||
attcollation = attform->attcollation;
|
attcollation = attform->attcollation;
|
||||||
ReleaseSysCache(atttuple);
|
ReleaseSysCache(atttuple);
|
||||||
@ -1461,11 +1461,11 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
|
|||||||
* User wrote "(column)" or "(column COLLATE something)".
|
* User wrote "(column)" or "(column COLLATE something)".
|
||||||
* Treat it like simple attribute anyway.
|
* Treat it like simple attribute anyway.
|
||||||
*/
|
*/
|
||||||
indexInfo->ii_KeyAttrNumbers[attn] = ((Var *) expr)->varattno;
|
indexInfo->ii_IndexAttrNumbers[attn] = ((Var *) expr)->varattno;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
indexInfo->ii_KeyAttrNumbers[attn] = 0; /* marks expression */
|
indexInfo->ii_IndexAttrNumbers[attn] = 0; /* marks expression */
|
||||||
indexInfo->ii_Expressions = lappend(indexInfo->ii_Expressions,
|
indexInfo->ii_Expressions = lappend(indexInfo->ii_Expressions,
|
||||||
expr);
|
expr);
|
||||||
|
|
||||||
|
2
src/backend/utils/cache/relcache.c
vendored
2
src/backend/utils/cache/relcache.c
vendored
@ -5065,7 +5065,7 @@ restart:
|
|||||||
/* Collect simple attribute references */
|
/* Collect simple attribute references */
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
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
|
* Since we have covering indexes with non-key columns, we must
|
||||||
|
@ -3718,7 +3718,7 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
|
|||||||
datum2;
|
datum2;
|
||||||
bool isnull1,
|
bool isnull1,
|
||||||
isnull2;
|
isnull2;
|
||||||
AttrNumber leading = state->indexInfo->ii_KeyAttrNumbers[0];
|
AttrNumber leading = state->indexInfo->ii_IndexAttrNumbers[0];
|
||||||
|
|
||||||
/* Be prepared to compare additional sort keys */
|
/* Be prepared to compare additional sort keys */
|
||||||
ltup = (HeapTuple) a->tuple;
|
ltup = (HeapTuple) a->tuple;
|
||||||
@ -3761,7 +3761,7 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b,
|
|||||||
|
|
||||||
for (; nkey < state->nKeys; nkey++, sortKey++)
|
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);
|
datum1 = heap_getattr(ltup, attno, tupDesc, &isnull1);
|
||||||
datum2 = heap_getattr(rtup, attno, tupDesc, &isnull2);
|
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
|
* set up first-column key value, and potentially abbreviate, if it's a
|
||||||
* simple column
|
* simple column
|
||||||
*/
|
*/
|
||||||
if (state->indexInfo->ii_KeyAttrNumbers[0] == 0)
|
if (state->indexInfo->ii_IndexAttrNumbers[0] == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
original = heap_getattr(tuple,
|
original = heap_getattr(tuple,
|
||||||
state->indexInfo->ii_KeyAttrNumbers[0],
|
state->indexInfo->ii_IndexAttrNumbers[0],
|
||||||
state->tupDesc,
|
state->tupDesc,
|
||||||
&stup->isnull1);
|
&stup->isnull1);
|
||||||
|
|
||||||
@ -3881,7 +3881,7 @@ copytup_cluster(Tuplesortstate *state, SortTuple *stup, void *tup)
|
|||||||
|
|
||||||
tuple = (HeapTuple) mtup->tuple;
|
tuple = (HeapTuple) mtup->tuple;
|
||||||
mtup->datum1 = heap_getattr(tuple,
|
mtup->datum1 = heap_getattr(tuple,
|
||||||
state->indexInfo->ii_KeyAttrNumbers[0],
|
state->indexInfo->ii_IndexAttrNumbers[0],
|
||||||
state->tupDesc,
|
state->tupDesc,
|
||||||
&mtup->isnull1);
|
&mtup->isnull1);
|
||||||
}
|
}
|
||||||
@ -3935,9 +3935,9 @@ readtup_cluster(Tuplesortstate *state, SortTuple *stup,
|
|||||||
&tuplen, sizeof(tuplen));
|
&tuplen, sizeof(tuplen));
|
||||||
stup->tuple = (void *) tuple;
|
stup->tuple = (void *) tuple;
|
||||||
/* set up first-column key value, if it's a simple column */
|
/* 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,
|
stup->datum1 = heap_getattr(tuple,
|
||||||
state->indexInfo->ii_KeyAttrNumbers[0],
|
state->indexInfo->ii_IndexAttrNumbers[0],
|
||||||
state->tupDesc,
|
state->tupDesc,
|
||||||
&stup->isnull1);
|
&stup->isnull1);
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ typedef struct IndexInfo
|
|||||||
NodeTag type;
|
NodeTag type;
|
||||||
int ii_NumIndexAttrs; /* total number of columns in index */
|
int ii_NumIndexAttrs; /* total number of columns in index */
|
||||||
int ii_NumIndexKeyAttrs; /* number of key 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_Expressions; /* list of Expr */
|
||||||
List *ii_ExpressionsState; /* list of ExprState */
|
List *ii_ExpressionsState; /* list of ExprState */
|
||||||
List *ii_Predicate; /* list of Expr */
|
List *ii_Predicate; /* list of Expr */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user