From d9d2edd6dc585dbf71cee7f46bce55ba101eed28 Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Fri, 21 Aug 2026 22:03:10 -0400
Subject: [PATCH v1 1/5] Convert stats_check functions from fcinfo to
 NullableDatum arrays.

Change stats_check_required_arg(), stats_check_arg_array(), and
stats_check_arg_pair() to stop using a fcinfo parameter and instead
use a NullableDatum args parameter.
---
 src/backend/statistics/attribute_stats.c      | 26 +++++++++----------
 src/backend/statistics/extended_stats_funcs.c | 20 +++++++-------
 src/backend/statistics/relation_stats.c       |  4 +--
 src/backend/statistics/stat_utils.c           | 20 +++++++-------
 src/include/statistics/stat_utils.h           |  6 ++---
 5 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/backend/statistics/attribute_stats.c b/src/backend/statistics/attribute_stats.c
index 16b0dd6a003..11bc1df1e0c 100644
--- a/src/backend/statistics/attribute_stats.c
+++ b/src/backend/statistics/attribute_stats.c
@@ -141,8 +141,8 @@ attribute_statistics_update(FunctionCallInfo fcinfo)
 	bool		inherited;
 	Oid			locked_table = InvalidOid;
 
-	stats_check_required_arg(fcinfo, attarginfo, ATTRELSCHEMA_ARG);
-	stats_check_required_arg(fcinfo, attarginfo, ATTRELNAME_ARG);
+	stats_check_required_arg(fcinfo->args, attarginfo, ATTRELSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, attarginfo, ATTRELNAME_ARG);
 
 	nspname = TextDatumGetCString(PG_GETARG_DATUM(ATTRELSCHEMA_ARG));
 	relname = TextDatumGetCString(PG_GETARG_DATUM(ATTRELNAME_ARG));
@@ -201,7 +201,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo)
 				 errmsg("cannot modify statistics on system column \"%s\"",
 						attname)));
 
