0001-Remove-IndexInfo.ii_OpclassOptions-field.patch

text/plain

Filename: 0001-Remove-IndexInfo.ii_OpclassOptions-field.patch
Type: text/plain
Part: 0
Message: Remove IndexInfo.ii_OpclassOptions field

Patch

Format: format-patch
Series: patch 0001
Subject: Remove IndexInfo.ii_OpclassOptions field
File+
src/backend/catalog/index.c 14 17
src/backend/catalog/toasting.c 1 2
src/backend/commands/indexcmds.c 17 13
src/backend/nodes/makefuncs.c 0 3
src/include/catalog/index.h 1 0
src/include/nodes/execnodes.h 0 1
From f8b629052e75835ab255bfa4e1ce6ada570fa9e2 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 24 Aug 2023 08:26:13 +0200
Subject: [PATCH 1/3] 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.
---
 src/backend/catalog/index.c      | 31 ++++++++++++++-----------------
 src/backend/catalog/toasting.c   |  3 +--
 src/backend/commands/indexcmds.c | 30 +++++++++++++++++-------------
 src/backend/nodes/makefuncs.c    |  3 ---
 src/include/catalog/index.h      |  1 +
 src/include/nodes/execnodes.h    |  1 -
 6 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index fd09378848..9b0cbd8979 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -721,6 +721,7 @@ index_create(Relation heapRelation,
 			 Oid tableSpaceId,
 			 const Oid *collationIds,
 			 const Oid *opclassIds,
+			 const Datum *opclassOptions,
 			 const int16 *coloptions,
 			 Datum reloptions,
 			 bits16 flags,
@@ -1016,7 +1017,7 @@ index_create(Relation heapRelation,
 	/*
 	 * append ATTRIBUTE tuples for the index
 	 */
-	AppendAttributeTuples(indexRelation, indexInfo->ii_OpclassOptions);
+	AppendAttributeTuples(indexRelation, opclassOptions);
 
 	/* ----------------
 	 *	  update pg_index
@@ -1224,10 +1225,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);
 
 	/*
@@ -1291,7 +1292,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
 				classTuple;
 	Datum		indclassDatum,
 				colOptionDatum,
-				optionDatum;
+				reloptionsDatum;
+	Datum	   *opclassOptions;
 	oidvector  *indclass;
 	int2vector *indcoloptions;
 	bool		isnull;
@@ -1325,11 +1327,11 @@ 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,
+	reloptionsDatum = SysCacheGetAttr(RELOID, classTuple,
 								  Anum_pg_class_reloptions, &isnull);
 
 	/*
@@ -1393,14 +1395,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.
@@ -1421,8 +1419,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? */
@@ -2465,8 +2464,6 @@ BuildIndexInfo(Relation index)
 								 &ii->ii_ExclusionStrats);
 	}
 
-	ii->ii_OpclassOptions = RelationGetIndexRawAttOptions(index);
-
 	return ii;
 }
 
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index 3fef593bf1..989f820791 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -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);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index ab8b81b302..a53861cecf 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -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++;
 	}
diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c
index 0e7e6e46d9..c6fb571982 100644
--- a/src/backend/nodes/makefuncs.c
+++ b/src/backend/nodes/makefuncs.c
@@ -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;
diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h
index 4d8ba81f90..096e4830ba 100644
--- a/src/include/catalog/index.h
+++ b/src/include/catalog/index.h
@@ -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,
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index cb714f4a19..8b65deeea9 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -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;
-- 
2.41.0