There are a lot of Datum *values, bool *nulls argument pairs that should really be const. The 0001 patch makes those changes. Some of these hunks depend on each other.

The 0002 patch, which I'm not proposing to commit at this time, makes similar changes but in a way that breaks the table and index AM APIs. So I'm just including that here in case anyone wonders, why didn't you touch those. And also maybe if we ever change that API incompatibly we could throw this one in then.
From ee393652d792b7ac11017ad9ebf0c9331c50c27c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Fri, 6 Oct 2023 14:57:56 +0200
Subject: [PATCH 1/2] Add const to values and nulls arguments

This excludes any changes that would change the external AM APIs.
---
 src/backend/access/brin/brin.c             |  4 ++--
 src/backend/access/common/heaptuple.c      | 26 +++++++++++-----------
 src/backend/access/common/indextuple.c     | 12 +++++-----
 src/backend/access/gist/gistutil.c         |  4 ++--
 src/backend/access/hash/hashsort.c         |  2 +-
 src/backend/access/index/genam.c           |  2 +-
 src/backend/access/spgist/spgutils.c       |  4 ++--
 src/backend/access/table/toast_helper.c    |  2 +-
 src/backend/executor/execIndexing.c        | 18 +++++++--------
 src/backend/executor/execTuples.c          |  2 +-
 src/backend/partitioning/partbounds.c      |  4 ++--
 src/backend/utils/adt/json.c               |  4 ++--
 src/backend/utils/adt/jsonb.c              | 10 ++++-----
 src/backend/utils/sort/tuplesortvariants.c |  4 ++--
 src/backend/utils/sort/tuplestore.c        |  2 +-
 src/include/access/genam.h                 |  2 +-
 src/include/access/gist_private.h          |  4 ++--
 src/include/access/hash.h                  |  2 +-
 src/include/access/htup_details.h          | 20 ++++++++---------
 src/include/access/itup.h                  |  4 ++--
 src/include/access/spgist_private.h        |  4 ++--
 src/include/access/toast_helper.h          |  2 +-
 src/include/executor/executor.h            |  4 ++--
 src/include/partitioning/partbounds.h      |  4 ++--
 src/include/utils/json.h                   |  8 +++----
 src/include/utils/jsonb.h                  |  8 +++----
 src/include/utils/tuplesort.h              |  2 +-
 src/include/utils/tuplestore.h             |  2 +-
 28 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index a7538f32c2..af392bc032 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -80,7 +80,7 @@ static void union_tuples(BrinDesc *bdesc, BrinMemTuple *a,
                                                 BrinTuple *b);
 static void brin_vacuum_scan(Relation idxrel, BufferAccessStrategy strategy);
 static bool add_values_to_range(Relation idxRel, BrinDesc *bdesc,
-                                                               BrinMemTuple 
*dtup, Datum *values, bool *nulls);
+                                                               BrinMemTuple 
*dtup, const Datum *values, const bool *nulls);
 static bool check_null_keys(BrinValues *bval, ScanKey *nullkeys, int 
nnullkeys);
 
 /*
@@ -1774,7 +1774,7 @@ brin_vacuum_scan(Relation idxrel, BufferAccessStrategy 
strategy)
 
 static bool
 add_values_to_range(Relation idxRel, BrinDesc *bdesc, BrinMemTuple *dtup,
-                                       Datum *values, bool *nulls)
+                                       const Datum *values, const bool *nulls)
 {
        int                     keyno;
 
diff --git a/src/backend/access/common/heaptuple.c 
b/src/backend/access/common/heaptuple.c
index ef246c901e..d6a4ddfd51 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -205,8 +205,8 @@ getmissingattr(TupleDesc tupleDesc,
  */
 Size
 heap_compute_data_size(TupleDesc tupleDesc,
-                                          Datum *values,
-                                          bool *isnull)
+                                          const Datum *values,
+                                          const bool *isnull)
 {
        Size            data_length = 0;
        int                     i;
@@ -390,7 +390,7 @@ fill_val(Form_pg_attribute att,
  */
 void
 heap_fill_tuple(TupleDesc tupleDesc,
-                               Datum *values, bool *isnull,
+                               const Datum *values, const bool *isnull,
                                char *data, Size data_size,
                                uint16 *infomask, bits8 *bit)
 {
@@ -1106,8 +1106,8 @@ heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc 
tupleDesc)
  */
 HeapTuple
 heap_form_tuple(TupleDesc tupleDescriptor,
-                               Datum *values,
-                               bool *isnull)
+                               const Datum *values,
+                               const bool *isnull)
 {
        HeapTuple       tuple;                  /* return tuple */
        HeapTupleHeader td;                     /* tuple data */
@@ -1200,9 +1200,9 @@ heap_form_tuple(TupleDesc tupleDescriptor,
 HeapTuple
 heap_modify_tuple(HeapTuple tuple,
                                  TupleDesc tupleDesc,
-                                 Datum *replValues,
-                                 bool *replIsnull,
-                                 bool *doReplace)
+                                 const Datum *replValues,
+                                 const bool *replIsnull,
+                                 const bool *doReplace)
 {
        int                     numberOfAttributes = tupleDesc->natts;
        int                     attoff;
@@ -1269,9 +1269,9 @@ HeapTuple
 heap_modify_tuple_by_cols(HeapTuple tuple,
                                                  TupleDesc tupleDesc,
                                                  int nCols,
-                                                 int *replCols,
-                                                 Datum *replValues,
-                                                 bool *replIsnull)
+                                                 const int *replCols,
+                                                 const Datum *replValues,
+                                                 const bool *replIsnull)
 {
        int                     numberOfAttributes = tupleDesc->natts;
        Datum      *values;
@@ -1442,8 +1442,8 @@ heap_freetuple(HeapTuple htup)
  */
 MinimalTuple
 heap_form_minimal_tuple(TupleDesc tupleDescriptor,
-                                               Datum *values,
-                                               bool *isnull)
+                                               const Datum *values,
+                                               const bool *isnull)
 {
        MinimalTuple tuple;                     /* return tuple */
        Size            len,
diff --git a/src/backend/access/common/indextuple.c 
b/src/backend/access/common/indextuple.c
index 8b178f94c1..9e9f87b134 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -42,8 +42,8 @@
   */
 IndexTuple
 index_form_tuple(TupleDesc tupleDescriptor,
-                                Datum *values,
-                                bool *isnull)
+                                const Datum *values,
+                                const bool *isnull)
 {
        return index_form_tuple_context(tupleDescriptor, values, isnull,
                                                                        
CurrentMemoryContext);
@@ -63,8 +63,8 @@ index_form_tuple(TupleDesc tupleDescriptor,
  */
 IndexTuple
 index_form_tuple_context(TupleDesc tupleDescriptor,
-                                                Datum *values,
-                                                bool *isnull,
+                                                const Datum *values,
+                                                const bool *isnull,
                                                 MemoryContext context)
 {
        char       *tp;                         /* tuple pointer */
@@ -79,8 +79,8 @@ index_form_tuple_context(TupleDesc tupleDescriptor,
        int                     numberOfAttributes = tupleDescriptor->natts;
 
 #ifdef TOAST_INDEX_HACK
-       Datum           untoasted_values[INDEX_MAX_KEYS];
-       bool            untoasted_free[INDEX_MAX_KEYS];
+       Datum           untoasted_values[INDEX_MAX_KEYS] = {0};
+       bool            untoasted_free[INDEX_MAX_KEYS] = {0};
 #endif
 
        if (numberOfAttributes > INDEX_MAX_KEYS)
diff --git a/src/backend/access/gist/gistutil.c 
b/src/backend/access/gist/gistutil.c
index b6bc8c2c56..9ce3687dbf 100644
--- a/src/backend/access/gist/gistutil.c
+++ b/src/backend/access/gist/gistutil.c
@@ -573,7 +573,7 @@ gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e,
 
 IndexTuple
 gistFormTuple(GISTSTATE *giststate, Relation r,
-                         Datum *attdata, bool *isnull, bool isleaf)
+                         const Datum *attdata, const bool *isnull, bool isleaf)
 {
        Datum           compatt[INDEX_MAX_KEYS];
        IndexTuple      res;
@@ -594,7 +594,7 @@ gistFormTuple(GISTSTATE *giststate, Relation r,
 
 void
 gistCompressValues(GISTSTATE *giststate, Relation r,
-                                  Datum *attdata, bool *isnull, bool isleaf, 
Datum *compatt)
+                                  const Datum *attdata, const bool *isnull, 
bool isleaf, Datum *compatt)
 {
        int                     i;
 
diff --git a/src/backend/access/hash/hashsort.c 
b/src/backend/access/hash/hashsort.c
index b67b2207c0..e7c3ab10e4 100644
--- a/src/backend/access/hash/hashsort.c
+++ b/src/backend/access/hash/hashsort.c
@@ -106,7 +106,7 @@ _h_spooldestroy(HSpool *hspool)
  * spool an index entry into the sort file.
  */
 void
-_h_spool(HSpool *hspool, ItemPointer self, Datum *values, bool *isnull)
+_h_spool(HSpool *hspool, ItemPointer self, const Datum *values, const bool 
*isnull)
 {
        tuplesort_putindextuplevalues(hspool->sortstate, hspool->index,
                                                                  self, values, 
isnull);
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 722927aeba..4ca1200684 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -175,7 +175,7 @@ IndexScanEnd(IndexScanDesc scan)
  */
 char *
 BuildIndexValueDescription(Relation indexRelation,
-                                                  Datum *values, bool *isnull)
+                                                  const Datum *values, const 
bool *isnull)
 {
        StringInfoData buf;
        Form_pg_index idxrec;
diff --git a/src/backend/access/spgist/spgutils.c 
b/src/backend/access/spgist/spgutils.c
index 8f32e46fb8..c112e1e5dd 100644
--- a/src/backend/access/spgist/spgutils.c
+++ b/src/backend/access/spgist/spgutils.c
@@ -788,7 +788,7 @@ memcpyInnerDatum(void *target, SpGistTypeDesc *att, Datum 
datum)
  */
 Size
 SpGistGetLeafTupleSize(TupleDesc tupleDescriptor,
-                                          Datum *datums, bool *isnulls)
+                                          const Datum *datums, const bool 
*isnulls)
 {
        Size            size;
        Size            data_size;
@@ -841,7 +841,7 @@ SpGistGetLeafTupleSize(TupleDesc tupleDescriptor,
  */
 SpGistLeafTuple
 spgFormLeafTuple(SpGistState *state, ItemPointer heapPtr,
-                                Datum *datums, bool *isnulls)
+                                const Datum *datums, const bool *isnulls)
 {
        SpGistLeafTuple tup;
        TupleDesc       tupleDescriptor = state->leafTupDesc;
diff --git a/src/backend/access/table/toast_helper.c 
b/src/backend/access/table/toast_helper.c
index b5cfeb21aa..871ebeeb56 100644
--- a/src/backend/access/table/toast_helper.c
+++ b/src/backend/access/table/toast_helper.c
@@ -316,7 +316,7 @@ toast_tuple_cleanup(ToastTupleContext *ttc)
  * relation.
  */
 void
-toast_delete_external(Relation rel, Datum *values, bool *isnull,
+toast_delete_external(Relation rel, const Datum *values, const bool *isnull,
                                          bool is_speculative)
 {
        TupleDesc       tupleDesc = rel->rd_att;
diff --git a/src/backend/executor/execIndexing.c 
b/src/backend/executor/execIndexing.c
index 1d82b64b89..3c6730632d 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -127,15 +127,15 @@ typedef enum
 static bool check_exclusion_or_unique_constraint(Relation heap, Relation index,
                                                                                
                 IndexInfo *indexInfo,
                                                                                
                 ItemPointer tupleid,
-                                                                               
                 Datum *values, bool *isnull,
+                                                                               
                 const Datum *values, const bool *isnull,
                                                                                
                 EState *estate, bool newIndex,
                                                                                
                 CEOUC_WAIT_MODE waitMode,
                                                                                
                 bool violationOK,
                                                                                
                 ItemPointer conflictTid);
 
-static bool index_recheck_constraint(Relation index, Oid *constr_procs,
-                                                                        Datum 
*existing_values, bool *existing_isnull,
-                                                                        Datum 
*new_values);
+static bool index_recheck_constraint(Relation index, const Oid *constr_procs,
+                                                                        const 
Datum *existing_values, const bool *existing_isnull,
+                                                                        const 
Datum *new_values);
 static bool index_unchanged_by_update(ResultRelInfo *resultRelInfo,
                                                                          
EState *estate, IndexInfo *indexInfo,
                                                                          
Relation indexRelation);
@@ -684,7 +684,7 @@ static bool
 check_exclusion_or_unique_constraint(Relation heap, Relation index,
                                                                         
IndexInfo *indexInfo,
                                                                         
ItemPointer tupleid,
-                                                                        Datum 
*values, bool *isnull,
+                                                                        const 
Datum *values, const bool *isnull,
                                                                         EState 
*estate, bool newIndex,
                                                                         
CEOUC_WAIT_MODE waitMode,
                                                                         bool 
violationOK,
@@ -910,7 +910,7 @@ void
 check_exclusion_constraint(Relation heap, Relation index,
                                                   IndexInfo *indexInfo,
                                                   ItemPointer tupleid,
-                                                  Datum *values, bool *isnull,
+                                                  const Datum *values, const 
bool *isnull,
                                                   EState *estate, bool 
newIndex)
 {
        (void) check_exclusion_or_unique_constraint(heap, index, indexInfo, 
tupleid,
@@ -924,9 +924,9 @@ check_exclusion_constraint(Relation heap, Relation index,
  * exclusion condition against the new_values.  Returns true if conflict.
  */
 static bool
-index_recheck_constraint(Relation index, Oid *constr_procs,
-                                                Datum *existing_values, bool 
*existing_isnull,
-                                                Datum *new_values)
+index_recheck_constraint(Relation index, const Oid *constr_procs,
+                                                const Datum *existing_values, 
const bool *existing_isnull,
+                                                const Datum *new_values)
 {
        int                     indnkeyatts = 
IndexRelationGetNumberOfKeyAttributes(index);
        int                     i;
diff --git a/src/backend/executor/execTuples.c 
b/src/backend/executor/execTuples.c
index fda20ec318..2c2712ceac 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -2273,7 +2273,7 @@ begin_tup_output_tupdesc(DestReceiver *dest,
  * write a single tuple
  */
 void
-do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
+do_tup_output(TupOutputState *tstate, const Datum *values, const bool *isnull)
 {
        TupleTableSlot *slot = tstate->slot;
        int                     natts = slot->tts_tupleDescriptor->natts;
diff --git a/src/backend/partitioning/partbounds.c 
b/src/backend/partitioning/partbounds.c
index 5436cc302d..9f207b44c3 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -4720,8 +4720,8 @@ get_range_nulltest(PartitionKey key)
  * Compute the hash value for given partition key values.
  */
 uint64
-compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc, Oid 
*partcollation,
-                                                        Datum *values, bool 
*isnull)
+compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc, const Oid 
*partcollation,
+                                                        const Datum *values, 
const bool *isnull)
 {
        int                     i;
        uint64          rowHash = 0;
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 55413c0fdf..71ae53ff97 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -1182,7 +1182,7 @@ catenate_stringinfo_string(StringInfo buffer, const char 
*addon)
 }
 
 Datum
-json_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types,
+json_build_object_worker(int nargs, const Datum *args, const bool *nulls, 
const Oid *types,
                                                 bool absent_on_null, bool 
unique_keys)
 {
        int                     i;
@@ -1295,7 +1295,7 @@ json_build_object_noargs(PG_FUNCTION_ARGS)
 }
 
 Datum
-json_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types,
+json_build_array_worker(int nargs, const Datum *args, const bool *nulls, const 
Oid *types,
                                                bool absent_on_null)
 {
        int                     i;
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index b10a60ac66..6f445f5c2b 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -58,7 +58,7 @@ static void jsonb_put_escaped_value(StringInfo out, 
JsonbValue *scalarVal);
 static JsonParseErrorType jsonb_in_scalar(void *pstate, char *token, 
JsonTokenType tokentype);
 static void composite_to_jsonb(Datum composite, JsonbInState *result);
 static void array_dim_to_jsonb(JsonbInState *result, int dim, int ndims, int 
*dims,
-                                                          Datum *vals, bool 
*nulls, int *valcount,
+                                                          const Datum *vals, 
const bool *nulls, int *valcount,
                                                           JsonTypeCategory 
tcategory, Oid outfuncoid);
 static void array_to_jsonb_internal(Datum array, JsonbInState *result);
 static void datum_to_jsonb_internal(Datum val, bool is_null, JsonbInState 
*result,
@@ -864,8 +864,8 @@ datum_to_jsonb_internal(Datum val, bool is_null, 
JsonbInState *result,
  * ourselves recursively to process the next dimension.
  */
 static void
-array_dim_to_jsonb(JsonbInState *result, int dim, int ndims, int *dims, Datum 
*vals,
-                                  bool *nulls, int *valcount, JsonTypeCategory 
tcategory,
+array_dim_to_jsonb(JsonbInState *result, int dim, int ndims, int *dims, const 
Datum *vals,
+                                  const bool *nulls, int *valcount, 
JsonTypeCategory tcategory,
                                   Oid outfuncoid)
 {
        int                     i;
@@ -1127,7 +1127,7 @@ datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid 
outfuncoid)
 }
 
 Datum
-jsonb_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types,
+jsonb_build_object_worker(int nargs, const Datum *args, const bool *nulls, 
const Oid *types,
                                                  bool absent_on_null, bool 
unique_keys)
 {
        int                     i;
@@ -1212,7 +1212,7 @@ jsonb_build_object_noargs(PG_FUNCTION_ARGS)
 }
 
 Datum
-jsonb_build_array_worker(int nargs, Datum *args, bool *nulls, Oid *types,
+jsonb_build_array_worker(int nargs, const Datum *args, const bool *nulls, 
const Oid *types,
                                                 bool absent_on_null)
 {
        int                     i;
diff --git a/src/backend/utils/sort/tuplesortvariants.c 
b/src/backend/utils/sort/tuplesortvariants.c
index 84442a93c5..2cd508e513 100644
--- a/src/backend/utils/sort/tuplesortvariants.c
+++ b/src/backend/utils/sort/tuplesortvariants.c
@@ -683,8 +683,8 @@ tuplesort_putheaptuple(Tuplesortstate *state, HeapTuple tup)
  */
 void
 tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel,
-                                                         ItemPointer self, 
Datum *values,
-                                                         bool *isnull)
+                                                         ItemPointer self, 
const Datum *values,
+                                                         const bool *isnull)
 {
        SortTuple       stup;
        IndexTuple      tuple;
diff --git a/src/backend/utils/sort/tuplestore.c 
b/src/backend/utils/sort/tuplestore.c
index f60633df24..38bbed4604 100644
--- a/src/backend/utils/sort/tuplestore.c
+++ b/src/backend/utils/sort/tuplestore.c
@@ -748,7 +748,7 @@ tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
  */
 void
 tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
-                                        Datum *values, bool *isnull)
+                                        const Datum *values, const bool 
*isnull)
 {
        MinimalTuple tuple;
        MemoryContext oldcxt = MemoryContextSwitchTo(state->context);
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index a308795665..4e626c615e 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -204,7 +204,7 @@ extern IndexScanDesc RelationGetIndexScan(Relation 
indexRelation,
                                                                                
  int nkeys, int norderbys);
 extern void IndexScanEnd(IndexScanDesc scan);
 extern char *BuildIndexValueDescription(Relation indexRelation,
-                                                                               
Datum *values, bool *isnull);
+                                                                               
const Datum *values, const bool *isnull);
 extern TransactionId index_compute_xid_horizon_for_tuples(Relation irel,
                                                                                
                                  Relation hrel,
                                                                                
                                  Buffer ibuf,
diff --git a/src/include/access/gist_private.h 
b/src/include/access/gist_private.h
index 3edc740a3f..18c37f0bd8 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -502,9 +502,9 @@ extern IndexTuple gistgetadjusted(Relation r,
                                                                  IndexTuple 
addtup,
                                                                  GISTSTATE 
*giststate);
 extern IndexTuple gistFormTuple(GISTSTATE *giststate,
-                                                               Relation r, 
Datum *attdata, bool *isnull, bool isleaf);
+                                                               Relation r, 
const Datum *attdata, const bool *isnull, bool isleaf);
 extern void gistCompressValues(GISTSTATE *giststate, Relation r,
-                                                          Datum *attdata, bool 
*isnull, bool isleaf, Datum *compatt);
+                                                          const Datum 
*attdata, const bool *isnull, bool isleaf, Datum *compatt);
 
 extern OffsetNumber gistchoose(Relation r, Page p,
                                                           IndexTuple it,
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 9e035270a1..4806ce6c4e 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -451,7 +451,7 @@ typedef struct HSpool HSpool;       /* opaque struct in 
hashsort.c */
 extern HSpool *_h_spoolinit(Relation heap, Relation index, uint32 num_buckets);
 extern void _h_spooldestroy(HSpool *hspool);
 extern void _h_spool(HSpool *hspool, ItemPointer self,
-                                        Datum *values, bool *isnull);
+                                        const Datum *values, const bool 
*isnull);
 extern void _h_indexbuild(HSpool *hspool, Relation heapRel);
 
 /* hashutil.c */
diff --git a/src/include/access/htup_details.h 
b/src/include/access/htup_details.h
index e01f4f35c8..6fd87dc108 100644
--- a/src/include/access/htup_details.h
+++ b/src/include/access/htup_details.h
@@ -696,9 +696,9 @@ struct MinimalTupleData
 
 /* prototypes for functions in common/heaptuple.c */
 extern Size heap_compute_data_size(TupleDesc tupleDesc,
-                                                                  Datum 
*values, bool *isnull);
+                                                                  const Datum 
*values, const bool *isnull);
 extern void heap_fill_tuple(TupleDesc tupleDesc,
-                                                       Datum *values, bool 
*isnull,
+                                                       const Datum *values, 
const bool *isnull,
                                                        char *data, Size 
data_size,
                                                        uint16 *infomask, bits8 
*bit);
 extern bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc);
@@ -712,23 +712,23 @@ extern HeapTuple heap_copytuple(HeapTuple tuple);
 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
 extern Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc);
 extern HeapTuple heap_form_tuple(TupleDesc tupleDescriptor,
-                                                                Datum *values, 
bool *isnull);
+                                                                const Datum 
*values, const bool *isnull);
 extern HeapTuple heap_modify_tuple(HeapTuple tuple,
                                                                   TupleDesc 
tupleDesc,
-                                                                  Datum 
*replValues,
-                                                                  bool 
*replIsnull,
-                                                                  bool 
*doReplace);
+                                                                  const Datum 
*replValues,
+                                                                  const bool 
*replIsnull,
+                                                                  const bool 
*doReplace);
 extern HeapTuple heap_modify_tuple_by_cols(HeapTuple tuple,
                                                                                
   TupleDesc tupleDesc,
                                                                                
   int nCols,
-                                                                               
   int *replCols,
-                                                                               
   Datum *replValues,
-                                                                               
   bool *replIsnull);
+                                                                               
   const int *replCols,
+                                                                               
   const Datum *replValues,
+                                                                               
   const bool *replIsnull);
 extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
                                                          Datum *values, bool 
*isnull);
 extern void heap_freetuple(HeapTuple htup);
 extern MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor,
-                                                                               
        Datum *values, bool *isnull);
+                                                                               
        const Datum *values, const bool *isnull);
 extern void heap_free_minimal_tuple(MinimalTuple mtup);
 extern MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup);
 extern HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup);
diff --git a/src/include/access/itup.h b/src/include/access/itup.h
index 2e2b8c7a47..1d55536dbd 100644
--- a/src/include/access/itup.h
+++ b/src/include/access/itup.h
@@ -75,9 +75,9 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
 
 /* routines in indextuple.c */
 extern IndexTuple index_form_tuple(TupleDesc tupleDescriptor,
-                                                                  Datum 
*values, bool *isnull);
+                                                                  const Datum 
*values, const bool *isnull);
 extern IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor,
-                                                                               
   Datum *values, bool *isnull,
+                                                                               
   const Datum *values, const bool *isnull,
                                                                                
   MemoryContext context);
 extern Datum nocache_index_getattr(IndexTuple tup, int attnum,
                                                                   TupleDesc 
tupleDesc);
diff --git a/src/include/access/spgist_private.h 
b/src/include/access/spgist_private.h
index c6ef46fc20..bc39ee45cc 100644
--- a/src/include/access/spgist_private.h
+++ b/src/include/access/spgist_private.h
@@ -506,10 +506,10 @@ extern void SpGistInitBuffer(Buffer b, uint16 f);
 extern void SpGistInitMetapage(Page page);
 extern unsigned int SpGistGetInnerTypeSize(SpGistTypeDesc *att, Datum datum);
 extern Size SpGistGetLeafTupleSize(TupleDesc tupleDescriptor,
-                                                                  Datum 
*datums, bool *isnulls);
+                                                                  const Datum 
*datums, const bool *isnulls);
 extern SpGistLeafTuple spgFormLeafTuple(SpGistState *state,
                                                                                
ItemPointer heapPtr,
-                                                                               
Datum *datums, bool *isnulls);
+                                                                               
const Datum *datums, const bool *isnulls);
 extern SpGistNodeTuple spgFormNodeTuple(SpGistState *state,
                                                                                
Datum label, bool isnull);
 extern SpGistInnerTuple spgFormInnerTuple(SpGistState *state,
diff --git a/src/include/access/toast_helper.h 
b/src/include/access/toast_helper.h
index e971bd2c8e..51a228db40 100644
--- a/src/include/access/toast_helper.h
+++ b/src/include/access/toast_helper.h
@@ -110,7 +110,7 @@ extern void toast_tuple_externalize(ToastTupleContext *ttc, 
int attribute,
                                                                        int 
options);
 extern void toast_tuple_cleanup(ToastTupleContext *ttc);
 
-extern void toast_delete_external(Relation rel, Datum *values, bool *isnull,
+extern void toast_delete_external(Relation rel, const Datum *values, const 
bool *isnull,
                                                                  bool 
is_speculative);
 
 #endif
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index aeebe0e0ff..e1eefb400b 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -509,7 +509,7 @@ typedef struct TupOutputState
 extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
                                                                                
                TupleDesc tupdesc,
                                                                                
                const TupleTableSlotOps *tts_ops);
-extern void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull);
+extern void do_tup_output(TupOutputState *tstate, const Datum *values, const 
bool *isnull);
 extern void do_text_output_multiline(TupOutputState *tstate, const char *txt);
 extern void end_tup_output(TupOutputState *tstate);
 
@@ -639,7 +639,7 @@ extern bool ExecCheckIndexConstraints(ResultRelInfo 
*resultRelInfo,
 extern void check_exclusion_constraint(Relation heap, Relation index,
                                                                           
IndexInfo *indexInfo,
                                                                           
ItemPointer tupleid,
-                                                                          
Datum *values, bool *isnull,
+                                                                          
const Datum *values, const bool *isnull,
                                                                           
EState *estate, bool newIndex);
 
 /*
diff --git a/src/include/partitioning/partbounds.h 
b/src/include/partitioning/partbounds.h
index d2e01f92df..53bcc867df 100644
--- a/src/include/partitioning/partbounds.h
+++ b/src/include/partitioning/partbounds.h
@@ -100,8 +100,8 @@ typedef struct PartitionBoundInfoData
 
 extern int     get_hash_partition_greatest_modulus(PartitionBoundInfo bound);
 extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo 
*partsupfunc,
-                                                                               
   Oid *partcollation,
-                                                                               
   Datum *values, bool *isnull);
+                                                                               
   const Oid *partcollation,
+                                                                               
   const Datum *values, const bool *isnull);
 extern List *get_qual_from_partbound(Relation parent,
                                                                         
PartitionBoundSpec *spec);
 extern PartitionBoundInfo partition_bounds_create(PartitionBoundSpec 
**boundspecs,
diff --git a/src/include/utils/json.h b/src/include/utils/json.h
index 35a9a5545d..f07e82c832 100644
--- a/src/include/utils/json.h
+++ b/src/include/utils/json.h
@@ -21,11 +21,11 @@ extern void escape_json(StringInfo buf, const char *str);
 extern char *JsonEncodeDateTime(char *buf, Datum value, Oid typid,
                                                                const int *tzp);
 extern bool to_json_is_immutable(Oid typoid);
-extern Datum json_build_object_worker(int nargs, Datum *args, bool *nulls,
-                                                                         Oid 
*types, bool absent_on_null,
+extern Datum json_build_object_worker(int nargs, const Datum *args, const bool 
*nulls,
+                                                                         const 
Oid *types, bool absent_on_null,
                                                                          bool 
unique_keys);
-extern Datum json_build_array_worker(int nargs, Datum *args, bool *nulls,
-                                                                        Oid 
*types, bool absent_on_null);
+extern Datum json_build_array_worker(int nargs, const Datum *args, const bool 
*nulls,
+                                                                        const 
Oid *types, bool absent_on_null);
 extern bool json_validate(text *json, bool check_unique_keys, bool 
throw_error);
 
 #endif                                                 /* JSON_H */
diff --git a/src/include/utils/jsonb.h b/src/include/utils/jsonb.h
index 649a1644f2..e62a5f2f44 100644
--- a/src/include/utils/jsonb.h
+++ b/src/include/utils/jsonb.h
@@ -430,10 +430,10 @@ extern Datum jsonb_set_element(Jsonb *jb, Datum *path, 
int path_len,
 extern Datum jsonb_get_element(Jsonb *jb, Datum *path, int npath,
                                                           bool *isnull, bool 
as_text);
 extern bool to_jsonb_is_immutable(Oid typoid);
-extern Datum jsonb_build_object_worker(int nargs, Datum *args, bool *nulls,
-                                                                          Oid 
*types, bool absent_on_null,
+extern Datum jsonb_build_object_worker(int nargs, const Datum *args, const 
bool *nulls,
+                                                                          
const Oid *types, bool absent_on_null,
                                                                           bool 
unique_keys);
-extern Datum jsonb_build_array_worker(int nargs, Datum *args, bool *nulls,
-                                                                         Oid 
*types, bool absent_on_null);
+extern Datum jsonb_build_array_worker(int nargs, const Datum *args, const bool 
*nulls,
+                                                                         const 
Oid *types, bool absent_on_null);
 
 #endif                                                 /* __JSONB_H__ */
diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h
index 3f71c70f17..3a49a6d2d4 100644
--- a/src/include/utils/tuplesort.h
+++ b/src/include/utils/tuplesort.h
@@ -437,7 +437,7 @@ extern void tuplesort_puttupleslot(Tuplesortstate *state,
 extern void tuplesort_putheaptuple(Tuplesortstate *state, HeapTuple tup);
 extern void tuplesort_putindextuplevalues(Tuplesortstate *state,
                                                                                
  Relation rel, ItemPointer self,
-                                                                               
  Datum *values, bool *isnull);
+                                                                               
  const Datum *values, const bool *isnull);
 extern void tuplesort_putdatum(Tuplesortstate *state, Datum val,
                                                           bool isNull);
 
diff --git a/src/include/utils/tuplestore.h b/src/include/utils/tuplestore.h
index 36424b80b1..1077c5fdea 100644
--- a/src/include/utils/tuplestore.h
+++ b/src/include/utils/tuplestore.h
@@ -54,7 +54,7 @@ extern void tuplestore_puttupleslot(Tuplestorestate *state,
                                                                        
TupleTableSlot *slot);
 extern void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple);
 extern void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
-                                                                Datum *values, 
bool *isnull);
+                                                                const Datum 
*values, const bool *isnull);
 
 /* Backwards compatibility macro */
 #define tuplestore_donestoring(state)  ((void) 0)

base-commit: fd4d93d269c02081958e4c0c214f1d82186e5689
-- 
2.42.0

From 8729ca6d758b57f7f4922beecdbdfdcc38ce22e1 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Fri, 6 Oct 2023 14:57:56 +0200
Subject: [PATCH 2/2] WIP: Add const to values and nulls arguments with
 external API changes

---
 contrib/amcheck/verify_nbtree.c                  |  6 +++---
 contrib/bloom/blinsert.c                         |  6 +++---
 contrib/bloom/bloom.h                            |  4 ++--
 contrib/bloom/blutils.c                          |  2 +-
 src/backend/access/brin/brin.c                   |  6 +++---
 src/backend/access/gin/gininsert.c               |  6 +++---
 src/backend/access/gist/gist.c                   |  2 +-
 src/backend/access/gist/gistbuild.c              | 14 +++++++-------
 src/backend/access/hash/hash.c                   | 10 +++++-----
 src/backend/access/hash/hashutil.c               |  2 +-
 src/backend/access/index/indexam.c               |  4 ++--
 src/backend/access/nbtree/nbtree.c               |  2 +-
 src/backend/access/nbtree/nbtsort.c              | 12 ++++++------
 src/backend/access/spgist/spgdoinsert.c          |  2 +-
 src/backend/access/spgist/spginsert.c            |  6 +++---
 src/include/access/amapi.h                       |  4 ++--
 src/include/access/brin_internal.h               |  2 +-
 src/include/access/genam.h                       |  2 +-
 src/include/access/gin_private.h                 |  2 +-
 src/include/access/gist_private.h                |  2 +-
 src/include/access/hash.h                        |  4 ++--
 src/include/access/nbtree.h                      |  2 +-
 src/include/access/spgist.h                      |  2 +-
 src/include/access/spgist_private.h              |  2 +-
 src/include/access/tableam.h                     |  4 ++--
 src/test/modules/dummy_index_am/dummy_index_am.c |  2 +-
 26 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index dbb83d80f8..206bde6ab2 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -161,7 +161,7 @@ static void bt_child_highkey_check(BtreeCheckState *state,
 static void bt_downlink_missing_check(BtreeCheckState *state, bool rightsplit,
                                                                          
BlockNumber blkno, Page page);
 static void bt_tuple_present_callback(Relation index, ItemPointer tid,
-                                                                         Datum 
*values, bool *isnull,
+                                                                         const 
Datum *values, const bool *isnull,
                                                                          bool 
tupleIsAlive, void *checkstate);
 static IndexTuple bt_normalize_tuple(BtreeCheckState *state,
                                                                         
IndexTuple itup);
@@ -2483,8 +2483,8 @@ bt_downlink_missing_check(BtreeCheckState *state, bool 
rightsplit,
  * also allows us to detect the corruption in many cases.
  */
 static void
-bt_tuple_present_callback(Relation index, ItemPointer tid, Datum *values,
-                                                 bool *isnull, bool 
tupleIsAlive, void *checkstate)
+bt_tuple_present_callback(Relation index, ItemPointer tid, const Datum *values,
+                                                 const bool *isnull, bool 
tupleIsAlive, void *checkstate)
 {
        BtreeCheckState *state = (BtreeCheckState *) checkstate;
        IndexTuple      itup,
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index b90145148d..8bf171f2ec 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -71,8 +71,8 @@ initCachedPage(BloomBuildState *buildstate)
  * Per-tuple callback for table_index_build_scan.
  */
 static void
-bloomBuildCallback(Relation index, ItemPointer tid, Datum *values,
-                                  bool *isnull, bool tupleIsAlive, void *state)
+bloomBuildCallback(Relation index, ItemPointer tid, const Datum *values,
+                                  const bool *isnull, bool tupleIsAlive, void 
*state)
 {
        BloomBuildState *buildstate = (BloomBuildState *) state;
        MemoryContext oldCtx;
@@ -171,7 +171,7 @@ blbuildempty(Relation index)
  * Insert new tuple to the bloom index.
  */
 bool
-blinsert(Relation index, Datum *values, bool *isnull,
+blinsert(Relation index, const Datum *values, const bool *isnull,
                 ItemPointer ht_ctid, Relation heapRel,
                 IndexUniqueCheck checkUnique,
                 bool indexUnchanged,
diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index 330811ec60..bc427f7632 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -181,14 +181,14 @@ extern void BloomInitMetapage(Relation index, ForkNumber 
forknum);
 extern void BloomInitPage(Page page, uint16 flags);
 extern Buffer BloomNewBuffer(Relation index);
 extern void signValue(BloomState *state, BloomSignatureWord *sign, Datum 
value, int attno);
-extern BloomTuple *BloomFormTuple(BloomState *state, ItemPointer iptr, Datum 
*values, bool *isnull);
+extern BloomTuple *BloomFormTuple(BloomState *state, ItemPointer iptr, const 
Datum *values, const bool *isnull);
 extern bool BloomPageAddItem(BloomState *state, Page page, BloomTuple *tuple);
 
 /* blvalidate.c */
 extern bool blvalidate(Oid opclassoid);
 
 /* index access method interface functions */
-extern bool blinsert(Relation index, Datum *values, bool *isnull,
+extern bool blinsert(Relation index, const Datum *values, const bool *isnull,
                                         ItemPointer ht_ctid, Relation heapRel,
                                         IndexUniqueCheck checkUnique,
                                         bool indexUnchanged,
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index f23fbb1d9e..aed4145dcd 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -290,7 +290,7 @@ signValue(BloomState *state, BloomSignatureWord *sign, 
Datum value, int attno)
  * Make bloom tuple from values.
  */
 BloomTuple *
-BloomFormTuple(BloomState *state, ItemPointer iptr, Datum *values, bool 
*isnull)
+BloomFormTuple(BloomState *state, ItemPointer iptr, const Datum *values, const 
bool *isnull)
 {
        int                     i;
        BloomTuple *res = (BloomTuple *) palloc0(state->sizeOfBloomTuple);
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index af392bc032..29e5ce7ea0 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -153,7 +153,7 @@ brinhandler(PG_FUNCTION_ARGS)
  * it), there's nothing to do for this tuple.
  */
 bool
-brininsert(Relation idxRel, Datum *values, bool *nulls,
+brininsert(Relation idxRel, const Datum *values, const bool *nulls,
                   ItemPointer heaptid, Relation heapRel,
                   IndexUniqueCheck checkUnique,
                   bool indexUnchanged,
@@ -781,8 +781,8 @@ brinendscan(IndexScanDesc scan)
 static void
 brinbuildCallback(Relation index,
                                  ItemPointer tid,
-                                 Datum *values,
-                                 bool *isnull,
+                                 const Datum *values,
+                                 const bool *isnull,
                                  bool tupleIsAlive,
                                  void *brstate)
 {
diff --git a/src/backend/access/gin/gininsert.c 
b/src/backend/access/gin/gininsert.c
index b4d216d4c6..78c7ee6ff9 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -277,8 +277,8 @@ ginHeapTupleBulkInsert(GinBuildState *buildstate, 
OffsetNumber attnum,
 }
 
 static void
-ginBuildCallback(Relation index, ItemPointer tid, Datum *values,
-                                bool *isnull, bool tupleIsAlive, void *state)
+ginBuildCallback(Relation index, ItemPointer tid, const Datum *values,
+                                const bool *isnull, bool tupleIsAlive, void 
*state)
 {
        GinBuildState *buildstate = (GinBuildState *) state;
        MemoryContext oldCtx;
@@ -483,7 +483,7 @@ ginHeapTupleInsert(GinState *ginstate, OffsetNumber attnum,
 }
 
 bool
-gininsert(Relation index, Datum *values, bool *isnull,
+gininsert(Relation index, const Datum *values, const bool *isnull,
                  ItemPointer ht_ctid, Relation heapRel,
                  IndexUniqueCheck checkUnique,
                  bool indexUnchanged,
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 8ef5fa0329..09fe9bf9cc 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -155,7 +155,7 @@ gistbuildempty(Relation index)
  *       It doesn't do any work; just locks the relation and passes the buck.
  */
 bool
-gistinsert(Relation r, Datum *values, bool *isnull,
+gistinsert(Relation r, const Datum *values, const bool *isnull,
                   ItemPointer ht_ctid, Relation heapRel,
                   IndexUniqueCheck checkUnique,
                   bool indexUnchanged,
diff --git a/src/backend/access/gist/gistbuild.c 
b/src/backend/access/gist/gistbuild.c
index 5e0c1447f9..d48099f6b5 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -134,7 +134,7 @@ typedef struct GistSortedBuildLevelState
 /* prototypes for private functions */
 
 static void gistSortedBuildCallback(Relation index, ItemPointer tid,
-                                                                       Datum 
*values, bool *isnull,
+                                                                       const 
Datum *values, const bool *isnull,
                                                                        bool 
tupleIsAlive, void *state);
 static void gist_indexsortbuild(GISTBuildState *state);
 static void gist_indexsortbuild_levelstate_add(GISTBuildState *state,
@@ -148,8 +148,8 @@ static void gistInitBuffering(GISTBuildState *buildstate);
 static int     calculatePagesPerBuffer(GISTBuildState *buildstate, int 
levelStep);
 static void gistBuildCallback(Relation index,
                                                          ItemPointer tid,
-                                                         Datum *values,
-                                                         bool *isnull,
+                                                         const Datum *values,
+                                                         const bool *isnull,
                                                          bool tupleIsAlive,
                                                          void *state);
 static void gistBufferingBuildInsert(GISTBuildState *buildstate,
@@ -369,8 +369,8 @@ gistbuild(Relation heap, Relation index, IndexInfo 
*indexInfo)
 static void
 gistSortedBuildCallback(Relation index,
                                                ItemPointer tid,
-                                               Datum *values,
-                                               bool *isnull,
+                                               const Datum *values,
+                                               const bool *isnull,
                                                bool tupleIsAlive,
                                                void *state)
 {
@@ -885,8 +885,8 @@ calculatePagesPerBuffer(GISTBuildState *buildstate, int 
levelStep)
 static void
 gistBuildCallback(Relation index,
                                  ItemPointer tid,
-                                 Datum *values,
-                                 bool *isnull,
+                                 const Datum *values,
+                                 const bool *isnull,
                                  bool tupleIsAlive,
                                  void *state)
 {
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index fc5d97f606..e7310fa874 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -43,8 +43,8 @@ typedef struct
 
 static void hashbuildCallback(Relation index,
                                                          ItemPointer tid,
-                                                         Datum *values,
-                                                         bool *isnull,
+                                                         const Datum *values,
+                                                         const bool *isnull,
                                                          bool tupleIsAlive,
                                                          void *state);
 
@@ -207,8 +207,8 @@ hashbuildempty(Relation index)
 static void
 hashbuildCallback(Relation index,
                                  ItemPointer tid,
-                                 Datum *values,
-                                 bool *isnull,
+                                 const Datum *values,
+                                 const bool *isnull,
                                  bool tupleIsAlive,
                                  void *state)
 {
@@ -246,7 +246,7 @@ hashbuildCallback(Relation index,
  *     Find the appropriate location for the new tuple, and put it there.
  */
 bool
-hashinsert(Relation rel, Datum *values, bool *isnull,
+hashinsert(Relation rel, const Datum *values, const bool *isnull,
                   ItemPointer ht_ctid, Relation heapRel,
                   IndexUniqueCheck checkUnique,
                   bool indexUnchanged,
diff --git a/src/backend/access/hash/hashutil.c 
b/src/backend/access/hash/hashutil.c
index 88089ce02b..ef3eebe4bf 100644
--- a/src/backend/access/hash/hashutil.c
+++ b/src/backend/access/hash/hashutil.c
@@ -317,7 +317,7 @@ _hash_get_indextuple_hashkey(IndexTuple itup)
  */
 bool
 _hash_convert_tuple(Relation index,
-                                       Datum *user_values, bool *user_isnull,
+                                       const Datum *user_values, const bool 
*user_isnull,
                                        Datum *index_values, bool *index_isnull)
 {
        uint32          hashkey;
diff --git a/src/backend/access/index/indexam.c 
b/src/backend/access/index/indexam.c
index b25b03f7ab..40e7279fc8 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -174,8 +174,8 @@ index_close(Relation relation, LOCKMODE lockmode)
  */
 bool
 index_insert(Relation indexRelation,
-                        Datum *values,
-                        bool *isnull,
+                        const Datum *values,
+                        const bool *isnull,
                         ItemPointer heap_t_ctid,
                         Relation heapRelation,
                         IndexUniqueCheck checkUnique,
diff --git a/src/backend/access/nbtree/nbtree.c 
b/src/backend/access/nbtree/nbtree.c
index 6c5b5c69ce..0ad9194fad 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -187,7 +187,7 @@ btbuildempty(Relation index)
  *             new tuple, and put it there.
  */
 bool
-btinsert(Relation rel, Datum *values, bool *isnull,
+btinsert(Relation rel, const Datum *values, const bool *isnull,
                 ItemPointer ht_ctid, Relation heapRel,
                 IndexUniqueCheck checkUnique,
                 bool indexUnchanged,
diff --git a/src/backend/access/nbtree/nbtsort.c 
b/src/backend/access/nbtree/nbtsort.c
index c2665fce41..c2cbc2f8fc 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -263,10 +263,10 @@ static double _bt_spools_heapscan(Relation heap, Relation 
index,
                                                                  BTBuildState 
*buildstate, IndexInfo *indexInfo);
 static void _bt_spooldestroy(BTSpool *btspool);
 static void _bt_spool(BTSpool *btspool, ItemPointer self,
-                                         Datum *values, bool *isnull);
+                                         const Datum *values, const bool 
*isnull);
 static void _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2);
-static void _bt_build_callback(Relation index, ItemPointer tid, Datum *values,
-                                                          bool *isnull, bool 
tupleIsAlive, void *state);
+static void _bt_build_callback(Relation index, ItemPointer tid, const Datum 
*values,
+                                                          const bool *isnull, 
bool tupleIsAlive, void *state);
 static Page _bt_blnewpage(uint32 level);
 static BTPageState *_bt_pagestate(BTWriteState *wstate, uint32 level);
 static void _bt_slideleft(Page rightmostpage);
@@ -530,7 +530,7 @@ _bt_spooldestroy(BTSpool *btspool)
  * spool an index entry into the sort file.
  */
 static void
-_bt_spool(BTSpool *btspool, ItemPointer self, Datum *values, bool *isnull)
+_bt_spool(BTSpool *btspool, ItemPointer self, const Datum *values, const bool 
*isnull)
 {
        tuplesort_putindextuplevalues(btspool->sortstate, btspool->index,
                                                                  self, values, 
isnull);
@@ -587,8 +587,8 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
 static void
 _bt_build_callback(Relation index,
                                   ItemPointer tid,
-                                  Datum *values,
-                                  bool *isnull,
+                                  const Datum *values,
+                                  const bool *isnull,
                                   bool tupleIsAlive,
                                   void *state)
 {
diff --git a/src/backend/access/spgist/spgdoinsert.c 
b/src/backend/access/spgist/spgdoinsert.c
index 3554edcc9a..a1b107d2b6 100644
--- a/src/backend/access/spgist/spgdoinsert.c
+++ b/src/backend/access/spgist/spgdoinsert.c
@@ -1913,7 +1913,7 @@ spgSplitNodeAction(Relation index, SpGistState *state,
  */
 bool
 spgdoinsert(Relation index, SpGistState *state,
-                       ItemPointer heapPtr, Datum *datums, bool *isnulls)
+                       ItemPointer heapPtr, const Datum *datums, const bool 
*isnulls)
 {
        bool            result = true;
        TupleDesc       leafDescriptor = state->leafTupDesc;
diff --git a/src/backend/access/spgist/spginsert.c 
b/src/backend/access/spgist/spginsert.c
index 4443f1918d..6c9b9098d6 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -40,8 +40,8 @@ typedef struct
 
 /* Callback to process one heap tuple during table_index_build_scan */
 static void
-spgistBuildCallback(Relation index, ItemPointer tid, Datum *values,
-                                       bool *isnull, bool tupleIsAlive, void 
*state)
+spgistBuildCallback(Relation index, ItemPointer tid, const Datum *values,
+                                       const bool *isnull, bool tupleIsAlive, 
void *state)
 {
        SpGistBuildState *buildstate = (SpGistBuildState *) state;
        MemoryContext oldCtx;
@@ -197,7 +197,7 @@ spgbuildempty(Relation index)
  * Insert one new tuple into an SPGiST index.
  */
 bool
-spginsert(Relation index, Datum *values, bool *isnull,
+spginsert(Relation index, const Datum *values, const bool *isnull,
                  ItemPointer ht_ctid, Relation heapRel,
                  IndexUniqueCheck checkUnique,
                  bool indexUnchanged,
diff --git a/src/include/access/amapi.h b/src/include/access/amapi.h
index 4476ff7fba..bfa3ec5303 100644
--- a/src/include/access/amapi.h
+++ b/src/include/access/amapi.h
@@ -105,8 +105,8 @@ typedef void (*ambuildempty_function) (Relation 
indexRelation);
 
 /* insert this tuple */
 typedef bool (*aminsert_function) (Relation indexRelation,
-                                                                  Datum 
*values,
-                                                                  bool *isnull,
+                                                                  const Datum 
*values,
+                                                                  const bool 
*isnull,
                                                                   ItemPointer 
heap_tid,
                                                                   Relation 
heapRelation,
                                                                   
IndexUniqueCheck checkUnique,
diff --git a/src/include/access/brin_internal.h 
b/src/include/access/brin_internal.h
index 97ddc925b2..45ed31af8a 100644
--- a/src/include/access/brin_internal.h
+++ b/src/include/access/brin_internal.h
@@ -91,7 +91,7 @@ extern void brin_free_desc(BrinDesc *bdesc);
 extern IndexBuildResult *brinbuild(Relation heap, Relation index,
                                                                   struct 
IndexInfo *indexInfo);
 extern void brinbuildempty(Relation index);
-extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
+extern bool brininsert(Relation idxRel, const Datum *values, const bool *nulls,
                                           ItemPointer heaptid, Relation 
heapRel,
                                           IndexUniqueCheck checkUnique,
                                           bool indexUnchanged,
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 4e626c615e..7ab83bc479 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -142,7 +142,7 @@ extern Relation index_open(Oid relationId, LOCKMODE 
lockmode);
 extern void index_close(Relation relation, LOCKMODE lockmode);
 
 extern bool index_insert(Relation indexRelation,
-                                                Datum *values, bool *isnull,
+                                                const Datum *values, const 
bool *isnull,
                                                 ItemPointer heap_t_ctid,
                                                 Relation heapRelation,
                                                 IndexUniqueCheck checkUnique,
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index 76b9923201..32a108a5ac 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -113,7 +113,7 @@ extern Datum gintuple_get_key(GinState *ginstate, 
IndexTuple tuple,
 extern IndexBuildResult *ginbuild(Relation heap, Relation index,
                                                                  struct 
IndexInfo *indexInfo);
 extern void ginbuildempty(Relation index);
-extern bool gininsert(Relation index, Datum *values, bool *isnull,
+extern bool gininsert(Relation index, const Datum *values, const bool *isnull,
                                          ItemPointer ht_ctid, Relation heapRel,
                                          IndexUniqueCheck checkUnique,
                                          bool indexUnchanged,
diff --git a/src/include/access/gist_private.h 
b/src/include/access/gist_private.h
index 18c37f0bd8..e4a2b2eea2 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -400,7 +400,7 @@ typedef struct GiSTOptions
 
 /* gist.c */
 extern void gistbuildempty(Relation index);
-extern bool gistinsert(Relation r, Datum *values, bool *isnull,
+extern bool gistinsert(Relation r, const Datum *values, const bool *isnull,
                                           ItemPointer ht_ctid, Relation 
heapRel,
                                           IndexUniqueCheck checkUnique,
                                           bool indexUnchanged,
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 4806ce6c4e..68c30d2e03 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -363,7 +363,7 @@ typedef struct HashOptions
 extern IndexBuildResult *hashbuild(Relation heap, Relation index,
                                                                   struct 
IndexInfo *indexInfo);
 extern void hashbuildempty(Relation index);
-extern bool hashinsert(Relation rel, Datum *values, bool *isnull,
+extern bool hashinsert(Relation rel, const Datum *values, const bool *isnull,
                                           ItemPointer ht_ctid, Relation 
heapRel,
                                           IndexUniqueCheck checkUnique,
                                           bool indexUnchanged,
@@ -465,7 +465,7 @@ extern uint32 _hash_get_totalbuckets(uint32 
splitpoint_phase);
 extern void _hash_checkpage(Relation rel, Buffer buf, int flags);
 extern uint32 _hash_get_indextuple_hashkey(IndexTuple itup);
 extern bool _hash_convert_tuple(Relation index,
-                                                               Datum 
*user_values, bool *user_isnull,
+                                                               const Datum 
*user_values, const bool *user_isnull,
                                                                Datum 
*index_values, bool *index_isnull);
 extern OffsetNumber _hash_binsearch(Page page, uint32 hash_value);
 extern OffsetNumber _hash_binsearch_last(Page page, uint32 hash_value);
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 6345e16d78..213857dde3 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -1127,7 +1127,7 @@ typedef struct BTOptions
  * external entry points for btree, in nbtree.c
  */
 extern void btbuildempty(Relation index);
-extern bool btinsert(Relation rel, Datum *values, bool *isnull,
+extern bool btinsert(Relation rel, const Datum *values, const bool *isnull,
                                         ItemPointer ht_ctid, Relation heapRel,
                                         IndexUniqueCheck checkUnique,
                                         bool indexUnchanged,
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index fe31d32dbe..002d4b872f 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -196,7 +196,7 @@ extern bytea *spgoptions(Datum reloptions, bool validate);
 extern IndexBuildResult *spgbuild(Relation heap, Relation index,
                                                                  struct 
IndexInfo *indexInfo);
 extern void spgbuildempty(Relation index);
-extern bool spginsert(Relation index, Datum *values, bool *isnull,
+extern bool spginsert(Relation index, const Datum *values, const bool *isnull,
                                          ItemPointer ht_ctid, Relation heapRel,
                                          IndexUniqueCheck checkUnique,
                                          bool indexUnchanged,
diff --git a/src/include/access/spgist_private.h 
b/src/include/access/spgist_private.h
index bc39ee45cc..d18c125c5a 100644
--- a/src/include/access/spgist_private.h
+++ b/src/include/access/spgist_private.h
@@ -538,7 +538,7 @@ extern void spgPageIndexMultiDelete(SpGistState *state, 
Page page,
                                                                        int 
firststate, int reststate,
                                                                        
BlockNumber blkno, OffsetNumber offnum);
 extern bool spgdoinsert(Relation index, SpGistState *state,
-                                               ItemPointer heapPtr, Datum 
*datums, bool *isnulls);
+                                               ItemPointer heapPtr, const 
Datum *datums, const bool *isnulls);
 
 /* spgproc.c */
 extern double *spg_key_orderbys_distances(Datum key, bool isLeaf,
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 230bc39cc0..c5e573405c 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -263,8 +263,8 @@ typedef struct TM_IndexDeleteOp
 /* Typedef for callback function for table_index_build_scan */
 typedef void (*IndexBuildCallback) (Relation index,
                                                                        
ItemPointer tid,
-                                                                       Datum 
*values,
-                                                                       bool 
*isnull,
+                                                                       const 
Datum *values,
+                                                                       const 
bool *isnull,
                                                                        bool 
tupleIsAlive,
                                                                        void 
*state);
 
diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c 
b/src/test/modules/dummy_index_am/dummy_index_am.c
index c14e0abe0c..542fed0384 100644
--- a/src/test/modules/dummy_index_am/dummy_index_am.c
+++ b/src/test/modules/dummy_index_am/dummy_index_am.c
@@ -163,7 +163,7 @@ dibuildempty(Relation index)
  * Insert new tuple to index AM.
  */
 static bool
-diinsert(Relation index, Datum *values, bool *isnull,
+diinsert(Relation index, const Datum *values, const bool *isnull,
                 ItemPointer ht_ctid, Relation heapRel,
                 IndexUniqueCheck checkUnique,
                 bool indexUnchanged,
-- 
2.42.0

Reply via email to