Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

Поиск
Список
Период
Сортировка
Искать

Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Atisss hh <125atishprak@gmail.com>
Дата:
Вложения:


On Sat, 7 Nov 2026 at 21:07, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      19849
Logged by:          Atish Prakash
Email address:      125atishprak@gmail.com
PostgreSQL version: 18.6
Operating system:   Linux x86_64
Description:       

With extended statistics on an array or tsvector expression, once ANALYZE
finds no
elements common enough to store, queries that use the statistics fail at
planning
time with an internal error. Elements that are all distinct are enough to
trigger
this, as is a column of empty arrays.

    CREATE TABLE tags(id int, a int[]);
    INSERT INTO tags
        SELECT i, ARRAY[i, i + 1000000] FROM generate_series(1, 50000) i;
    CREATE STATISTICS s_a ON (a || a) FROM tags;
    ANALYZE tags;

    SELECT count(*) FROM tags WHERE (a || a) @> '{5}';

Actual, on 19rc1 and master:

    ERROR:  unexpected null value in cached tuple for catalog pg_statistic
column stavalues3

Expected, as on 18.6: the query runs and returns 1.

Also failing the same way:
- (t || t) on text[], with @>
- (v || v) on tsvector, with @@ (the message names stavalues1)
- the array operators && and <@, and = ANY

A range expression with no non-empty values also stores a NULL stavalues,
but the
query I tried, (a * a) && '[1,2)', did not fail.

A plain column with the same data, and an expression index with the same
data, do
not fail.

