Remove IndexInfo.ii_OpclassOptions field
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Oct 2023 15:39:31 +0000 (17:39 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Oct 2023 15:51:02 +0000 (17:51 +0200)
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

src/backend/catalog/index.c
src/backend/catalog/toasting.c
src/backend/commands/indexcmds.c
src/backend/nodes/makefuncs.c
src/include/catalog/index.h
src/include/nodes/execnodes.h

index 3d5adab2c530eae6890a1679c5ff72e9cb4de1c2..143fae01ebd548aaf262dca02d569ec01cf7e40a 100644 (file)
@@ -720,6 +720,7 @@ index_create(Relation heapRelation,
                         Oid tableSpaceId,
                         const Oid *collationIds,
                         const Oid *opclassIds,
+                        const Datum *opclassOptions,
                         const int16 *coloptions,
                         Datum reloptions,
                         bits16 flags,
@@ -1015,7 +1016,7 @@ index_create(Relation heapRelation,
        /*
         * append ATTRIBUTE tuples for the index
         */
-       AppendAttributeTuples(indexRelation, indexInfo->ii_OpclassOptions);
+       AppendAttributeTuples(indexRelation, opclassOptions);
 
        /* ----------------
         *        update pg_index
@@ -1223,10 +1224,10 @@ index_create(Relation heapRelation,
        indexRelation->rd_index->indnkeyatts = indexInfo->ii_NumIndexKeyAttrs;
 
        /* Validate opclass-specific options */
-       if (indexInfo->ii_OpclassOptions)
+       if (opclassOptions)
                for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
                        (void) index_opclass_options(indexRelation, i + 1,
-                                                                                indexInfo->ii_OpclassOptions[i],
+                                                                                opclassOptions[i],
                                                                                 true);
 
        /*
@@ -1290,7 +1291,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
                                classTuple;
        Datum           indclassDatum,
                                colOptionDatum,
-                               optionDatum;
+                               reloptionsDatum;
+       Datum      *opclassOptions;
        oidvector  *indclass;
        int2vector *indcoloptions;
        bool            isnull;
@@ -1324,12 +1326,12 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
                                                                                        Anum_pg_index_indoption);
        indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum);
 
-       /* Fetch options of index if any */
+       /* Fetch reloptions of index if any */
        classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(oldIndexId));
        if (!HeapTupleIsValid(classTuple))
                elog(ERROR, "cache lookup failed for relation %u", oldIndexId);
-       optionDatum = SysCacheGetAttr(RELOID, classTuple,
-                                                                 Anum_pg_class_reloptions, &isnull);
+       reloptionsDatum = SysCacheGetAttr(RELOID, classTuple,
+                                                                         Anum_pg_class_reloptions, &isnull);
 
        /*
         * Fetch the list of expressions and predicates directly from the
@@ -1392,14 +1394,10 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
                newInfo->ii_IndexAttrNumbers[i] = oldInfo->ii_IndexAttrNumbers[i];
        }
 
-       /* Extract opclass parameters for each attribute, if any */
-       if (oldInfo->ii_OpclassOptions != NULL)
-       {
-               newInfo->ii_OpclassOptions = palloc0(sizeof(Datum) *
-                                                                                        newInfo->ii_NumIndexAttrs);
-               for (int i = 0; i < newInfo->ii_NumIndexAttrs; i++)
-                       newInfo->ii_OpclassOptions[i] = get_attoptions(oldIndexId, i + 1);
-       }
+       /* Extract opclass options for each attribute */
+       opclassOptions = palloc0(sizeof(Datum) * newInfo->ii_NumIndexAttrs);
+       for (int i = 0; i < newInfo->ii_NumIndexAttrs; i++)
+               opclassOptions[i] = get_attoptions(oldIndexId, i + 1);
 
        /*
         * Now create the new index.
@@ -1420,8 +1418,9 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
                                                          tablespaceOid,
                                                          indexRelation->rd_indcollation,
                                                          indclass->values,
+                                                         opclassOptions,
                                                          indcoloptions->values,
-                                                         optionDatum,
+                                                         reloptionsDatum,
                                                          INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT,
                                                          0,
                                                          true, /* allow table to be a system catalog? */
@@ -2464,8 +2463,6 @@ BuildIndexInfo(Relation index)
                                                                 &ii->ii_ExclusionStrats);
        }
 
