Skip to content

Commit 7841623

Browse files
committed
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
1 parent af3ee8a commit 7841623

File tree

6 files changed

+34
-37
lines changed

6 files changed

+34
-37
lines changed

src/backend/catalog/index.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ index_create(Relation heapRelation,
720720
Oid tableSpaceId,
721721
const Oid *collationIds,
722722
const Oid *opclassIds,
723+
const Datum *opclassOptions,
723724
const int16 *coloptions,
724725
Datum reloptions,
725726
bits16 flags,
@@ -1015,7 +1016,7 @@ index_create(Relation heapRelation,
10151016
/*
10161017
* append ATTRIBUTE tuples for the index
10171018
*/
1018-
AppendAttributeTuples(indexRelation, indexInfo->ii_OpclassOptions);
1019+
AppendAttributeTuples(indexRelation, opclassOptions);
10191020

10201021
/* ----------------
10211022
* update pg_index
@@ -1223,10 +1224,10 @@ index_create(Relation heapRelation,
12231224
indexRelation->rd_index->indnkeyatts = indexInfo->ii_NumIndexKeyAttrs;
12241225

12251226
/* Validate opclass-specific options */
1226-
if (indexInfo->ii_OpclassOptions)
1227+
if (opclassOptions)
12271228
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
12281229
(void) index_opclass_options(indexRelation, i + 1,
1229-
indexInfo->ii_OpclassOptions[i],
1230+
opclassOptions[i],
12301231
true);
12311232

12321233
/*
@@ -1290,7 +1291,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
12901291
classTuple;
12911292
Datum indclassDatum,
12921293
colOptionDatum,
1293-
optionDatum;
1294+
reloptionsDatum;
1295+
Datum *opclassOptions;
12941296
oidvector *indclass;
12951297
int2vector *indcoloptions;
12961298
bool isnull;
@@ -1324,12 +1326,12 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
13241326
Anum_pg_index_indoption);
13251327
indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum);
13261328

1327-
/* Fetch options of index if any */
1329+
/* Fetch reloptions of index if any */
13281330
classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(oldIndexId));
13291331
if (!HeapTupleIsValid(classTuple))
13301332
elog(ERROR, "cache lookup failed for relation %u", oldIndexId);
1331-
optionDatum = SysCacheGetAttr(RELOID, classTuple,
1332-
Anum_pg_class_reloptions, &isnull);
1333+
reloptionsDatum = SysCacheGetAttr(RELOID, classTuple,
1334+
Anum_pg_class_reloptions, &isnull);
13331335

13341336
/*
13351337
* Fetch the list of expressions and predicates directly from the
@@ -1392,14 +1394,10 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
13921394
newInfo->ii_IndexAttrNumbers[i] = oldInfo->ii_IndexAttrNumbers[i];
13931395
}
13941396

1395-
/* Extract opclass parameters for each attribute, if any */
1396-
if (oldInfo->ii_OpclassOptions != NULL)
1397-
{
1398-
newInfo->ii_OpclassOptions = palloc0(sizeof(Datum) *
1399-
newInfo->ii_NumIndexAttrs);
1400-
for (int i = 0; i < newInfo->ii_NumIndexAttrs; i++)
1401-
newInfo->ii_OpclassOptions[i] = get_attoptions(oldIndexId, i + 1);
1402-
}
1397+
/* Extract opclass options for each attribute */
1398+
opclassOptions = palloc0(sizeof(Datum) * newInfo->ii_NumIndexAttrs);
1399+
for (int i = 0; i < newInfo->ii_NumIndexAttrs; i++)
1400+
opclassOptions[i] = get_attoptions(oldIndexId, i + 1);
14031401

14041402
/*
14051403
* Now create the new index.
@@ -1420,8 +1418,9 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
14201418
tablespaceOid,
14211419
indexRelation->rd_indcollation,
14221420
indclass->values,
1421+
opclassOptions,
14231422
indcoloptions->values,
1424-
optionDatum,
1423+
reloptionsDatum,
14251424
INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT,
14261425
0,
14271426
true, /* allow table to be a system catalog? */
@@ -2464,8 +2463,6 @@ BuildIndexInfo(Relation index)
24642463
&ii->ii_ExclusionStrats);
24652464
}
24662465