Cause: commit 261f89a976 ("Track the maximum possible frequency of non-MCE
array
elements") stores a statistics slot even when there are no values. It
changed the
test in update_attstats() from numvalues > 0 to stavalues != NULL, but
serialize_expr_stats() in extended_stats.c still tests numvalues[k] > 0, so
the slot
kind and numbers are stored with a NULL stavalues. get_attstatsslot() then
fails in
SysCacheGetAttrNotNull(). I identified the commit from the code and the
commit
message, and did not bisect.

A possible patch is attached
(0001-fix-expression-stats-empty-stavalues.patch). It
changes that test to match update_attstats(). With it, the queries above
return
correct results on master, and all 239 core regression tests pass. It adds
no new
test.

Found with statistics round-trip tests. I reproduced and checked the result
myself.


Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
shihao zhong <zhong950419@gmail.com>
Дата:
Вложения:
Hi,

Thanks for the report and the patch, Atish. I can reproduce it on
master and 19rc1, and 18 works.

0001 is your fix plus the same change for stanumbers. Now
serialize_expr_stats() matches update_attstats() again. 

0002 adds a test to stats_ext with empty arrays and tsvectors.

This came with 261f89a976b, so it should go to 19 too.

Thanks,
Shihao

Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Michael Paquier <michael@paquier.xyz>
Дата:
Вложения:
On Mon, Nov 09, 2026 at 12:10:33AM -0500, shihao zhong wrote:
> Thanks for the report and the patch, Atish. I can reproduce it on
> master and 19rc1, and 18 works.
> 
> 0001 is your fix plus the same change for stanumbers. Now
> serialize_expr_stats() matches update_attstats() again.
> 
> 0002 adds a test to stats_ext with empty arrays and tsvectors.
> 
> This came with 261f89a976b, so it should go to 19 too.

Hmm, yeah, that looks like an oversight in the serialization of the
expression stats, and we should map to a non-NULL check.  I would not
call this error a expected:
ERROR:  unexpected null value in cached tuple for catalog pg_statistic
column stavalues1

FWIW, I have been puzzled by this failure while looking a bit at the
surroundings of this code for a different bug, just today. when
dealing with empty arrays for MCEs:
https://www.postgresql.org/message-id/avFaBdhb4ONGhIjH%40paquier.xyz
And then noted that this thread already reported something..

Tom, any thoughts?
--
Michael

Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Michael Paquier  writes:
> On Mon, Nov 09, 2026 at 12:10:33AM -0500, shihao zhong wrote:
>> 0001 is your fix plus the same change for stanumbers. Now
>> serialize_expr_stats() matches update_attstats() again.

Ugh.

> Tom, any thoughts?

I think it's unfortunate that we have two copies of largely the same
code that have to be kept in sync.  At the very least we ought to
install comments warning of that in both places.  But I wonder if
it's practical to refactor so that there's just one copy?

			regards, tom lane


Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
shihao zhong <zhong950419@gmail.com>
Дата:
Вложения:
Hi folks,

Thanks for reviewing my patch. 

> But I wonder if
> it's practical to refactor so that there's just one copy?

Thanks, Tom. The refactor turned out to be small. The code that fills
in the pg_statistic columns can move into one function in analyze.c,
and both places call it.

v3-00x goes to master 
v3-REL_19 goes to 19

Thanks,
Shihao


Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Michael Paquier <michael@paquier.xyz>
Дата:
Вложения:
On Mon, Nov 09, 2026 at 06:09:19PM -0500, shihao zhong wrote:
> Thanks, Tom. The refactor turned out to be small. The code that fills
> in the pg_statistic columns can move into one function in analyze.c,
> and both places call it.

v3-0003's code cut looks tempting.  That would have prevented the
original issue.

@@ -2333,12 +2333,7 @@ build_expr_data(List *exprs, int stattarget)
         values[Anum_pg_statistic_starelid - 1] = ObjectIdGetDatum(InvalidOid);
         values[Anum_pg_statistic_staattnum - 1] = Int16GetDatum(InvalidAttrNumber);
         values[Anum_pg_statistic_stainherit - 1] = BoolGetDatum(false);
[...]
@@ -1764,79 +1843,15 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
         values[Anum_pg_statistic_starelid - 1] = ObjectIdGetDatum(relid);
         values[Anum_pg_statistic_staattnum - 1] = Int16GetDatum(stats->tupattnum);
         values[Anum_pg_statistic_stainherit - 1] = BoolGetDatum(inh);

These two could also be passed down as arguments of your new
fill_attstats_values(), filling them within the routine instead of
letting the two callers do it.

+ * values[] and nulls[] must have room for Natts_pg_statistic entries.  All

One thing that always stresses me with this kind of assumption is that
an error means an out-of-bound write, and a CVE.  Here, we could also
use a palloc0'ed area worth Natts_pg_statistic, instead of expecting
the caller to do the right thing.  The ANALYZE and expression stats
code paths are not performance-critical.  Or ubsan would just catch
any problems?
--
Michael

Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Michael Paquier  writes:
> These two could also be passed down as arguments of your new
> fill_attstats_values(), filling them within the routine instead of
> letting the two callers do it.
> + * values[] and nulls[] must have room for Natts_pg_statistic entries.  All
> One thing that always stresses me with this kind of assumption is that
> an error means an out-of-bound write, and a CVE.  Here, we could also
> use a palloc0'ed area worth Natts_pg_statistic, instead of expecting
> the caller to do the right thing.  The ANALYZE and expression stats
> code paths are not performance-critical.  Or ubsan would just catch
> any problems?

Yeah, I didn't love this particular refactorization either.  I think
it'd be nicer to have the values[] and nulls[] arrays totally inside
the shared function and do the tuple-building within it, as attached.

One thing that bugs me slightly about this is that it seems weird to
be passing starelid and stainherit explicitly while digging staattnum
out of the VacAttrStats struct.  It works, because examine_expression
is careful to set stats->tupattnum = InvalidAttrNumber, but maybe
it would be cleaner to pass all three parts of the primary key as
explicit arguments.  Does anyone else feel that way?

			regards, tom lane

From 32f2fe04e43f57cdff4f0adec0af6d7bdb909e75 Mon Sep 17 00:00:00 2001
From: Tom Lane 
Date: Tue, 10 Nov 2026 13:43:27 -0500
Subject: [PATCH v4] Store empty stavalues when needed for expression
 statistics.

Commit 261f89a97 changed the API contract for update_attstats()
to store an empty array, not a NULL, if it's passed a nonnull
stavalues pointer along with a zero values count.  We missed
that serialize_expr_stats() needs to be kept in sync with that,
so that we now get "unexpected null value" errors if statistics
on an expression hit one of the cases where the statistics
collection code requests that.

Rather than just adjusting serialize_expr_stats() to match, let's
avoid having duplicated code at all, by factoring out a routine
to build a pg_statistic tuple from a VacAttrStats structure.

Bug: #19849
Reported-by: Atish Prakash <125atishprak@gmail.com>
Author: Atish Prakash <125atishprak@gmail.com>
Co-authored-by: Shihao Zhong 
Co-authored-by: Tom Lane 
Discussion: https://postgr.es/m/19849-38b8bd2fea807154@postgresql.org
Backpatch-through: 19
---
 src/backend/commands/analyze.c          | 201 ++++++++++++++----------
 src/backend/statistics/extended_stats.c |  84 +---------
 src/include/commands/vacuum.h           |   4 +
 3 files changed, 122 insertions(+), 167 deletions(-)

diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 518d7526255..01efa78cf76 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -1713,6 +1713,115 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
 }
 
 
