Hi hackers,

Attached is a small cleanup patch for extended statistics.

lookup_var_attr_stats() assigns tupDesc to VacAttrStats entries created for expressions. That appears to be obsolete: make_build_data() uses tupDesc only when fetching values for regular columns, while expressions are handled separately using VacAttrStats entries created by examine_expression().

The old comment also points at statext_mcv_build(), but this does not seem to match the current code anymore. If some future code needs a tuple descriptor for expression entries here, it should probably set up that dependency explicitly rather than rely on copying vacatts[0]->tupDesc.

The patch removes the assignment and the outdated XXX comment.

Best regards,
Denis Rodionov
Tantor Labs LLC,
https://tantorlabs.com/
From 5c092b86955f9df47e02e393c1ee5a4bf6e6c79c Mon Sep 17 00:00:00 2001
From: Denis Rodionov <[email protected]>
Date: Thu, 28 May 2026 17:56:09 +0300
Subject: [PATCH v1] Remove obsolete tupDesc assignment in extended statistics

lookup_var_attr_stats() assigns tupDesc to VacAttrStats entries built for
expressions. This appears to be obsolete.

make_build_data() uses tupDesc only for regular columns, when fetching
attribute values from sample rows. For expressions, it creates separate
VacAttrStats entries with examine_expression(), so the entries built by
lookup_var_attr_stats() do not need tupDesc.

Remove the assignment and the outdated XXX comment.
---
 src/backend/statistics/extended_stats.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index 2b83355d26e..049933896b4 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -785,14 +785,6 @@ lookup_var_attr_stats(Bitmapset *attrs, List *exprs,
 			return NULL;
 		}
 
-		/*
-		 * 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.
-		 */
-		stats[i]->tupDesc = vacatts[0]->tupDesc;
-
 		i++;
 	}
 
-- 
2.34.1

Reply via email to