1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-31 03:21:24 +03:00

Remove IndexInfo.ii_OpclassOptions field

It is unnecessary to include this field in IndexInfo.  It is only used
by DDL code, not during execution.  It is really only used to pass
local information around between functions in index.c and indexcmds.c,
for which it is clearer to use local variables, like in similar cases.

Discussion: https://www.postgresql.org/message-id/flat/f84640e3-00d3-5abd-3f41-e6a19d33c40b@eisentraut.org
This commit is contained in:
Peter Eisentraut 2023-10-03 17:39:31 +02:00
parent af3ee8a086
commit 7841623571
6 changed files with 34 additions and 37 deletions

View File

@ -720,6 +720,7 @@ index_create(Relation heapRelation,
Oid tableSpaceId, Oid tableSpaceId,
const Oid *collationIds, const Oid *collationIds,
const Oid *opclassIds, const Oid *opclassIds,
const Datum *opclassOptions,
const int16 *coloptions, const int16 *coloptions,
Datum reloptions, Datum reloptions,
bits16 flags, bits16 flags,
@ -1015,7 +1016,7 @@ index_create(Relation heapRelation,
/* /*
* append ATTRIBUTE tuples for the index * append ATTRIBUTE tuples for the index
*/ */
AppendAttributeTuples(indexRelation, indexInfo->ii_OpclassOptions); AppendAttributeTuples(indexRelation, opclassOptions);
/* ---------------- /* ----------------
* update pg_index * update pg_index
@ -1223,10 +1224,10 @@ index_create(Relation heapRelation,
indexRelation->rd_index->indnkeyatts = indexInfo->ii_NumIndexKeyAttrs; indexRelation->rd_index->indnkeyatts = indexInfo->ii_NumIndexKeyAttrs;
/* Validate opclass-specific options */ /* Validate opclass-specific options */
if (indexInfo->ii_OpclassOptions) if (opclassOptions)
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++) for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
(void) index_opclass_options(indexRelation, i + 1, (void) index_opclass_options(indexRelation, i + 1,
indexInfo->ii_OpclassOptions[i], opclassOptions[i],
true); true);
/* /*
@ -1290,7 +1291,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
classTuple; classTuple;
Datum indclassDatum, Datum indclassDatum,
colOptionDatum, colOptionDatum,
optionDatum; reloptionsDatum;
Datum *opclassOptions;
oidvector *indclass; oidvector *indclass;
int2vector *indcoloptions; int2vector *indcoloptions;
bool isnull; bool isnull;
@ -1324,11 +1326,11 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
Anum_pg_index_indoption); Anum_pg_index_indoption);
indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum); indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum);
/* Fetch options of index if any */ /* Fetch reloptions of index if any */
classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(oldIndexId)); classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(oldIndexId));
if (!HeapTupleIsValid(classTuple)) if (!HeapTupleIsValid(classTuple))
elog(ERROR, "cache lookup failed for relation %u", oldIndexId); elog(ERROR, "cache lookup failed for relation %u", oldIndexId);
optionDatum = SysCacheGetAttr(RELOID, classTuple, reloptionsDatum = SysCacheGetAttr(RELOID, classTuple,
Anum_pg_class_reloptions, &isnull); Anum_pg_class_reloptions, &isnull);
/* /*
@ -1392,14 +1394,10 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
newInfo->ii_IndexAttrNumbers[i] = oldInfo->ii_IndexAttrNumbers[i]; newInfo->ii_IndexAttrNumbers[i] = oldInfo->ii_IndexAttrNumbers[i];
} }
/* Extract opclass parameters for each attribute, if any */ /* Extract opclass options for each attribute */
if (oldInfo->ii_OpclassOptions != NULL) opclassOptions = palloc0(sizeof(Datum) * newInfo->ii_NumIndexAttrs);
{
newInfo->ii_OpclassOptions = palloc0(sizeof(Datum) *
newInfo->ii_NumIndexAttrs);
for (int i = 0; i < newInfo->ii_NumIndexAttrs; i++) for (int i = 0; i < newInfo->ii_NumIndexAttrs; i++)
newInfo->ii_OpclassOptions[i] = get_attoptions(oldIndexId, i + 1); opclassOptions[i] = get_attoptions(oldIndexId, i + 1);
}
/* /*
* Now create the new index. * Now create the new index.
@ -1420,8 +1418,9 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
tablespaceOid, tablespaceOid,
indexRelation->rd_indcollation, indexRelation->rd_indcollation,
indclass->values, indclass->values,
opclassOptions,
indcoloptions->values, indcoloptions->values,
optionDatum, reloptionsDatum,
INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT, INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT,
0, 0,
true, /* allow table to be a system catalog? */ true, /* allow table to be a system catalog? */
@ -2464,8 +2463,6 @@ BuildIndexInfo(Relation index)
&ii->ii_ExclusionStrats); &ii->ii_ExclusionStrats);
} }
ii->ii_OpclassOptions = RelationGetIndexRawAttOptions(index);
return ii; return ii;
} }