-	stats_check_required_arg(fcinfo, attarginfo, INHERITED_ARG);
+	stats_check_required_arg(fcinfo->args, attarginfo, INHERITED_ARG);
 	inherited = PG_GETARG_BOOL(INHERITED_ARG);
 
 	return attribute_statistics_update_internal(reloid, attname, attnum,
@@ -253,31 +253,31 @@ attribute_statistics_update_internal(Oid reloid,
 	 * and set the corresponding argument to NULL in fcinfo.
 	 */
 
-	if (!stats_check_arg_array(fcinfo, attarginfo, MOST_COMMON_FREQS_ARG))
+	if (!stats_check_arg_array(fcinfo->args, attarginfo, MOST_COMMON_FREQS_ARG))
 	{
 		do_mcv = false;
 		result = false;
 	}
 
-	if (!stats_check_arg_array(fcinfo, attarginfo, MOST_COMMON_ELEM_FREQS_ARG))
+	if (!stats_check_arg_array(fcinfo->args, attarginfo, MOST_COMMON_ELEM_FREQS_ARG))
 	{
 		do_mcelem = false;
 		result = false;
 	}
-	if (!stats_check_arg_array(fcinfo, attarginfo, ELEM_COUNT_HISTOGRAM_ARG))
+	if (!stats_check_arg_array(fcinfo->args, attarginfo, ELEM_COUNT_HISTOGRAM_ARG))
 	{
 		do_dechist = false;
 		result = false;
 	}
 
-	if (!stats_check_arg_pair(fcinfo, attarginfo,
+	if (!stats_check_arg_pair(fcinfo->args, attarginfo,
 							  MOST_COMMON_VALS_ARG, MOST_COMMON_FREQS_ARG))
 	{
 		do_mcv = false;
 		result = false;
 	}
 
-	if (!stats_check_arg_pair(fcinfo, attarginfo,
+	if (!stats_check_arg_pair(fcinfo->args, attarginfo,
 							  MOST_COMMON_ELEMS_ARG,
 							  MOST_COMMON_ELEM_FREQS_ARG))
 	{
@@ -285,7 +285,7 @@ attribute_statistics_update_internal(Oid reloid,
 		result = false;
 	}
 
-	if (!stats_check_arg_pair(fcinfo, attarginfo,
+	if (!stats_check_arg_pair(fcinfo->args, attarginfo,
 							  RANGE_LENGTH_HISTOGRAM_ARG,
 							  RANGE_EMPTY_FRAC_ARG))
 	{
@@ -631,10 +631,10 @@ pg_clear_attribute_stats(PG_FUNCTION_ARGS)
 	bool		inherited;
 	Oid			locked_table = InvalidOid;
 
-	stats_check_required_arg(fcinfo, cleararginfo, C_ATTRELSCHEMA_ARG);
-	stats_check_required_arg(fcinfo, cleararginfo, C_ATTRELNAME_ARG);
-	stats_check_required_arg(fcinfo, cleararginfo, C_ATTNAME_ARG);
-	stats_check_required_arg(fcinfo, cleararginfo, C_INHERITED_ARG);
+	stats_check_required_arg(fcinfo->args, cleararginfo, C_ATTRELSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, cleararginfo, C_ATTRELNAME_ARG);
+	stats_check_required_arg(fcinfo->args, cleararginfo, C_ATTNAME_ARG);
+	stats_check_required_arg(fcinfo->args, cleararginfo, C_INHERITED_ARG);
 
 	nspname = TextDatumGetCString(PG_GETARG_DATUM(C_ATTRELSCHEMA_ARG));
 	relname = TextDatumGetCString(PG_GETARG_DATUM(C_ATTRELNAME_ARG));
diff --git a/src/backend/statistics/extended_stats_funcs.c b/src/backend/statistics/extended_stats_funcs.c
index 988f81c6be4..2117617ab18 100644
--- a/src/backend/statistics/extended_stats_funcs.c
+++ b/src/backend/statistics/extended_stats_funcs.c
@@ -373,17 +373,17 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 	}
 
 	/* relation arguments */
-	stats_check_required_arg(fcinfo, extarginfo, RELSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, RELSCHEMA_ARG);
 	relnspname = TextDatumGetCString(PG_GETARG_DATUM(RELSCHEMA_ARG));
-	stats_check_required_arg(fcinfo, extarginfo, RELNAME_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, RELNAME_ARG);
 	relname = TextDatumGetCString(PG_GETARG_DATUM(RELNAME_ARG));
 
 	/* extended statistics arguments */
-	stats_check_required_arg(fcinfo, extarginfo, STATSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, STATSCHEMA_ARG);
 	nspname = TextDatumGetCString(PG_GETARG_DATUM(STATSCHEMA_ARG));
-	stats_check_required_arg(fcinfo, extarginfo, STATNAME_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, STATNAME_ARG);
 	stxname = TextDatumGetCString(PG_GETARG_DATUM(STATNAME_ARG));
-	stats_check_required_arg(fcinfo, extarginfo, INHERITED_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, INHERITED_ARG);
 	inherited = PG_GETARG_BOOL(INHERITED_ARG);
 
 	/*
@@ -1758,17 +1758,17 @@ pg_clear_extended_stats(PG_FUNCTION_ARGS)
 	Oid			locked_table = InvalidOid;
 
 	/* relation arguments */
-	stats_check_required_arg(fcinfo, extarginfo, RELSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, RELSCHEMA_ARG);
 	relnspname = TextDatumGetCString(PG_GETARG_DATUM(RELSCHEMA_ARG));
-	stats_check_required_arg(fcinfo, extarginfo, RELNAME_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, RELNAME_ARG);
 	relname = TextDatumGetCString(PG_GETARG_DATUM(RELNAME_ARG));
 
 	/* extended statistics arguments */
-	stats_check_required_arg(fcinfo, extarginfo, STATSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, STATSCHEMA_ARG);
 	nspname = TextDatumGetCString(PG_GETARG_DATUM(STATSCHEMA_ARG));
-	stats_check_required_arg(fcinfo, extarginfo, STATNAME_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, STATNAME_ARG);
 	stxname = TextDatumGetCString(PG_GETARG_DATUM(STATNAME_ARG));
-	stats_check_required_arg(fcinfo, extarginfo, INHERITED_ARG);
+	stats_check_required_arg(fcinfo->args, extarginfo, INHERITED_ARG);
 	inherited = PG_GETARG_BOOL(INHERITED_ARG);
 
 	if (RecoveryInProgress())
diff --git a/src/backend/statistics/relation_stats.c b/src/backend/statistics/relation_stats.c
index f2743c00c58..faa5c716b1a 100644
--- a/src/backend/statistics/relation_stats.c
+++ b/src/backend/statistics/relation_stats.c
@@ -74,8 +74,8 @@ relation_statistics_update(FunctionCallInfo fcinfo)
 	Oid			reloid;
 	Oid			locked_table = InvalidOid;
 
-	stats_check_required_arg(fcinfo, relarginfo, RELSCHEMA_ARG);
-	stats_check_required_arg(fcinfo, relarginfo, RELNAME_ARG);
+	stats_check_required_arg(fcinfo->args, relarginfo, RELSCHEMA_ARG);
+	stats_check_required_arg(fcinfo->args, relarginfo, RELNAME_ARG);
 
 	nspname = TextDatumGetCString(PG_GETARG_DATUM(RELSCHEMA_ARG));
 	relname = TextDatumGetCString(PG_GETARG_DATUM(RELNAME_ARG));
diff --git a/src/backend/statistics/stat_utils.c b/src/backend/statistics/stat_utils.c
index 5ff37ef4cf8..c1698497d68 100644
--- a/src/backend/statistics/stat_utils.c
+++ b/src/backend/statistics/stat_utils.c
@@ -51,11 +51,11 @@ static Node *statatt_get_index_expr(Relation rel, int attnum);
  * Ensure that a given argument is not null.
  */
 void
-stats_check_required_arg(FunctionCallInfo fcinfo,
+stats_check_required_arg(const NullableDatum *args,
 						 struct StatsArgInfo *arginfo,
 						 int argnum)
 {
-	if (PG_ARGISNULL(argnum))
+	if (args[argnum].isnull)
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("argument \"%s\" must not be null",
@@ -70,16 +70,16 @@ stats_check_required_arg(FunctionCallInfo fcinfo,
  * true.
  */
 bool
-stats_check_arg_array(FunctionCallInfo fcinfo,
+stats_check_arg_array(const NullableDatum *args,
 					  struct StatsArgInfo *arginfo,
 					  int argnum)
 {
 	ArrayType  *arr;
 
-	if (PG_ARGISNULL(argnum))
+	if (args[argnum].isnull)
 		return true;
 
-	arr = DatumGetArrayTypeP(PG_GETARG_DATUM(argnum));
+	arr = DatumGetArrayTypeP(args[argnum].value);
 
 	if (ARR_NDIM(arr) != 1)
 	{
@@ -111,17 +111,17 @@ stats_check_arg_array(FunctionCallInfo fcinfo,
  * true.
  */
 bool
-stats_check_arg_pair(FunctionCallInfo fcinfo,
+stats_check_arg_pair(const NullableDatum *args,
 					 struct StatsArgInfo *arginfo,
 					 int argnum1, int argnum2)
 {
-	if (PG_ARGISNULL(argnum1) && PG_ARGISNULL(argnum2))
+	if (args[argnum1].isnull && args[argnum2].isnull)
 		return true;
 
-	if (PG_ARGISNULL(argnum1) || PG_ARGISNULL(argnum2))
+	if (args[argnum1].isnull || args[argnum2].isnull)
 	{
-		int			nullarg = PG_ARGISNULL(argnum1) ? argnum1 : argnum2;
-		int			otherarg = PG_ARGISNULL(argnum1) ? argnum2 : argnum1;
+		int			nullarg = args[argnum1].isnull ? argnum1 : argnum2;
+		int			otherarg = args[argnum1].isnull ? argnum2 : argnum1;
 
 		ereport(WARNING,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/include/statistics/stat_utils.h b/src/include/statistics/stat_utils.h
index 15e962dbb7c..8209c0d8949 100644
--- a/src/include/statistics/stat_utils.h
+++ b/src/include/statistics/stat_utils.h
@@ -25,12 +25,12 @@ struct StatsArgInfo
 	Oid			argtype;
 };
 
-extern void stats_check_required_arg(FunctionCallInfo fcinfo,
+extern void stats_check_required_arg(const NullableDatum *args,
 									 struct StatsArgInfo *arginfo,
 									 int argnum);
-extern bool stats_check_arg_array(FunctionCallInfo fcinfo,
+extern bool stats_check_arg_array(const NullableDatum *args,
 								  struct StatsArgInfo *arginfo, int argnum);
-extern bool stats_check_arg_pair(FunctionCallInfo fcinfo,
+extern bool stats_check_arg_pair(const NullableDatum *args,
 								 struct StatsArgInfo *arginfo,
 								 int argnum1, int argnum2);
 

base-commit: 3c982c9bf1af994090a181c68f9407ff39d3ddf7
-- 
2.50.1 (Apple Git-155)