+/*
+ * build_statistic_tuple() -- build a pg_statistic tuple from a VacAttrStats
+ *
+ * relid is the Oid of the table being analyzed, inh indicates if these are
+ * inheritance-tree or table-only stats, stats contains the collected stats
+ * including the column number.
+ *
+ * tupdesc must be a tuple descriptor for pg_statistic.  oldtup is the
+ * existing pg_statistic tuple we intend to replace, or NULL to build
+ * a new pg_statistic tuple.
+ *
+ * This is exported so that extended_stats.c can use it.  (In that usage,
+ * relid is InvalidOid, so don't trust it for anything.)
+ */
+HeapTuple
+build_statistic_tuple(Oid relid, bool inh,
+					  VacAttrStats *stats,
+					  TupleDesc tupdesc,
+					  HeapTuple oldtup)
+{
+	HeapTuple	stup;
+	Datum		values[Natts_pg_statistic];
+	bool		nulls[Natts_pg_statistic];
+	bool		replaces[Natts_pg_statistic];
+	int			i,
+				k;
+
+	for (i = 0; i < Natts_pg_statistic; ++i)
+	{
+		nulls[i] = false;
+		replaces[i] = true;
+	}
+
+	values[Anum_pg_statistic_starelid - 1] = ObjectIdGetDatum(relid);
+	values[Anum_pg_statistic_staattnum - 1] = Int16GetDatum(stats->tupattnum);
+	values[Anum_pg_statistic_stainherit - 1] = BoolGetDatum(inh);
+	values[Anum_pg_statistic_stanullfrac - 1] = Float4GetDatum(stats->stanullfrac);
+	values[Anum_pg_statistic_stawidth - 1] = Int32GetDatum(stats->stawidth);
+	values[Anum_pg_statistic_stadistinct - 1] = Float4GetDatum(stats->stadistinct);
+	i = Anum_pg_statistic_stakind1 - 1;
+	for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
+	{
+		values[i++] = Int16GetDatum(stats->stakind[k]); /* stakindN */
+	}
+	i = Anum_pg_statistic_staop1 - 1;
+	for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
+	{
+		values[i++] = ObjectIdGetDatum(stats->staop[k]);	/* staopN */
+	}
+	i = Anum_pg_statistic_stacoll1 - 1;
+	for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
+	{
+		values[i++] = ObjectIdGetDatum(stats->stacoll[k]);	/* stacollN */
+	}
+	i = Anum_pg_statistic_stanumbers1 - 1;
+	for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
+	{
+		if (stats->stanumbers[k] != NULL)
+		{
+			int			nnum = stats->numnumbers[k];
+			Datum	   *numdatums = palloc_array(Datum, nnum);
+			ArrayType  *arry;
+
+			for (int n = 0; n < nnum; n++)
+				numdatums[n] = Float4GetDatum(stats->stanumbers[k][n]);
+			arry = construct_array_builtin(numdatums, nnum, FLOAT4OID);
+			values[i++] = PointerGetDatum(arry);	/* stanumbersN */
+		}
+		else
+		{
+			nulls[i] = true;
+			values[i++] = (Datum) 0;
+		}
+	}
+	i = Anum_pg_statistic_stavalues1 - 1;
+	for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
+	{
+		if (stats->stavalues[k] != NULL)
+		{
+			ArrayType  *arry;
+
+			arry = construct_array(stats->stavalues[k],
+								   stats->numvalues[k],
+								   stats->statypid[k],
+								   stats->statyplen[k],
+								   stats->statypbyval[k],
+								   stats->statypalign[k]);
+			values[i++] = PointerGetDatum(arry);	/* stavaluesN */
+		}
+		else
+		{
+			nulls[i] = true;
+			values[i++] = (Datum) 0;
+		}
+	}
+
+	/* Build a replacement or all-new tuple */
+	if (HeapTupleIsValid(oldtup))
+		stup = heap_modify_tuple(oldtup,
+								 tupdesc,
+								 values,
+								 nulls,
+								 replaces);
+	else
+		stup = heap_form_tuple(tupdesc, values, nulls);
+
+	return stup;
+}
+
 /*
  *	update_attstats() -- update attribute statistics for one relation
  *
@@ -1752,88 +1861,14 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
 		VacAttrStats *stats = vacattrstats[attno];
 		HeapTuple	stup,
 					oldtup;
-		int			i,
-					k,
-					n;
-		Datum		values[Natts_pg_statistic];
-		bool		nulls[Natts_pg_statistic];
-		bool		replaces[Natts_pg_statistic];
 
 		/* Ignore attr if we weren't able to collect stats */
 		if (!stats->stats_valid)
 			continue;
 
