From dfa595a003ea237a7431603824b9e5f28c5b20fa Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 16 Aug 2023 07:45:28 +0200 Subject: [PATCH 1/3] Add const decorations in index.c and indexcmds.c and some adjacent places. This especially makes it easier to understand for some complicated function signatures which are the input and the output arguments. --- src/backend/bootstrap/bootstrap.c | 2 +- src/backend/catalog/heap.c | 2 +- src/backend/catalog/index.c | 66 +++++++++++++++---------------- src/backend/catalog/namespace.c | 10 ++--- src/backend/commands/indexcmds.c | 58 +++++++++++++-------------- src/include/bootstrap/bootstrap.h | 2 +- src/include/catalog/heap.h | 2 +- src/include/catalog/index.h | 28 ++++++------- src/include/catalog/namespace.h | 10 ++--- src/include/commands/defrem.h | 8 ++-- 10 files changed, 94 insertions(+), 94 deletions(-) diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 49e956b2c5..4cc2efa95c 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -914,7 +914,7 @@ AllocateAttribute(void) void index_register(Oid heap, Oid ind, - IndexInfo *indexInfo) + const IndexInfo *indexInfo) { IndexList *newind; MemoryContext oldcxt; diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 4c30c7d461..c89b0bfa75 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -697,7 +697,7 @@ void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, - Datum *attoptions, + const Datum *attoptions, CatalogIndexState indstate) { TupleTableSlot **slot; diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index eb2b8d84c3..2a30eb3a32 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -106,20 +106,20 @@ typedef struct /* non-export function prototypes */ static bool relationHasPrimaryKey(Relation rel); static TupleDesc ConstructTupleDescriptor(Relation heapRelation, - IndexInfo *indexInfo, - List *indexColNames, + const IndexInfo *indexInfo, + const List *indexColNames, Oid accessMethodObjectId, - Oid *collationObjectId, - Oid *classObjectId); + const Oid *collationObjectId, + const Oid *classObjectId); static void InitializeAttributeOids(Relation indexRelation, int numatts, Oid indexoid); -static void AppendAttributeTuples(Relation indexRelation, Datum *attopts); +static void AppendAttributeTuples(Relation indexRelation, const Datum *attopts); static void UpdateIndexRelation(Oid indexoid, Oid heapoid, Oid parentIndexId, - IndexInfo *indexInfo, - Oid *collationOids, - Oid *classOids, - int16 *coloptions, + const IndexInfo *indexInfo, + const Oid *collationOids, + const Oid *classOids, + const int16 *coloptions, bool primary, bool isexclusion, bool immediate, @@ -205,9 +205,9 @@ relationHasPrimaryKey(Relation rel) */ void index_check_primary_key(Relation heapRel, - IndexInfo *indexInfo, + const IndexInfo *indexInfo, bool is_alter_table, - IndexStmt *stmt) + const IndexStmt *stmt) { int i; @@ -284,11 +284,11 @@ index_check_primary_key(Relation heapRel, */ static TupleDesc ConstructTupleDescriptor(Relation heapRelation, - IndexInfo *indexInfo, - List *indexColNames, + const IndexInfo *indexInfo, + const List *indexColNames, Oid accessMethodObjectId, - Oid *collationObjectId, - Oid *classObjectId) + const Oid *collationObjectId, + const Oid *classObjectId) { int numatts = indexInfo->ii_NumIndexAttrs; int numkeyatts = indexInfo->ii_NumIndexKeyAttrs; @@ -516,7 +516,7 @@ InitializeAttributeOids(Relation indexRelation, * ---------------------------------------------------------------- */ static void -AppendAttributeTuples(Relation indexRelation, Datum *attopts) +AppendAttributeTuples(Relation indexRelation, const Datum *attopts) { Relation pg_attribute; CatalogIndexState indstate; @@ -551,10 +551,10 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid, Oid parentIndexId, - IndexInfo *indexInfo, - Oid *collationOids, - Oid *classOids, - int16 *coloptions, + const IndexInfo *indexInfo, + const Oid *collationOids, + const Oid *classOids, + const int16 *coloptions, bool primary, bool isexclusion, bool immediate, @@ -718,12 +718,12 @@ index_create(Relation heapRelation, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, - List *indexColNames, + const List *indexColNames, Oid accessMethodObjectId, Oid tableSpaceId, - Oid *collationObjectId, - Oid *classObjectId, - int16 *coloptions, + const Oid *collationObjectId, + const Oid *classObjectId, + const int16 *coloptions, Datum reloptions, bits16 flags, bits16 constr_flags, @@ -1908,7 +1908,7 @@ ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, - IndexInfo *indexInfo, + const IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, @@ -2537,10 +2537,10 @@ BuildDummyIndexInfo(Relation index) * Use build_attrmap_by_name(index2, index1) to build the attmap. */ bool -CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, - Oid *collations1, Oid *collations2, - Oid *opfamilies1, Oid *opfamilies2, - AttrMap *attmap) +CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, + const Oid *collations1, const Oid *collations2, + const Oid *opfamilies1, const Oid *opfamilies2, + const AttrMap *attmap) { int i; @@ -3559,7 +3559,7 @@ IndexGetRelation(Oid indexId, bool missing_ok) */ void reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, - ReindexParams *params) + const ReindexParams *params) { Relation iRel, heapRelation; @@ -3872,7 +3872,7 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, * index rebuild. */ bool -reindex_relation(Oid relid, int flags, ReindexParams *params) +reindex_relation(Oid relid, int flags, const ReindexParams *params) { Relation rel; Oid toast_relid; @@ -4177,9 +4177,9 @@ SerializeReindexState(Size maxsize, char *start_address) * Restore reindex state in a parallel worker. */ void -RestoreReindexState(void *reindexstate) +RestoreReindexState(const void *reindexstate) { - SerializedReindexState *sistate = (SerializedReindexState *) reindexstate; + const SerializedReindexState *sistate = (const SerializedReindexState *) reindexstate; int c = 0; MemoryContext oldcontext; diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 0c679fbf94..4ceae038ec 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -2831,7 +2831,7 @@ TSConfigIsVisible(Oid cfgid) * *nspname_p is set to NULL if there is no explicit schema name. */ void -DeconstructQualifiedName(List *names, +DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p) { @@ -3017,7 +3017,7 @@ CheckSetNamespace(Oid oldNspOid, Oid nspOid) * if we have to create or clean out the temp namespace. */ Oid -QualifiedNameGetCreationNamespace(List *names, char **objname_p) +QualifiedNameGetCreationNamespace(const List *names, char **objname_p) { char *schemaname; Oid namespaceId; @@ -3084,7 +3084,7 @@ get_namespace_oid(const char *nspname, bool missing_ok) * Utility routine to convert a qualified-name list into RangeVar form. */ RangeVar * -makeRangeVarFromNameList(List *names) +makeRangeVarFromNameList(const List *names) { RangeVar *rel = makeRangeVar(NULL, NULL, -1); @@ -3124,7 +3124,7 @@ makeRangeVarFromNameList(List *names) * but we also allow A_Star for the convenience of ColumnRef processing. */ char * -NameListToString(List *names) +NameListToString(const List *names) { StringInfoData string; ListCell *l; @@ -3158,7 +3158,7 @@ NameListToString(List *names) * so the string could be re-parsed (eg, by textToQualifiedNameList). */ char * -NameListToQuotedString(List *names) +NameListToQuotedString(const List *names) { StringInfoData string; ListCell *l; diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index baf3e6e57a..8e707d4ad9 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -71,15 +71,15 @@ /* non-export function prototypes */ -static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts); +static bool CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts); static void CheckPredicate(Expr *predicate); static void ComputeIndexAttrs(IndexInfo *indexInfo, Oid *typeOidP, Oid *collationOidP, Oid *classOidP, int16 *colOptionP, - List *attList, - List *exclusionOpNames, + const List *attList, + const List *exclusionOpNames, Oid relId, const char *accessMethodName, Oid accessMethodId, bool amcanorder, @@ -88,25 +88,25 @@ static void ComputeIndexAttrs(IndexInfo *indexInfo, int ddl_sec_context, int *ddl_save_nestlevel); static char *ChooseIndexName(const char *tabname, Oid namespaceId, - List *colnames, List *exclusionOpNames, + const List *colnames, const List *exclusionOpNames, bool primary, bool isconstraint); -static char *ChooseIndexNameAddition(List *colnames); -static List *ChooseIndexColumnNames(List *indexElems); -static void ReindexIndex(RangeVar *indexRelation, ReindexParams *params, +static char *ChooseIndexNameAddition(const List *colnames); +static List *ChooseIndexColumnNames(const List *indexElems); +static void ReindexIndex(const RangeVar *indexRelation, const ReindexParams *params, bool isTopLevel); static void RangeVarCallbackForReindexIndex(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg); -static Oid ReindexTable(RangeVar *relation, ReindexParams *params, +static Oid ReindexTable(const RangeVar *relation, const ReindexParams *params, bool isTopLevel); static void ReindexMultipleTables(const char *objectName, - ReindexObjectType objectKind, ReindexParams *params); + ReindexObjectType objectKind, const ReindexParams *params); static void reindex_error_callback(void *arg); -static void ReindexPartitions(Oid relid, ReindexParams *params, +static void ReindexPartitions(Oid relid, const ReindexParams *params, bool isTopLevel); -static void ReindexMultipleInternal(List *relids, - ReindexParams *params); +static void ReindexMultipleInternal(const List *relids, + const ReindexParams *params); static bool ReindexRelationConcurrently(Oid relationOid, - ReindexParams *params); + const ReindexParams *params); static void update_relispartition(Oid relationId, bool newval); static inline void set_indexsafe_procflags(void); @@ -169,8 +169,8 @@ typedef struct ReindexErrorInfo bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, - List *attributeList, - List *exclusionOpNames) + const List *attributeList, + const List *exclusionOpNames) { bool isconstraint; Oid *typeObjectId; @@ -349,7 +349,7 @@ CheckIndexCompatible(Oid oldId, * datums. Both elements of arrays and array themselves can be NULL. */ static bool -CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts) +CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts) { int i; @@ -1859,8 +1859,8 @@ ComputeIndexAttrs(IndexInfo *indexInfo, Oid *collationOidP, Oid *classOidP, int16 *colOptionP, - List *attList, /* list of IndexElem's */ - List *exclusionOpNames, + const List *attList, /* list of IndexElem's */ + const List *exclusionOpNames, Oid relId, const char *accessMethodName, Oid accessMethodId, @@ -2225,7 +2225,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo, * partition key definitions. */ Oid -ResolveOpClass(List *opclass, Oid attrType, +ResolveOpClass(const List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId) { char *schemaname; @@ -2542,7 +2542,7 @@ ChooseRelationName(const char *name1, const char *name2, */ static char * ChooseIndexName(const char *tabname, Oid namespaceId, - List *colnames, List *exclusionOpNames, + const List *colnames, const List *exclusionOpNames, bool primary, bool isconstraint) { char *indexname; @@ -2596,7 +2596,7 @@ ChooseIndexName(const char *tabname, Oid namespaceId, * ChooseExtendedStatisticNameAddition. */ static char * -ChooseIndexNameAddition(List *colnames) +ChooseIndexNameAddition(const List *colnames) { char buf[NAMEDATALEN * 2]; int buflen = 0; @@ -2630,7 +2630,7 @@ ChooseIndexNameAddition(List *colnames) * Returns a List of plain strings (char *, not String nodes). */ static List * -ChooseIndexColumnNames(List *indexElems) +ChooseIndexColumnNames(const List *indexElems) { List *result = NIL; ListCell *lc; @@ -2691,7 +2691,7 @@ ChooseIndexColumnNames(List *indexElems) * each subroutine of REINDEX. */ void -ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel) +ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel) { ReindexParams params = {0}; ListCell *lc; @@ -2786,7 +2786,7 @@ ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel) * Recreate a specific index. */ static void -ReindexIndex(RangeVar *indexRelation, ReindexParams *params, bool isTopLevel) +ReindexIndex(const RangeVar *indexRelation, const ReindexParams *params, bool isTopLevel) { struct ReindexIndexCallbackState state; Oid indOid; @@ -2909,7 +2909,7 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation, * Recreate all indexes of a table (and of its toast table, if any) */ static Oid -ReindexTable(RangeVar *relation, ReindexParams *params, bool isTopLevel) +ReindexTable(const RangeVar *relation, const ReindexParams *params, bool isTopLevel) { Oid heapOid; bool result; @@ -2968,7 +2968,7 @@ ReindexTable(RangeVar *relation, ReindexParams *params, bool isTopLevel) */ static void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, - ReindexParams *params) + const ReindexParams *params) { Oid objectOid; Relation relationRelation; @@ -3206,7 +3206,7 @@ reindex_error_callback(void *arg) * by the caller. */ static void -ReindexPartitions(Oid relid, ReindexParams *params, bool isTopLevel) +ReindexPartitions(Oid relid, const ReindexParams *params, bool isTopLevel) { List *partitions = NIL; char relkind = get_rel_relkind(relid); @@ -3300,7 +3300,7 @@ ReindexPartitions(Oid relid, ReindexParams *params, bool isTopLevel) * and starts a new transaction when finished. */ static void -ReindexMultipleInternal(List *relids, ReindexParams *params) +ReindexMultipleInternal(const List *relids, const ReindexParams *params) { ListCell *l; @@ -3424,7 +3424,7 @@ ReindexMultipleInternal(List *relids, ReindexParams *params) * anyway, and a non-concurrent reindex is more efficient. */ static bool -ReindexRelationConcurrently(Oid relationOid, ReindexParams *params) +ReindexRelationConcurrently(Oid relationOid, const ReindexParams *params) { typedef struct ReindexIndexInfo { diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h index 2c28a52ce7..e1cb73c5f2 100644 --- a/src/include/bootstrap/bootstrap.h +++ b/src/include/bootstrap/bootstrap.h @@ -42,7 +42,7 @@ extern void InsertOneTuple(void); extern void InsertOneValue(char *value, int i); extern void InsertOneNull(int i); -extern void index_register(Oid heap, Oid ind, IndexInfo *indexInfo); +extern void index_register(Oid heap, Oid ind, const IndexInfo *indexInfo); extern void build_indices(void); extern void boot_get_type_io_data(Oid typid, diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index d01ab504b6..c472ee1365 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -97,7 +97,7 @@ extern List *heap_truncate_find_FKs(List *relationIds); extern void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, - Datum *attoptions, + const Datum *attoptions, CatalogIndexState indstate); extern void InsertPgClassTuple(Relation pg_class_desc, diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index c8532fb97c..72ac2dc1b1 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -54,9 +54,9 @@ typedef struct ValidateIndexState } ValidateIndexState; extern void index_check_primary_key(Relation heapRel, - IndexInfo *indexInfo, + const IndexInfo *indexInfo, bool is_alter_table, - IndexStmt *stmt); + const IndexStmt *stmt); #define INDEX_CREATE_IS_PRIMARY (1 << 0) #define INDEX_CREATE_ADD_CONSTRAINT (1 << 1) @@ -73,12 +73,12 @@ extern Oid index_create(Relation heapRelation, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, - List *indexColNames, + const List *indexColNames, Oid accessMethodObjectId, Oid tableSpaceId, - Oid *collationObjectId, - Oid *classObjectId, - int16 *coloptions, + const Oid *collationObjectId, + const Oid *classObjectId, + const int16 *coloptions, Datum reloptions, bits16 flags, bits16 constr_flags, @@ -110,7 +110,7 @@ extern void index_concurrently_set_dead(Oid heapId, extern ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, - IndexInfo *indexInfo, + const IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, @@ -123,10 +123,10 @@ extern IndexInfo *BuildIndexInfo(Relation index); extern IndexInfo *BuildDummyIndexInfo(Relation index); -extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, - Oid *collations1, Oid *collations2, - Oid *opfamilies1, Oid *opfamilies2, - AttrMap *attmap); +extern bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, + const Oid *collations1, const Oid *collations2, + const Oid *opfamilies1, const Oid *opfamilies2, + const AttrMap *attmap); extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii); @@ -149,7 +149,7 @@ extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action); extern Oid IndexGetRelation(Oid indexId, bool missing_ok); extern void reindex_index(Oid indexId, bool skip_constraint_checks, - char persistence, ReindexParams *params); + char persistence, const ReindexParams *params); /* Flag bits for reindex_relation(): */ #define REINDEX_REL_PROCESS_TOAST 0x01 @@ -158,7 +158,7 @@ extern void reindex_index(Oid indexId, bool skip_constraint_checks, #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10 -extern bool reindex_relation(Oid relid, int flags, ReindexParams *params); +extern bool reindex_relation(Oid relid, int flags, const ReindexParams *params); extern bool ReindexIsProcessingHeap(Oid heapOid); extern bool ReindexIsProcessingIndex(Oid indexOid); @@ -166,7 +166,7 @@ extern bool ReindexIsProcessingIndex(Oid indexOid); extern void ResetReindexState(int nestLevel); extern Size EstimateReindexStateSpace(void); extern void SerializeReindexState(Size maxsize, char *start_address); -extern void RestoreReindexState(void *reindexstate); +extern void RestoreReindexState(const void *reindexstate); extern void IndexSetParentIndex(Relation partitionIdx, Oid parentOid); diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h index 49ef619e4b..e027940430 100644 --- a/src/include/catalog/namespace.h +++ b/src/include/catalog/namespace.h @@ -136,7 +136,7 @@ extern bool TSTemplateIsVisible(Oid tmplId); extern Oid get_ts_config_oid(List *names, bool missing_ok); extern bool TSConfigIsVisible(Oid cfgid); -extern void DeconstructQualifiedName(List *names, +extern void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p); extern Oid LookupNamespaceNoError(const char *nspname); @@ -145,10 +145,10 @@ extern Oid get_namespace_oid(const char *nspname, bool missing_ok); extern Oid LookupCreationNamespace(const char *nspname); extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid); -extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p); -extern RangeVar *makeRangeVarFromNameList(List *names); -extern char *NameListToString(List *names); -extern char *NameListToQuotedString(List *names); +extern Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p); +extern RangeVar *makeRangeVarFromNameList(const List *names); +extern char *NameListToString(const List *names); +extern char *NameListToQuotedString(const List *names); extern bool isTempNamespace(Oid namespaceId); extern bool isTempToastNamespace(Oid namespaceId); diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index 478203ed4c..190040d463 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -35,7 +35,7 @@ extern ObjectAddress DefineIndex(Oid relationId, bool check_not_in_use, bool skip_build, bool quiet); -extern void ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel); +extern void ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel); extern char *makeObjectName(const char *name1, const char *name2, const char *label); extern char *ChooseRelationName(const char *name1, const char *name2, @@ -43,10 +43,10 @@ extern char *ChooseRelationName(const char *name1, const char *name2, bool isconstraint); extern bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, - List *attributeList, - List *exclusionOpNames); + const List *attributeList, + const List *exclusionOpNames); extern Oid GetDefaultOpClass(Oid type_id, Oid am_id); -extern Oid ResolveOpClass(List *opclass, Oid attrType, +extern Oid ResolveOpClass(const List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId); /* commands/functioncmds.c */ -- 2.41.0