View File

@ -299,7 +299,6 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
indexInfo->ii_ExclusionOps = NULL; indexInfo->ii_ExclusionOps = NULL;
indexInfo->ii_ExclusionProcs = NULL; indexInfo->ii_ExclusionProcs = NULL;
indexInfo->ii_ExclusionStrats = NULL; indexInfo->ii_ExclusionStrats = NULL;
indexInfo->ii_OpclassOptions = NULL;
indexInfo->ii_Unique = true; indexInfo->ii_Unique = true;
indexInfo->ii_NullsNotDistinct = false; indexInfo->ii_NullsNotDistinct = false;
indexInfo->ii_ReadyForInserts = true; indexInfo->ii_ReadyForInserts = true;
@ -327,7 +326,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
list_make2("chunk_id", "chunk_seq"), list_make2("chunk_id", "chunk_seq"),
BTREE_AM_OID, BTREE_AM_OID,
rel->rd_rel->reltablespace, rel->rd_rel->reltablespace,
collationIds, opclassIds, coloptions, (Datum) 0, collationIds, opclassIds, NULL, coloptions, (Datum) 0,
INDEX_CREATE_IS_PRIMARY, 0, true, true, NULL); INDEX_CREATE_IS_PRIMARY, 0, true, true, NULL);
table_close(toast_rel, NoLock); table_close(toast_rel, NoLock);

View File