-		/*
-		 * Construct a new pg_statistic tuple
-		 */
-		for (i = 0; i < Natts_pg_statistic; ++i)
-		{
-			nulls[i] = false;
-			replaces[i] = true;
-		}
-
-		values[Anum_pg_statistic_starelid - 1] = ObjectIdGetDatum(relid);
-		values[Anum_pg_statistic_staattnum - 1] = Int16GetDatum(stats->tupattnum);
-		values[Anum_pg_statistic_stainherit - 1] = BoolGetDatum(inh);
-		values[Anum_pg_statistic_stanullfrac - 1] = Float4GetDatum(stats->stanullfrac);
-		values[Anum_pg_statistic_stawidth - 1] = Int32GetDatum(stats->stawidth);
-		values[Anum_pg_statistic_stadistinct - 1] = Float4GetDatum(stats->stadistinct);
-		i = Anum_pg_statistic_stakind1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			values[i++] = Int16GetDatum(stats->stakind[k]); /* stakindN */
-		}
-		i = Anum_pg_statistic_staop1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			values[i++] = ObjectIdGetDatum(stats->staop[k]);	/* staopN */
-		}
-		i = Anum_pg_statistic_stacoll1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			values[i++] = ObjectIdGetDatum(stats->stacoll[k]);	/* stacollN */
-		}
-		i = Anum_pg_statistic_stanumbers1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			if (stats->stanumbers[k] != NULL)
-			{
-				int			nnum = stats->numnumbers[k];
-				Datum	   *numdatums = palloc_array(Datum, nnum);
-				ArrayType  *arry;
-
-				for (n = 0; n < nnum; n++)
-					numdatums[n] = Float4GetDatum(stats->stanumbers[k][n]);
-				arry = construct_array_builtin(numdatums, nnum, FLOAT4OID);
-				values[i++] = PointerGetDatum(arry);	/* stanumbersN */
-			}
-			else
-			{
-				nulls[i] = true;
-				values[i++] = (Datum) 0;
-			}
-		}
-		i = Anum_pg_statistic_stavalues1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			if (stats->stavalues[k] != NULL)
-			{
-				ArrayType  *arry;
-
-				arry = construct_array(stats->stavalues[k],
-									   stats->numvalues[k],
-									   stats->statypid[k],
-									   stats->statyplen[k],
-									   stats->statypbyval[k],
-									   stats->statypalign[k]);
-				values[i++] = PointerGetDatum(arry);	/* stavaluesN */
-			}
-			else
-			{
-				nulls[i] = true;
-				values[i++] = (Datum) 0;
-			}
-		}
+		/* Open index information when we know we need it */
+		if (indstate == NULL)
+			indstate = CatalogOpenIndexes(sd);
 
 		/* Is there already a pg_statistic tuple for this attribute? */
 		oldtup = SearchSysCache3(STATRELATTINH,
@@ -1841,25 +1876,19 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
 								 Int16GetDatum(stats->tupattnum),
 								 BoolGetDatum(inh));
 