-       ii->ii_OpclassOptions = RelationGetIndexRawAttOptions(index);
-
        return ii;
 }
 
index 3fef593bf1a3672b165b7e2119cb1a2f787bedf1..989f8207913741a13608ec1687894cef7f20f763 100644 (file)
@@ -299,7 +299,6 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
        indexInfo->ii_ExclusionOps = NULL;
        indexInfo->ii_ExclusionProcs = NULL;
        indexInfo->ii_ExclusionStrats = NULL;
-       indexInfo->ii_OpclassOptions = NULL;
        indexInfo->ii_Unique = true;
        indexInfo->ii_NullsNotDistinct = false;
        indexInfo->ii_ReadyForInserts = true;
@@ -327,7 +326,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
                                 list_make2("chunk_id", "chunk_seq"),
                                 BTREE_AM_OID,
                                 rel->rd_rel->reltablespace,
-                                collationIds, opclassIds, coloptions, (Datum) 0,
+                                collationIds, opclassIds, NULL, coloptions, (Datum) 0,
                                 INDEX_CREATE_IS_PRIMARY, 0, true, true, NULL);
 
        table_close(toast_rel, NoLock);
index ab8b81b3020198f33e4f8ccb99fda77cb2ea686a..a53861cecf79d26bda2038d5d65119b3d9e32cae 100644 (file)
@@ -77,6 +77,7 @@ static void ComputeIndexAttrs(IndexInfo *indexInfo,
                                                          Oid *typeOids,
                                                          Oid *collationOids,
                                                          Oid *opclassOids,
+                                                         Datum *opclassOptions,
                                                          int16 *colOptions,
                                                          const List *attList,
                                                          const List *exclusionOpNames,
@@ -177,6 +178,7 @@ CheckIndexCompatible(Oid oldId,
        Oid                *typeIds;
        Oid                *collationIds;
        Oid                *opclassIds;
+       Datum      *opclassOptions;
        Oid                     accessMethodId;
        Oid                     relationId;
        HeapTuple       tuple;
@@ -238,9 +240,10 @@ CheckIndexCompatible(Oid oldId,
        typeIds = palloc_array(Oid, numberOfAttributes);
        collationIds = palloc_array(Oid, numberOfAttributes);
        opclassIds = palloc_array(Oid, numberOfAttributes);
+       opclassOptions = palloc_array(Datum, numberOfAttributes);
        coloptions = palloc_array(int16, numberOfAttributes);
        ComputeIndexAttrs(indexInfo,
-                                         typeIds, collationIds, opclassIds,
+                                         typeIds, collationIds, opclassIds, opclassOptions,
                                          coloptions, attributeList,
                                          exclusionOpNames, relationId,
                                          accessMethodName, accessMethodId,
@@ -298,13 +301,12 @@ CheckIndexCompatible(Oid oldId,
        /* Any change in opclass options break compatibility. */
        if (ret)
        {
-               Datum      *opclassOptions = RelationGetIndexRawAttOptions(irel);
+               Datum      *oldOpclassOptions = RelationGetIndexRawAttOptions(irel);
 
-               ret = CompareOpclassOptions(opclassOptions,
-                                                                       indexInfo->ii_OpclassOptions, old_natts);
+               ret = CompareOpclassOptions(oldOpclassOptions, opclassOptions, old_natts);
 
-               if (opclassOptions)
-                       pfree(opclassOptions);
+               if (oldOpclassOptions)
+                       pfree(oldOpclassOptions);
        }
 
        /* Any change in exclusion operator selections breaks compatibility. */
@@ -540,6 +542,7 @@ DefineIndex(Oid tableId,
        Oid                *typeIds;
        Oid                *collationIds;
        Oid                *opclassIds;
+       Datum      *opclassOptions;
        Oid                     accessMethodId;
        Oid                     namespaceId;
        Oid                     tablespaceId;
@@ -900,9 +903,10 @@ DefineIndex(Oid tableId,
        typeIds = palloc_array(Oid, numberOfAttributes);
        collationIds = palloc_array(Oid, numberOfAttributes);
        opclassIds = palloc_array(Oid, numberOfAttributes);
+       opclassOptions = palloc_array(Datum, numberOfAttributes);
        coloptions = palloc_array(int16, numberOfAttributes);
        ComputeIndexAttrs(indexInfo,
-                                         typeIds, collationIds, opclassIds,
+                                         typeIds, collationIds, opclassIds, opclassOptions,
                                          coloptions, allIndexParams,
                                          stmt->excludeOpNames, tableId,
                                          accessMethodName, accessMethodId,
@@ -1179,7 +1183,7 @@ DefineIndex(Oid tableId,
                                         parentConstraintId,
                                         stmt->oldNumber, indexInfo, indexColNames,
                                         accessMethodId, tablespaceId,
-                                        collationIds, opclassIds,
+                                        collationIds, opclassIds, opclassOptions,
                                         coloptions, reloptions,
                                         flags, constr_flags,
                                         allowSystemTableMods, !check_rights,
@@ -1855,6 +1859,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
                                  Oid *typeOids,
                                  Oid *collationOids,
                                  Oid *opclassOids,
+                                 Datum *opclassOptions,
                                  int16 *colOptions,
                                  const List *attList,  /* list of IndexElem's */
                                  const List *exclusionOpNames,
@@ -2011,6 +2016,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
                                                 errmsg("including column does not support NULLS FIRST/LAST options")));
 
                        opclassOids[attn] = InvalidOid;
+                       opclassOptions[attn] = (Datum) 0;
                        colOptions[attn] = 0;
                        collationOids[attn] = InvalidOid;
                        attn++;
@@ -2202,14 +2208,12 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
                {
                        Assert(attn < nkeycols);
 
-                       if (!indexInfo->ii_OpclassOptions)
-                               indexInfo->ii_OpclassOptions =
-                                       palloc0_array(Datum, indexInfo->ii_NumIndexAttrs);
-
-                       indexInfo->ii_OpclassOptions[attn] =
+                       opclassOptions[attn] =
                                transformRelOptions((Datum) 0, attribute->opclassopts,
                                                                        NULL, NULL, false, false);
                }
+               else
+                       opclassOptions[attn] = (Datum) 0;
 
                attn++;
        }
index 0e7e6e46d943b79c36825ee0f47fbad6eccd46d1..c6fb5719821966c7b756ffd4256aaa5757c8d906 100644 (file)
@@ -777,9 +777,6 @@ makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
        n->ii_ExclusionProcs = NULL;
        n->ii_ExclusionStrats = NULL;
 
-       /* opclass options */
-       n->ii_OpclassOptions = NULL;
-
        /* speculative inserts */
        n->ii_UniqueOps = NULL;
        n->ii_UniqueProcs = NULL;
index 4d8ba81f90798e9450253007f066e10768871bf3..096e4830ba1c9effc2b3d6bb810b84d9c51f761d 100644 (file)
@@ -78,6 +78,7 @@ extern Oid    index_create(Relation heapRelation,
                                                 Oid tableSpaceId,
                                                 const Oid *collationIds,
                                                 const Oid *opclassIds,
+                                                const Datum *opclassOptions,
                                                 const int16 *coloptions,
                                                 Datum reloptions,
                                                 bits16 flags,
index 869465d6f803a78417ffc325de4cc8c432362903..108d69ba287fe4333f762c773e8cca7a8e2db746 100644 (file)
@@ -187,7 +187,6 @@ typedef struct IndexInfo
        Oid                *ii_UniqueOps;       /* array with one entry per column */
        Oid                *ii_UniqueProcs; /* 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_NullsNotDistinct;
        bool            ii_ReadyForInserts;