@ -77,6 +77,7 @@ static void ComputeIndexAttrs(IndexInfo *indexInfo,
Oid *typeOids, Oid *typeOids,
Oid *collationOids, Oid *collationOids,
Oid *opclassOids, Oid *opclassOids,
Datum *opclassOptions,
int16 *colOptions, int16 *colOptions,
const List *attList, const List *attList,
const List *exclusionOpNames, const List *exclusionOpNames,
@ -177,6 +178,7 @@ CheckIndexCompatible(Oid oldId,
Oid *typeIds; Oid *typeIds;
Oid *collationIds; Oid *collationIds;
Oid *opclassIds; Oid *opclassIds;
Datum *opclassOptions;
Oid accessMethodId; Oid accessMethodId;
Oid relationId; Oid relationId;
HeapTuple tuple; HeapTuple tuple;
@ -238,9 +240,10 @@ CheckIndexCompatible(Oid oldId,
typeIds = palloc_array(Oid, numberOfAttributes); typeIds = palloc_array(Oid, numberOfAttributes);
collationIds = palloc_array(Oid, numberOfAttributes); collationIds = palloc_array(Oid, numberOfAttributes);
opclassIds = palloc_array(Oid, numberOfAttributes); opclassIds = palloc_array(Oid, numberOfAttributes);
opclassOptions = palloc_array(Datum, numberOfAttributes);
coloptions = palloc_array(int16, numberOfAttributes); coloptions = palloc_array(int16, numberOfAttributes);
ComputeIndexAttrs(indexInfo, ComputeIndexAttrs(indexInfo,
typeIds, collationIds, opclassIds, typeIds, collationIds, opclassIds, opclassOptions,
coloptions, attributeList, coloptions, attributeList,
exclusionOpNames, relationId, exclusionOpNames, relationId,
accessMethodName, accessMethodId, accessMethodName, accessMethodId,
@ -298,13 +301,12 @@ CheckIndexCompatible(Oid oldId,
/* Any change in opclass options break compatibility. */ /* Any change in opclass options break compatibility. */
if (ret) if (ret)
{ {
Datum *opclassOptions = RelationGetIndexRawAttOptions(irel); Datum *oldOpclassOptions = RelationGetIndexRawAttOptions(irel);
ret = CompareOpclassOptions(opclassOptions, ret = CompareOpclassOptions(oldOpclassOptions, opclassOptions, old_natts);
indexInfo->ii_OpclassOptions, old_natts);
if (opclassOptions) if (oldOpclassOptions)
pfree(opclassOptions); pfree(oldOpclassOptions);
} }
/* Any change in exclusion operator selections breaks compatibility. */ /* Any change in exclusion operator selections breaks compatibility. */
@ -540,6 +542,7 @@ DefineIndex(Oid tableId,
Oid *typeIds; Oid *typeIds;
Oid *collationIds; Oid *collationIds;
Oid *opclassIds; Oid *opclassIds;
Datum *opclassOptions;
Oid accessMethodId; Oid accessMethodId;
Oid namespaceId; Oid namespaceId;
Oid tablespaceId; Oid tablespaceId;
@ -900,9 +903,10 @@ DefineIndex(Oid tableId,
typeIds = palloc_array(Oid, numberOfAttributes); typeIds = palloc_array(Oid, numberOfAttributes);
collationIds = palloc_array(Oid, numberOfAttributes); collationIds = palloc_array(Oid, numberOfAttributes);
opclassIds = palloc_array(Oid, numberOfAttributes); opclassIds = palloc_array(Oid, numberOfAttributes);
opclassOptions = palloc_array(Datum, numberOfAttributes);
coloptions = palloc_array(int16, numberOfAttributes); coloptions = palloc_array(int16, numberOfAttributes);
ComputeIndexAttrs(indexInfo, ComputeIndexAttrs(indexInfo,
typeIds, collationIds, opclassIds, typeIds, collationIds, opclassIds, opclassOptions,
coloptions, allIndexParams, coloptions, allIndexParams,
stmt->excludeOpNames, tableId, stmt->excludeOpNames, tableId,
accessMethodName, accessMethodId, accessMethodName, accessMethodId,
@ -1179,7 +1183,7 @@ DefineIndex(Oid tableId,
parentConstraintId, parentConstraintId,
stmt->oldNumber, indexInfo, indexColNames, stmt->oldNumber, indexInfo, indexColNames,
accessMethodId, tablespaceId, accessMethodId, tablespaceId,
collationIds, opclassIds, collationIds, opclassIds, opclassOptions,
coloptions, reloptions, coloptions, reloptions,
flags, constr_flags, flags, constr_flags,
allowSystemTableMods, !check_rights, allowSystemTableMods, !check_rights,
@ -1855,6 +1859,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
Oid *typeOids, Oid *typeOids,
Oid *collationOids, Oid *collationOids,
Oid *opclassOids, Oid *opclassOids,
Datum *opclassOptions,
int16 *colOptions, int16 *colOptions,
const List *attList, /* list of IndexElem's */ const List *attList, /* list of IndexElem's */
const List *exclusionOpNames, const List *exclusionOpNames,
@ -2011,6 +2016,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
errmsg("including column does not support NULLS FIRST/LAST options"))); errmsg("including column does not support NULLS FIRST/LAST options")));
opclassOids[attn] = InvalidOid; opclassOids[attn] = InvalidOid;
opclassOptions[attn] = (Datum) 0;
colOptions[attn] = 0; colOptions[attn] = 0;
collationOids[attn] = InvalidOid; collationOids[attn] = InvalidOid;
attn++; attn++;
@ -2202,14 +2208,12 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
{ {
Assert(attn < nkeycols); Assert(attn < nkeycols);
if (!indexInfo->ii_OpclassOptions) opclassOptions[attn] =
indexInfo->ii_OpclassOptions =
palloc0_array(Datum, indexInfo->ii_NumIndexAttrs);
indexInfo->ii_OpclassOptions[attn] =
transformRelOptions((Datum) 0, attribute->opclassopts, transformRelOptions((Datum) 0, attribute->opclassopts,
NULL, NULL, false, false); NULL, NULL, false, false);
} }
else
opclassOptions[attn] = (Datum) 0;
attn++; attn++;
} }

View File

@ -777,9 +777,6 @@ makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
n->ii_ExclusionProcs = NULL; n->ii_ExclusionProcs = NULL;
n->ii_ExclusionStrats = NULL; n->ii_ExclusionStrats = NULL;
/* opclass options */
n->ii_OpclassOptions = NULL;
/* speculative inserts */ /* speculative inserts */
n->ii_UniqueOps = NULL; n->ii_UniqueOps = NULL;
n->ii_UniqueProcs = NULL; n->ii_UniqueProcs = NULL;

View File

@ -78,6 +78,7 @@ extern Oid index_create(Relation heapRelation,
Oid tableSpaceId, Oid tableSpaceId,
const Oid *collationIds, const Oid *collationIds,
const Oid *opclassIds, const Oid *opclassIds,
const Datum *opclassOptions,
const int16 *coloptions, const int16 *coloptions,
Datum reloptions, Datum reloptions,
bits16 flags, bits16 flags,

View File

@ -187,7 +187,6 @@ typedef struct IndexInfo
Oid *ii_UniqueOps; /* array with one entry per column */ Oid *ii_UniqueOps; /* array with one entry per column */
Oid *ii_UniqueProcs; /* array with one entry per column */ Oid *ii_UniqueProcs; /* array with one entry per column */
uint16 *ii_UniqueStrats; /* array with one entry per column */ uint16 *ii_UniqueStrats; /* array with one entry per column */
Datum *ii_OpclassOptions; /* array with one entry per column */
bool ii_Unique; bool ii_Unique;
bool ii_NullsNotDistinct; bool ii_NullsNotDistinct;
bool ii_ReadyForInserts; bool ii_ReadyForInserts;