1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Mark function arguments of type "Datum *" as "const Datum *" where possible

Several functions in the codebase accept "Datum *" parameters but do
not modify the pointed-to data.  These have been updated to take
"const Datum *" instead, improving type safety and making the
interfaces clearer about their intent.  This change helps the compiler
catch accidental modifications and better documents immutability of
arguments.

Most of "Datum *" parameters have a pairing "bool *isnull" parameter,
they are constified as well.

No functional behavior is changed by this patch.

Author: Chao Li <lic@highgo.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2msfT0knvzUa72ZBwu9LR_RLY4on85w2a9YpE-o2By5HQ@mail.gmail.com
This commit is contained in:
Peter Eisentraut
2025-10-31 10:45:02 +01:00
parent aa4535307e
commit 8a27d418f8
34 changed files with 145 additions and 145 deletions

View File

@@ -39,25 +39,25 @@
static Selectivity calc_arraycontsel(VariableStatData *vardata, Datum constval,
Oid elemtype, Oid operator);
static Selectivity mcelem_array_selec(ArrayType *array,
static Selectivity mcelem_array_selec(const ArrayType *array,
TypeCacheEntry *typentry,
Datum *mcelem, int nmcelem,
float4 *numbers, int nnumbers,
float4 *hist, int nhist,
const Datum *mcelem, int nmcelem,
const float4 *numbers, int nnumbers,
const float4 *hist, int nhist,
Oid operator);
static Selectivity mcelem_array_contain_overlap_selec(Datum *mcelem, int nmcelem,
float4 *numbers, int nnumbers,
Datum *array_data, int nitems,
static Selectivity mcelem_array_contain_overlap_selec(const Datum *mcelem, int nmcelem,
const float4 *numbers, int nnumbers,
const Datum *array_data, int nitems,
Oid operator, TypeCacheEntry *typentry);
static Selectivity mcelem_array_contained_selec(Datum *mcelem, int nmcelem,
float4 *numbers, int nnumbers,
Datum *array_data, int nitems,
float4 *hist, int nhist,
static Selectivity mcelem_array_contained_selec(const Datum *mcelem, int nmcelem,
const float4 *numbers, int nnumbers,
const Datum *array_data, int nitems,
const float4 *hist, int nhist,
Oid operator, TypeCacheEntry *typentry);
static float *calc_hist(const float4 *hist, int nhist, int n);
static float *calc_distr(const float *p, int n, int m, float rest);
static int floor_log2(uint32 n);
static bool find_next_mcelem(Datum *mcelem, int nmcelem, Datum value,
static bool find_next_mcelem(const Datum *mcelem, int nmcelem, Datum value,
int *index, TypeCacheEntry *typentry);
static int element_compare(const void *key1, const void *key2, void *arg);
static int float_compare_desc(const void *key1, const void *key2);
@@ -425,10 +425,10 @@ calc_arraycontsel(VariableStatData *vardata, Datum constval,
* mcelem_array_contained_selec depending on the operator.
*/
static Selectivity
mcelem_array_selec(ArrayType *array, TypeCacheEntry *typentry,
Datum *mcelem, int nmcelem,
float4 *numbers, int nnumbers,
float4 *hist, int nhist,
mcelem_array_selec(const ArrayType *array, TypeCacheEntry *typentry,
const Datum *mcelem, int nmcelem,
const float4 *numbers, int nnumbers,
const float4 *hist, int nhist,
Oid operator)
{
Selectivity selec;
@@ -518,9 +518,9 @@ mcelem_array_selec(ArrayType *array, TypeCacheEntry *typentry,
* fraction of nonempty arrays in the column.
*/
static Selectivity
mcelem_array_contain_overlap_selec(Datum *mcelem, int nmcelem,
float4 *numbers, int nnumbers,
Datum *array_data, int nitems,
mcelem_array_contain_overlap_selec(const Datum *mcelem, int nmcelem,
const float4 *numbers, int nnumbers,
const Datum *array_data, int nitems,
Oid operator, TypeCacheEntry *typentry)
{
Selectivity selec,
@@ -699,10 +699,10 @@ mcelem_array_contain_overlap_selec(Datum *mcelem, int nmcelem,
* ... * fn^on * (1 - fn)^(1 - on), o1, o2, ..., on) | o1 + o2 + .. on = m
*/
static Selectivity
mcelem_array_contained_selec(Datum *mcelem, int nmcelem,
float4 *numbers, int nnumbers,
Datum *array_data, int nitems,
float4 *hist, int nhist,
mcelem_array_contained_selec(const Datum *mcelem, int nmcelem,
const float4 *numbers, int nnumbers,
const Datum *array_data, int nitems,
const float4 *hist, int nhist,
Oid operator, TypeCacheEntry *typentry)
{
int mcelem_index,
@@ -1136,7 +1136,7 @@ floor_log2(uint32 n)
* exact match.)
*/
static bool
find_next_mcelem(Datum *mcelem, int nmcelem, Datum value, int *index,
find_next_mcelem(const Datum *mcelem, int nmcelem, Datum value, int *index,
TypeCacheEntry *typentry)
{
int l = *index,

View File

@@ -960,8 +960,8 @@ ending_error:
*/
void
CopyArrayEls(ArrayType *array,
Datum *values,
bool *nulls,
const Datum *values,
const bool *nulls,
int nitems,
int typlen,
bool typbyval,
@@ -3629,7 +3629,7 @@ construct_empty_expanded_array(Oid element_type,
* to hard-wire values if the element type is hard-wired.
*/
void
deconstruct_array(ArrayType *array,
deconstruct_array(const ArrayType *array,
Oid elmtype,
int elmlen, bool elmbyval, char elmalign,
Datum **elemsp, bool **nullsp, int *nelemsp)
@@ -3695,7 +3695,7 @@ deconstruct_array(ArrayType *array,
* useful when manipulating arrays from/for system catalogs.
*/
void
deconstruct_array_builtin(ArrayType *array,
deconstruct_array_builtin(const ArrayType *array,
Oid elmtype,
Datum **elemsp, bool **nullsp, int *nelemsp)
{
@@ -3765,7 +3765,7 @@ deconstruct_array_builtin(ArrayType *array,
* if the array *might* contain a null.
*/
bool
array_contains_nulls(ArrayType *array)
array_contains_nulls(const ArrayType *array)
{
int nelems;
bits8 *bitmap;

View File

@@ -89,7 +89,7 @@ typedef struct JsonAggState
static void composite_to_json(Datum composite, StringInfo result,
bool use_line_feeds);
static void array_dim_to_json(StringInfo 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,
bool use_line_feeds);
static void array_to_json_internal(Datum array, StringInfo result,
@@ -429,8 +429,8 @@ JsonEncodeDateTime(char *buf, Datum value, Oid typid, const int *tzp)
* ourselves recursively to process the next dimension.
*/
static void
array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, Datum *vals,
bool *nulls, int *valcount, JsonTypeCategory tcategory,
array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, const Datum *vals,
const bool *nulls, int *valcount, JsonTypeCategory tcategory,
Oid outfuncoid, bool use_line_feeds)
{
int i;

View File

@@ -477,16 +477,16 @@ static Datum populate_domain(DomainIOData *io, Oid typid, const char *colname,
/* functions supporting jsonb_delete, jsonb_set and jsonb_concat */
static JsonbValue *IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,
JsonbParseState **state);
static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems,
bool *path_nulls, int path_len,
static JsonbValue *setPath(JsonbIterator **it, const Datum *path_elems,
const bool *path_nulls, int path_len,
JsonbParseState **st, int level, JsonbValue *newval,
int op_type);
static void setPathObject(JsonbIterator **it, Datum *path_elems,
bool *path_nulls, int path_len, JsonbParseState **st,
static void setPathObject(JsonbIterator **it, const Datum *path_elems,
const bool *path_nulls, int path_len, JsonbParseState **st,
int level,
JsonbValue *newval, uint32 npairs, int op_type);
static void setPathArray(JsonbIterator **it, Datum *path_elems,
bool *path_nulls, int path_len, JsonbParseState **st,
static void setPathArray(JsonbIterator **it, const Datum *path_elems,
const bool *path_nulls, int path_len, JsonbParseState **st,
int level,
JsonbValue *newval, uint32 nelems, int op_type);
@@ -1528,7 +1528,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
}
Datum
jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
jsonb_get_element(Jsonb *jb, const Datum *path, int npath, bool *isnull, bool as_text)
{
JsonbContainer *container = &jb->root;
JsonbValue *jbvp = NULL;
@@ -1676,7 +1676,7 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
}
Datum
jsonb_set_element(Jsonb *jb, Datum *path, int path_len,
jsonb_set_element(Jsonb *jb, const Datum *path, int path_len,
JsonbValue *newval)
{
JsonbValue *res;
@@ -1718,8 +1718,8 @@ push_null_elements(JsonbParseState **ps, int num)
* Caller is responsible to make sure such path does not exist yet.
*/
static void
push_path(JsonbParseState **st, int level, Datum *path_elems,
bool *path_nulls, int path_len, JsonbValue *newval)
push_path(JsonbParseState **st, int level, const Datum *path_elems,
const bool *path_nulls, int path_len, JsonbValue *newval)
{
/*
* tpath contains expected type of an empty jsonb created at each level
@@ -5201,8 +5201,8 @@ IteratorConcat(JsonbIterator **it1, JsonbIterator **it2,
* whatever bits in op_type are set, or nothing is done.
*/
static JsonbValue *
setPath(JsonbIterator **it, Datum *path_elems,
bool *path_nulls, int path_len,
setPath(JsonbIterator **it, const Datum *path_elems,
const bool *path_nulls, int path_len,
JsonbParseState **st, int level, JsonbValue *newval, int op_type)
{
JsonbValue v;
@@ -5283,7 +5283,7 @@ setPath(JsonbIterator **it, Datum *path_elems,
* Object walker for setPath
*/
static void
setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
setPathObject(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls,
int path_len, JsonbParseState **st, int level,
JsonbValue *newval, uint32 npairs, int op_type)
{
@@ -5422,7 +5422,7 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
* Array walker for setPath
*/
static void
setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
setPathArray(JsonbIterator **it, const Datum *path_elems, const bool *path_nulls,
int path_len, JsonbParseState **st, int level,
JsonbValue *newval, uint32 nelems, int op_type)
{

View File

@@ -49,10 +49,10 @@ static float8 get_position(TypeCacheEntry *typcache, const RangeBound *value,
static float8 get_len_position(double value, double hist1, double hist2);
static float8 get_distance(TypeCacheEntry *typcache, const RangeBound *bound1,
const RangeBound *bound2);
static int length_hist_bsearch(Datum *length_hist_values,
static int length_hist_bsearch(const Datum *length_hist_values,
int length_hist_nvalues, double value,
bool equal);
static double calc_length_hist_frac(Datum *length_hist_values,
static double calc_length_hist_frac(const Datum *length_hist_values,
int length_hist_nvalues, double length1,
double length2, bool equal);
static double calc_hist_selectivity_contained(TypeCacheEntry *typcache,
@@ -60,14 +60,14 @@ static double calc_hist_selectivity_contained(TypeCacheEntry *typcache,
RangeBound *upper,
const RangeBound *hist_lower,
int hist_nvalues,
Datum *length_hist_values,
const Datum *length_hist_values,
int length_hist_nvalues);
static double calc_hist_selectivity_contains(TypeCacheEntry *typcache,
const RangeBound *lower,
const RangeBound *upper,
const RangeBound *hist_lower,
int hist_nvalues,
Datum *length_hist_values,
const Datum *length_hist_values,
int length_hist_nvalues);
/*
@@ -765,7 +765,7 @@ rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value, const RangeBou
* given length, returns -1.
*/
static int
length_hist_bsearch(Datum *length_hist_values, int length_hist_nvalues,
length_hist_bsearch(const Datum *length_hist_values, int length_hist_nvalues,
double value, bool equal)
{
int lower = -1,
@@ -963,7 +963,7 @@ get_distance(TypeCacheEntry *typcache, const RangeBound *bound1, const RangeBoun
* 'equal' is true).
*/
static double
calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
calc_length_hist_frac(const Datum *length_hist_values, int length_hist_nvalues,
double length1, double length2, bool equal)
{
double frac;
@@ -1131,7 +1131,7 @@ static double
calc_hist_selectivity_contained(TypeCacheEntry *typcache,
const RangeBound *lower, RangeBound *upper,
const RangeBound *hist_lower, int hist_nvalues,
Datum *length_hist_values, int length_hist_nvalues)
const Datum *length_hist_values, int length_hist_nvalues)
{
int i,
upper_index;
@@ -1252,7 +1252,7 @@ static double
calc_hist_selectivity_contains(TypeCacheEntry *typcache,
const RangeBound *lower, const RangeBound *upper,
const RangeBound *hist_lower, int hist_nvalues,
Datum *length_hist_values, int length_hist_nvalues)
const Datum *length_hist_values, int length_hist_nvalues)
{
int i,
lower_index;

View File

@@ -48,17 +48,17 @@ static Selectivity networkjoinsel_inner(Oid operator,
static Selectivity networkjoinsel_semi(Oid operator,
VariableStatData *vardata1, VariableStatData *vardata2);
static Selectivity mcv_population(float4 *mcv_numbers, int mcv_nvalues);
static Selectivity inet_hist_value_sel(Datum *values, int nvalues,
static Selectivity inet_hist_value_sel(const Datum *values, int nvalues,
Datum constvalue, int opr_codenum);
static Selectivity inet_mcv_join_sel(Datum *mcv1_values,
float4 *mcv1_numbers, int mcv1_nvalues, Datum *mcv2_values,
float4 *mcv2_numbers, int mcv2_nvalues, Oid operator);
static Selectivity inet_mcv_hist_sel(Datum *mcv_values, float4 *mcv_numbers,
int mcv_nvalues, Datum *hist_values, int hist_nvalues,
static Selectivity inet_mcv_hist_sel(const Datum *mcv_values, float4 *mcv_numbers,
int mcv_nvalues, const Datum *hist_values, int hist_nvalues,
int opr_codenum);
static Selectivity inet_hist_inclusion_join_sel(Datum *hist1_values,
static Selectivity inet_hist_inclusion_join_sel(const Datum *hist1_values,
int hist1_nvalues,
Datum *hist2_values, int hist2_nvalues,
const Datum *hist2_values, int hist2_nvalues,
int opr_codenum);
static Selectivity inet_semi_join_sel(Datum lhs_value,
bool mcv_exists, Datum *mcv_values, int mcv_nvalues,
@@ -601,7 +601,7 @@ mcv_population(float4 *mcv_numbers, int mcv_nvalues)
* better option than not considering these buckets at all.
*/
static Selectivity
inet_hist_value_sel(Datum *values, int nvalues, Datum constvalue,
inet_hist_value_sel(const Datum *values, int nvalues, Datum constvalue,
int opr_codenum)
{
Selectivity match = 0.0;
@@ -702,8 +702,8 @@ inet_mcv_join_sel(Datum *mcv1_values, float4 *mcv1_numbers, int mcv1_nvalues,
* the histogram.
*/
static Selectivity
inet_mcv_hist_sel(Datum *mcv_values, float4 *mcv_numbers, int mcv_nvalues,
Datum *hist_values, int hist_nvalues,
inet_mcv_hist_sel(const Datum *mcv_values, float4 *mcv_numbers, int mcv_nvalues,
const Datum *hist_values, int hist_nvalues,
int opr_codenum)
{
Selectivity selec = 0.0;
@@ -739,8 +739,8 @@ inet_mcv_hist_sel(Datum *mcv_values, float4 *mcv_numbers, int mcv_nvalues,
* average? That would at least avoid non-commutative estimation results.
*/
static Selectivity
inet_hist_inclusion_join_sel(Datum *hist1_values, int hist1_nvalues,
Datum *hist2_values, int hist2_nvalues,
inet_hist_inclusion_join_sel(const Datum *hist1_values, int hist1_nvalues,
const Datum *hist2_values, int hist2_nvalues,
int opr_codenum)
{
double match = 0.0;

View File

@@ -660,8 +660,8 @@ pct_info_cmp(const void *pa, const void *pb)
*/
static struct pct_info *
setup_pct_info(int num_percentiles,
Datum *percentiles_datum,
bool *percentiles_null,
const Datum *percentiles_datum,
const bool *percentiles_null,
int64 rowcount,
bool continuous)
{

View File

@@ -46,18 +46,18 @@ static float8 get_position(TypeCacheEntry *typcache, const RangeBound *value,
static float8 get_len_position(double value, double hist1, double hist2);
static float8 get_distance(TypeCacheEntry *typcache, const RangeBound *bound1,
const RangeBound *bound2);
static int length_hist_bsearch(Datum *length_hist_values,
static int length_hist_bsearch(const Datum *length_hist_values,
int length_hist_nvalues, double value, bool equal);
static double calc_length_hist_frac(Datum *length_hist_values,
static double calc_length_hist_frac(const Datum *length_hist_values,
int length_hist_nvalues, double length1, double length2, bool equal);
static double calc_hist_selectivity_contained(TypeCacheEntry *typcache,
const RangeBound *lower, RangeBound *upper,
const RangeBound *hist_lower, int hist_nvalues,
Datum *length_hist_values, int length_hist_nvalues);
const Datum *length_hist_values, int length_hist_nvalues);
static double calc_hist_selectivity_contains(TypeCacheEntry *typcache,
const RangeBound *lower, const RangeBound *upper,
const RangeBound *hist_lower, int hist_nvalues,
Datum *length_hist_values, int length_hist_nvalues);
const Datum *length_hist_values, int length_hist_nvalues);
/*
* Returns a default selectivity estimate for given operator, when we don't
@@ -654,7 +654,7 @@ rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value, const RangeBou
* given length, returns -1.
*/
static int
length_hist_bsearch(Datum *length_hist_values, int length_hist_nvalues,
length_hist_bsearch(const Datum *length_hist_values, int length_hist_nvalues,
double value, bool equal)
{
int lower = -1,
@@ -852,7 +852,7 @@ get_distance(TypeCacheEntry *typcache, const RangeBound *bound1, const RangeBoun
* 'equal' is true).
*/
static double
calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
calc_length_hist_frac(const Datum *length_hist_values, int length_hist_nvalues,
double length1, double length2, bool equal)
{
double frac;
@@ -1018,7 +1018,7 @@ static double
calc_hist_selectivity_contained(TypeCacheEntry *typcache,
const RangeBound *lower, RangeBound *upper,
const RangeBound *hist_lower, int hist_nvalues,
Datum *length_hist_values, int length_hist_nvalues)
const Datum *length_hist_values, int length_hist_nvalues)
{
int i,
upper_index;
@@ -1139,7 +1139,7 @@ static double
calc_hist_selectivity_contains(TypeCacheEntry *typcache,
const RangeBound *lower, const RangeBound *upper,
const RangeBound *hist_lower, int hist_nvalues,
Datum *length_hist_values, int length_hist_nvalues)
const Datum *length_hist_values, int length_hist_nvalues)
{
int i,
lower_index;

View File

@@ -891,8 +891,8 @@ xmltotext_with_options(xmltype *data, XmlOptionType xmloption_arg, bool indent)
xmltype *
xmlelement(XmlExpr *xexpr,
Datum *named_argvalue, bool *named_argnull,
Datum *argvalue, bool *argnull)
const Datum *named_argvalue, const bool *named_argnull,
const Datum *argvalue, const bool *argnull)
{
#ifdef USE_LIBXML
xmltype *result;