From 2e0ac34fb30bc01040caeca9323713679b9a6995 Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Sun, 28 Jun 2026 16:53:19 -0500
Subject: [PATCH v2 07/13] Make extended_statistics_update stop using fcinfo.

Change the function signature of extended_statistics_update to use a
NullableDatum array instead of a full FunctionCallInfo.
---
 src/backend/statistics/extended_stats_funcs.c | 62 +++++++++----------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/src/backend/statistics/extended_stats_funcs.c b/src/backend/statistics/extended_stats_funcs.c
index f9a1d287e22..5e46a7e9678 100644
--- a/src/backend/statistics/extended_stats_funcs.c
+++ b/src/backend/statistics/extended_stats_funcs.c
@@ -121,7 +121,7 @@ static const char *extexprargname[EXPRELEM_NUM_EXPRELEMS] =
 	"range_bounds_histogram"
 };
 
-static bool extended_statistics_update(FunctionCallInfo fcinfo);
+static bool extended_statistics_update(const NullableDatum *args);
 
 static HeapTuple get_pg_statistic_ext(Relation pg_stext, Oid nspoid,
 									  const char *stxname);
@@ -311,7 +311,7 @@ upsert_pg_statistic_ext_data(const Datum *values, const bool *nulls,
  * be updated.
  */
 static bool
-extended_statistics_update(FunctionCallInfo fcinfo)
+extended_statistics_update(const NullableDatum *args)
 {
 	char	   *relnspname;
 	char	   *relname;
@@ -356,12 +356,12 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 	 * Therefore, none of the three array values is meaningful unless the
 	 * other two are also present and in sync in terms of array length.
 	 */
-	has.mcv = (!PG_ARGISNULL(EXTARG_MOST_COMMON_VALS) &&
-			   !PG_ARGISNULL(EXTARG_MOST_COMMON_FREQS) &&
-			   !PG_ARGISNULL(EXTARG_MOST_COMMON_BASE_FREQS));
-	has.ndistinct = !PG_ARGISNULL(EXTARG_NDISTINCT);
-	has.dependencies = !PG_ARGISNULL(EXTARG_DEPENDENCIES);
-	has.expressions = !PG_ARGISNULL(EXTARG_EXPRESSIONS);
+	has.mcv = (!args[EXTARG_MOST_COMMON_VALS].isnull &&
+			   !args[EXTARG_MOST_COMMON_FREQS].isnull &&
+			   !args[EXTARG_MOST_COMMON_BASE_FREQS].isnull);
+	has.ndistinct = !args[EXTARG_NDISTINCT].isnull;
+	has.dependencies = !args[EXTARG_DEPENDENCIES].isnull;
+	has.expressions = !args[EXTARG_EXPRESSIONS].isnull;
 
 	if (RecoveryInProgress())
 	{
@@ -373,18 +373,18 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 	}
 
 	/* relation arguments */
-	stats_check_required_arg(fcinfo->args, extarginfo, EXTARG_RELSCHEMA);
-	relnspname = TextDatumGetCString(PG_GETARG_DATUM(EXTARG_RELSCHEMA));
-	stats_check_required_arg(fcinfo->args, extarginfo, EXTARG_RELNAME);
-	relname = TextDatumGetCString(PG_GETARG_DATUM(EXTARG_RELNAME));
+	stats_check_required_arg(args, extarginfo, EXTARG_RELSCHEMA);
+	relnspname = TextDatumGetCString(args[EXTARG_RELSCHEMA].value);
+	stats_check_required_arg(args, extarginfo, EXTARG_RELNAME);
+	relname = TextDatumGetCString(args[EXTARG_RELNAME].value);
 
 	/* extended statistics arguments */
-	stats_check_required_arg(fcinfo->args, extarginfo, EXTARG_STATSCHEMA);
-	nspname = TextDatumGetCString(PG_GETARG_DATUM(EXTARG_STATSCHEMA));
-	stats_check_required_arg(fcinfo->args, extarginfo, EXTARG_STATNAME);
-	stxname = TextDatumGetCString(PG_GETARG_DATUM(EXTARG_STATNAME));
-	stats_check_required_arg(fcinfo->args, extarginfo, EXTARG_INHERITED);
-	inherited = PG_GETARG_BOOL(EXTARG_INHERITED);
+	stats_check_required_arg(args, extarginfo, EXTARG_STATSCHEMA);
+	nspname = TextDatumGetCString(args[EXTARG_STATSCHEMA].value);
+	stats_check_required_arg(args, extarginfo, EXTARG_STATNAME);
+	stxname = TextDatumGetCString(args[EXTARG_STATNAME].value);
+	stats_check_required_arg(args, extarginfo, EXTARG_INHERITED);
+	inherited = DatumGetBool(args[EXTARG_INHERITED].value);
 
 	/*
 	 * First open the relation where we expect to find the statistics.  This
@@ -514,9 +514,9 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 	 */
 	if (!enabled.mcv)
 	{
-		if (!PG_ARGISNULL(EXTARG_MOST_COMMON_VALS) ||
-			!PG_ARGISNULL(EXTARG_MOST_COMMON_FREQS) ||
-			!PG_ARGISNULL(EXTARG_MOST_COMMON_BASE_FREQS))
+		if (!args[EXTARG_MOST_COMMON_VALS].isnull ||
+			!args[EXTARG_MOST_COMMON_FREQS].isnull ||
+			!args[EXTARG_MOST_COMMON_BASE_FREQS].isnull)
 		{
 			ereport(WARNING,
 					errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -538,9 +538,9 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 		 * statistics object expects something, something is wrong.  This
 		 * issues a WARNING if a partial input has been provided.
 		 */
-		if (!PG_ARGISNULL(EXTARG_MOST_COMMON_VALS) ||
-			!PG_ARGISNULL(EXTARG_MOST_COMMON_FREQS) ||
-			!PG_ARGISNULL(EXTARG_MOST_COMMON_BASE_FREQS))
+		if (!args[EXTARG_MOST_COMMON_VALS].isnull ||
+			!args[EXTARG_MOST_COMMON_FREQS].isnull ||
+			!args[EXTARG_MOST_COMMON_BASE_FREQS].isnull)
 		{
 			ereport(WARNING,
 					errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -655,7 +655,7 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 
 	if (has.ndistinct)
 	{
-		Datum		ndistinct_datum = PG_GETARG_DATUM(EXTARG_NDISTINCT);
+		Datum		ndistinct_datum = args[EXTARG_NDISTINCT].value;
 		bytea	   *data = DatumGetByteaPP(ndistinct_datum);
 		MVNDistinct *ndistinct = statext_ndistinct_deserialize(data);
 
@@ -674,7 +674,7 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 
 	if (has.dependencies)
 	{
-		Datum		dependencies_datum = PG_GETARG_DATUM(EXTARG_DEPENDENCIES);
+		Datum		dependencies_datum = args[EXTARG_DEPENDENCIES].value;
 		bytea	   *data = DatumGetByteaPP(dependencies_datum);
 		MVDependencies *dependencies = statext_dependencies_deserialize(data);
 
@@ -696,9 +696,9 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 		Datum		datum;
 		bool		val_ok = false;
 
-		datum = import_mcv(PG_GETARG_ARRAYTYPE_P(EXTARG_MOST_COMMON_VALS),
-						   PG_GETARG_ARRAYTYPE_P(EXTARG_MOST_COMMON_FREQS),
-						   PG_GETARG_ARRAYTYPE_P(EXTARG_MOST_COMMON_BASE_FREQS),
+		datum = import_mcv(DatumGetArrayTypeP(args[EXTARG_MOST_COMMON_VALS].value),
+						   DatumGetArrayTypeP(args[EXTARG_MOST_COMMON_FREQS].value),
+						   DatumGetArrayTypeP(args[EXTARG_MOST_COMMON_BASE_FREQS].value),
 						   atttypids, atttypmods, atttypcolls, numattrs,
 						   &val_ok);
 
@@ -733,7 +733,7 @@ extended_statistics_update(FunctionCallInfo fcinfo)
 								   &atttypids[numattnums],
 								   &atttypmods[numattnums],
 								   &atttypcolls[numattnums],
-								   PG_GETARG_JSONB_P(EXTARG_EXPRESSIONS),
+								   DatumGetJsonbP(args[EXTARG_EXPRESSIONS].value),
 								   &ok);
 
 		table_close(pgsd, RowExclusiveLock);
@@ -1744,7 +1744,7 @@ pg_restore_extended_stats(PG_FUNCTION_ARGS)
 	if (!stats_fill_fcinfo_from_arg_pairs(fcinfo, positional_fcinfo, extarginfo))
 		result = false;
 
-	if (!extended_statistics_update(positional_fcinfo))
+	if (!extended_statistics_update(positional_fcinfo->args))
 		result = false;
 
 	PG_RETURN_BOOL(result);
-- 
2.50.1 (Apple Git-155)

