From 2b456217c69eb0877d4b66b0472933e263daf5e2 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Sat, 31 Jan 2026 13:58:34 +0100 Subject: [PATCH v1 1/5] Mark constant opclass-related fields const in RelationData This enables future sharing of these fields across indexes that have the same opclasses. rd_supportinfo is dynamically filled with data, and so isn't marked const. --- src/backend/access/index/indexam.c | 4 ++-- src/backend/utils/cache/relcache.c | 17 +++++++++++------ src/include/utils/rel.h | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index 7967e939847..0bd0dd9a2f3 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -852,7 +852,7 @@ index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum) { - RegProcedure *loc; + const RegProcedure *loc; int nproc; int procindex; @@ -907,7 +907,7 @@ index_getprocinfo(Relation irel, /* Initialize the lookup info if first time through */ if (locinfo->fn_oid == InvalidOid) { - RegProcedure *loc = irel->rd_support; + const RegProcedure *loc = irel->rd_support; RegProcedure procId; Assert(loc != NULL); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index f475d703977..0ff4c049634 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1451,6 +1451,9 @@ RelationInitIndexAccessInfo(Relation relation) int indnatts; int indnkeyatts; uint16 amsupport; + Oid *opfamily; + Oid *opcintype; + RegProcedure *support; /* * Make a copy of the pg_index entry for the index. Since pg_index @@ -1507,9 +1510,9 @@ RelationInitIndexAccessInfo(Relation relation) * Allocate arrays to hold data. Opclasses are not used for included * columns, so allocate them for indnkeyatts only. */ - relation->rd_opfamily = (Oid *) + opfamily = (Oid *) MemoryContextAllocZero(indexcxt, indnkeyatts * sizeof(Oid)); - relation->rd_opcintype = (Oid *) + opcintype = (Oid *) MemoryContextAllocZero(indexcxt, indnkeyatts * sizeof(Oid)); amsupport = relation->rd_indam->amsupport; @@ -1517,14 +1520,14 @@ RelationInitIndexAccessInfo(Relation relation) { int nsupport = indnatts * amsupport; - relation->rd_support = (RegProcedure *) + support = (RegProcedure *) MemoryContextAllocZero(indexcxt, nsupport * sizeof(RegProcedure)); relation->rd_supportinfo = (FmgrInfo *) MemoryContextAllocZero(indexcxt, nsupport * sizeof(FmgrInfo)); } else { - relation->rd_support = NULL; + support = NULL; relation->rd_supportinfo = NULL; } @@ -1564,10 +1567,12 @@ RelationInitIndexAccessInfo(Relation relation) * opfamilies and opclass input types. (aminfo and supportinfo are left * as zeroes, and are filled on-the-fly when used) */ - IndexSupportInitialize(indclass, relation->rd_support, - relation->rd_opfamily, relation->rd_opcintype, + IndexSupportInitialize(indclass, support, opfamily, opcintype, amsupport, indnkeyatts); + relation->rd_opfamily = opfamily; + relation->rd_opcintype = opcintype; + relation->rd_support = support; /* * Similarly extract indoption and copy it to the cache entry */ diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 41ab4586c6b..78e052bf34b 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -204,9 +204,9 @@ typedef struct RelationData MemoryContext rd_indexcxt; /* private memory cxt for this stuff */ /* use "struct" here to avoid needing to include amapi.h: */ const struct IndexAmRoutine *rd_indam; /* index AM's API struct */ - Oid *rd_opfamily; /* OIDs of op families for each index col */ - Oid *rd_opcintype; /* OIDs of opclass declared input data types */ - RegProcedure *rd_support; /* OIDs of support procedures */ + const Oid *rd_opfamily; /* OIDs of op families for each index col */ + const Oid *rd_opcintype; /* OIDs of opclass declared input data types */ + const RegProcedure *rd_support; /* OIDs of support procedures */ struct FmgrInfo *rd_supportinfo; /* lookup info for support procedures */ int16 *rd_indoption; /* per-column AM-specific flags */ List *rd_indexprs; /* index expression trees, if any */ -- 2.50.1 (Apple Git-155)