-		/* Open index information when we know we need it */
-		if (indstate == NULL)
-			indstate = CatalogOpenIndexes(sd);
+		/* Build the new or replacement tuple */
+		stup = build_statistic_tuple(relid, inh, stats,
+									 RelationGetDescr(sd), oldtup);
 
 		if (HeapTupleIsValid(oldtup))
 		{
 			/* Yes, replace it */
-			stup = heap_modify_tuple(oldtup,
-									 RelationGetDescr(sd),
-									 values,
-									 nulls,
-									 replaces);
 			ReleaseSysCache(oldtup);
 			CatalogTupleUpdateWithInfo(sd, &stup->t_self, stup, indstate);
 		}
 		else
 		{
 			/* No, insert new tuple */
-			stup = heap_form_tuple(RelationGetDescr(sd), values, nulls);
 			CatalogTupleInsertWithInfo(sd, stup, indstate);
 		}
 
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index b66a49a6fb5..da5e7264d25 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -2333,14 +2333,13 @@ build_expr_data(List *exprs, int stattarget)
 	return exprdata;
 }
 
-/* form an array of pg_statistic rows (per update_attstats) */
+/* form an array of pg_statistic rows, one per expression */
 static Datum
 serialize_expr_stats(AnlExprData *exprdata, int nexprs)
 {
 	int			exprno;
 	Oid			typOid;
 	Relation	sd;
-
 	ArrayBuildState *astate = NULL;
 
 	sd = table_open(StatisticRelationId, RowExclusiveLock);
@@ -2355,12 +2354,7 @@ serialize_expr_stats(AnlExprData *exprdata, int nexprs)
 
 	for (exprno = 0; exprno < nexprs; exprno++)
 	{
-		int			i,
-					k;
 		VacAttrStats *stats = exprdata[exprno].vacattrstat;
-
-		Datum		values[Natts_pg_statistic];
-		bool		nulls[Natts_pg_statistic];
 		HeapTuple	stup;
 
 		if (!stats->stats_valid)
@@ -2373,80 +2367,8 @@ serialize_expr_stats(AnlExprData *exprdata, int nexprs)
 			continue;
 		}
 
-		/*
-		 * Construct a new pg_statistic tuple
-		 */
-		for (i = 0; i < Natts_pg_statistic; ++i)
-		{
-			nulls[i] = false;
-		}
-
-		values[Anum_pg_statistic_starelid - 1] = ObjectIdGetDatum(InvalidOid);
-		values[Anum_pg_statistic_staattnum - 1] = Int16GetDatum(InvalidAttrNumber);
-		values[Anum_pg_statistic_stainherit - 1] = BoolGetDatum(false);
-		values[Anum_pg_statistic_stanullfrac - 1] = Float4GetDatum(stats->stanullfrac);
-		values[Anum_pg_statistic_stawidth - 1] = Int32GetDatum(stats->stawidth);
-		values[Anum_pg_statistic_stadistinct - 1] = Float4GetDatum(stats->stadistinct);
-		i = Anum_pg_statistic_stakind1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			values[i++] = Int16GetDatum(stats->stakind[k]); /* stakindN */
-		}
-		i = Anum_pg_statistic_staop1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			values[i++] = ObjectIdGetDatum(stats->staop[k]);	/* staopN */
-		}
-		i = Anum_pg_statistic_stacoll1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			values[i++] = ObjectIdGetDatum(stats->stacoll[k]);	/* stacollN */
-		}
-		i = Anum_pg_statistic_stanumbers1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			int			nnum = stats->numnumbers[k];
-
-			if (nnum > 0)
-			{
-				int			n;
-				Datum	   *numdatums = palloc_array(Datum, nnum);
-				ArrayType  *arry;
-
-				for (n = 0; n < nnum; n++)
-					numdatums[n] = Float4GetDatum(stats->stanumbers[k][n]);
-				arry = construct_array_builtin(numdatums, nnum, FLOAT4OID);
-				values[i++] = PointerGetDatum(arry);	/* stanumbersN */
-			}
-			else
-			{
-				nulls[i] = true;
-				values[i++] = (Datum) 0;
-			}
-		}
-		i = Anum_pg_statistic_stavalues1 - 1;
-		for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
-		{
-			if (stats->numvalues[k] > 0)
-			{
-				ArrayType  *arry;
-
-				arry = construct_array(stats->stavalues[k],
-									   stats->numvalues[k],
-									   stats->statypid[k],
-									   stats->statyplen[k],
-									   stats->statypbyval[k],
-									   stats->statypalign[k]);
-				values[i++] = PointerGetDatum(arry);	/* stavaluesN */
-			}
-			else
-			{
-				nulls[i] = true;
-				values[i++] = (Datum) 0;
-			}
-		}
-
-		stup = heap_form_tuple(RelationGetDescr(sd), values, nulls);
+		stup = build_statistic_tuple(InvalidOid, false, stats,
+									 RelationGetDescr(sd), NULL);
 
 		astate = accumArrayResult(astate,
 								  heap_copy_tuple_as_datum(stup, RelationGetDescr(sd)),
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index 89fa1fcd261..3bcb7113762 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -441,6 +441,10 @@ extern void analyze_rel(Oid relid, RangeVar *relation,
 						BufferAccessStrategy bstrategy);
 extern bool attribute_is_analyzable(Relation onerel, int attnum, Form_pg_attribute attr,
 									int *p_attstattarget);
+extern HeapTuple build_statistic_tuple(Oid relid, bool inh,
+									   VacAttrStats *stats,
+									   TupleDesc tupdesc,
+									   HeapTuple oldtup);
 extern bool std_typanalyze(VacAttrStats *stats);
 
 /* in utils/misc/sampling.c --- duplicate of declarations in utils/sampling.h */
-- 
2.52.0

Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Michael Paquier <michael@paquier.xyz>
Дата:
Вложения:
On Tue, Nov 10, 2026 at 01:53:01PM -0500, Tom Lane wrote:
> Yeah, I didn't love this particular refactorization either.  I think
> it'd be nicer to have the values[] and nulls[] arrays totally inside
> the shared function and do the tuple-building within it, as attached.

Including the tuple build in the routine sounds good here.  That takes
care of my worries with the previous patch.

> One thing that bugs me slightly about this is that it seems weird to
> be passing starelid and stainherit explicitly while digging staattnum
> out of the VacAttrStats struct.  It works, because examine_expression
> is careful to set stats->tupattnum = InvalidAttrNumber, but maybe
> it would be cleaner to pass all three parts of the primary key as
> explicit arguments.  Does anyone else feel that way?

None here.  Passing down tupattnum as an argument coming from "stats"
also felt a bit strange..
--
Michael

Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
shihao zhong <zhong950419@gmail.com>
Дата:
Hi Tom,

Thanks for v4. Keeping the arrays inside the function is nicer than
my version.

> Does anyone else feel that way?
I’d pass all three key columns because it is weird that two come from the
arguments and one comes from stats.

Thanks,
Shihao



Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
shihao zhong  writes:
>> Does anyone else feel that way?

> I’d pass all three key columns because it is weird that two come from the
> arguments and one comes from stats.

Done like that, then.

			regards, tom lane


Re: BUG #19849: queries fail after ANALYZE with expression stats on arrays

От:
Michael Paquier <michael@paquier.xyz>
Дата:
Вложения:
On Wed, Nov 11, 2026 at 11:05:19AM -0500, Tom Lane wrote:
> Done like that, then.

Thanks.
--
Michael
FAQ