2467-
ii->ii_OpclassOptions = RelationGetIndexRawAttOptions(index);
2468-
24692466
return ii;
24702467
}
24712468

src/backend/catalog/toasting.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
299299
indexInfo->ii_ExclusionOps = NULL;
300300
indexInfo->ii_ExclusionProcs = NULL;
301301
indexInfo->ii_ExclusionStrats = NULL;
302-
indexInfo->ii_OpclassOptions = NULL;
303302
indexInfo->ii_Unique = true;
304303
indexInfo->ii_NullsNotDistinct = false;
305304
indexInfo->ii_ReadyForInserts = true;
@@ -327,7 +326,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
327326
list_make2("chunk_id", "chunk_seq"),
328327
BTREE_AM_OID,
329328
rel->rd_rel->reltablespace,
330-
collationIds, opclassIds, coloptions, (Datum) 0,
329+
collationIds, opclassIds, NULL, coloptions, (Datum) 0,
331330
INDEX_CREATE_IS_PRIMARY, 0, true, true, NULL);
332331

333332
table_close(toast_rel, NoLock);

src/backend/commands/indexcmds.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void ComputeIndexAttrs(IndexInfo *indexInfo,
7777
Oid *typeOids,
7878
Oid *collationOids,
7979
Oid *opclassOids,
80+
Datum *opclassOptions,
8081
int16 *colOptions,
8182
const List *attList,
8283
const List *exclusionOpNames,
@@ -177,6 +178,7 @@ CheckIndexCompatible(Oid oldId,
177178
Oid *typeIds;
178179
Oid *collationIds;
179180
Oid *opclassIds;
181+
Datum *opclassOptions;
180182
Oid accessMethodId;
181183
Oid relationId;
182184
HeapTuple tuple;
@@ -238,9 +240,10 @@ CheckIndexCompatible(Oid oldId,
238240
typeIds = palloc_array(Oid, numberOfAttributes);
239241
collationIds = palloc_array(Oid, numberOfAttributes);
240242
opclassIds = palloc_array(Oid, numberOfAttributes);
243+
opclassOptions = palloc_array(Datum, numberOfAttributes);
241244
coloptions = palloc_array(int16, numberOfAttributes);
242245
ComputeIndexAttrs(indexInfo,
243-
typeIds, collationIds, opclassIds,
246+
typeIds, collationIds, opclassIds, opclassOptions,
244247
coloptions, attributeList,
245248
exclusionOpNames, relationId,
246249
accessMethodName, accessMethodId,
@@ -298,13 +301,12 @@ CheckIndexCompatible(Oid oldId,
298301
/* Any change in opclass options break compatibility. */
299302
if (ret)
300303
{
301-
Datum *opclassOptions = RelationGetIndexRawAttOptions(irel);
304+
Datum *oldOpclassOptions = RelationGetIndexRawAttOptions(irel);
302305

303-
ret = CompareOpclassOptions(opclassOptions,
304-
indexInfo->ii_OpclassOptions, old_natts);
306+
ret = CompareOpclassOptions(oldOpclassOptions, opclassOptions, old_natts);
305307

306-
if (opclassOptions)
307-
pfree(opclassOptions);
308+
if (oldOpclassOptions)
309+
pfree(oldOpclassOptions);
308310
}
309311

310312
/* Any change in exclusion operator selections breaks compatibility. */
@@ -540,6 +542,7 @@ DefineIndex(Oid tableId,
540542
Oid *typeIds;
541543
Oid *collationIds;
542544
Oid *opclassIds;
545+
Datum *opclassOptions;
543546
Oid accessMethodId;
544547
Oid namespaceId;
545548
Oid tablespaceId;
@@ -900,9 +903,10 @@ DefineIndex(Oid tableId,
900903
typeIds = palloc_array(Oid, numberOfAttributes);
901904
collationIds = palloc_array(Oid, numberOfAttributes);
902905
opclassIds = palloc_array(Oid, numberOfAttributes);
906+
opclassOptions = palloc_array(Datum, numberOfAttributes);
903907
coloptions = palloc_array(int16, numberOfAttributes);
904908
ComputeIndexAttrs(indexInfo,
905-
typeIds, collationIds, opclassIds,
909+
typeIds, collationIds, opclassIds, opclassOptions,
906910
coloptions, allIndexParams,
907911
stmt->excludeOpNames, tableId,
908912
accessMethodName, accessMethodId,
@@ -1179,7 +1183,7 @@ DefineIndex(Oid tableId,
11791183
parentConstraintId,
11801184
stmt->oldNumber, indexInfo, indexColNames,
11811185
accessMethodId, tablespaceId,
1182-
collationIds, opclassIds,
1186+
collationIds, opclassIds, opclassOptions,
11831187
coloptions, reloptions,
11841188
flags, constr_flags,
11851189
allowSystemTableMods, !check_rights,
@@ -1855,6 +1859,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
18551859
Oid *typeOids,
18561860
Oid *collationOids,
18571861
Oid *opclassOids,
1862+
Datum *opclassOptions,
18581863
int16 *colOptions,
18591864
const List *attList, /* list of IndexElem's */
18601865
const List *exclusionOpNames,
@@ -2011,6 +2016,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
20112016
errmsg("including column does not support NULLS FIRST/LAST options")));
20122017

20132018
opclassOids[attn] = InvalidOid;
2019+
opclassOptions[attn] = (Datum) 0;
20142020
colOptions[attn] = 0;
20152021
collationOids[attn] = InvalidOid;
20162022
attn++;
@@ -2202,14 +2208,12 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
22022208
{
22032209
Assert(attn < nkeycols);
22042210

2205-
if (!indexInfo->ii_OpclassOptions)
2206-
indexInfo->ii_OpclassOptions =
2207-
palloc0_array(Datum, indexInfo->ii_NumIndexAttrs);
2208-
2209-
indexInfo->ii_OpclassOptions[attn] =
2211+
opclassOptions[attn] =
22102212
transformRelOptions((Datum) 0, attribute->opclassopts,
22112213
NULL, NULL, false, false);
22122214
}
2215+
else
2216+
opclassOptions[attn] = (Datum) 0;
22132217

22142218
attn++;
22152219
}

src/backend/nodes/makefuncs.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,6 @@ makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
777777
n->ii_ExclusionProcs = NULL;
778778
n->ii_ExclusionStrats = NULL;
779779

780-
/* opclass options */
781-
n->ii_OpclassOptions = NULL;
782-
783780
/* speculative inserts */
784781
n->ii_UniqueOps = NULL;
785782
n->ii_UniqueProcs = NULL;

src/include/catalog/index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extern Oid index_create(Relation heapRelation,
7878
Oid tableSpaceId,
7979
const Oid *collationIds,
8080
const Oid *opclassIds,
81+
const Datum *opclassOptions,
8182
const int16 *coloptions,
8283
Datum reloptions,
8384
bits16 flags,

src/include/nodes/execnodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ typedef struct IndexInfo
187187
Oid *ii_UniqueOps; /* array with one entry per column */
188188
Oid *ii_UniqueProcs; /* array with one entry per column */
189189
uint16 *ii_UniqueStrats; /* array with one entry per column */
190-
Datum *ii_OpclassOptions; /* array with one entry per column */
191190
bool ii_Unique;
192191
bool ii_NullsNotDistinct;
193192
bool ii_ReadyForInserts;

0 commit comments

Comments
 (0)