From c1ce464684b1f475adcad14e934060dc20dabe15 Mon Sep 17 00:00:00 2001
From: Denis Rodionov <denis.rodionov@tantorlabs.ru>
Date: Thu, 4 Jun 2026 20:23:07 +0300
Subject: [PATCH v2] Remove obsolete tupDesc assignment in extended statistics

lookup_var_attr_stats() assigned tupDesc to VacAttrStats entries built for
expressions.  That appears to be obsolete: make_build_data() uses tupDesc only
for regular columns, while expression values are evaluated separately.

Remove the assignment and add an assertion documenting that expression stats
do not need a tuple descriptor.
---
 src/backend/statistics/extended_stats.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index 2b83355d26e..f812cea41e3 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -786,12 +786,10 @@ lookup_var_attr_stats(Bitmapset *attrs, List *exprs,
 		}
 
 		/*
-		 * XXX We need tuple descriptor later, and we just grab it from
-		 * stats[0]->tupDesc (see e.g. statext_mcv_build). But as coded
-		 * examine_attribute does not set that, so just grab it from the first
-		 * vacatts element.
+		 * Expression stats are not tied to a heap attribute, so they do not
+		 * need a tuple descriptor.
 		 */
-		stats[i]->tupDesc = vacatts[0]->tupDesc;
+		Assert(stats[i]->tupDesc == NULL);
 
 		i++;
 	}
-- 
2.34.1

