From b320e6ad5228eead2b9c95f54815d987853ba7f8 Mon Sep 17 00:00:00 2001 From: zhangyue Date: Sat, 23 Aug 2025 12:15:12 +0800 Subject: [PATCH] Fix incorrect column number in funcTupleDesc initialization. In process_sample_rows(), when initializing funcTupleDesc for table columns, the column number should start from NUM_SAMPLE_FIXED_COLS + 1 (5) instead of 4. The first 4 columns (1-4) are reserved for fixed columns: - Column 1: totalrows (FLOAT8OID) - Column 2: totaldeadrows (FLOAT8OID) - Column 3: oversized_cols_length (FLOAT8ARRAYOID) - Column 4: NDV array (FLOAT8ARRAYOID) Table columns should start from column 5, so the correct formula is: (AttrNumber) NUM_SAMPLE_FIXED_COLS + 1 + index This bug is harmless because funcTupleDesc's column type information is not actually used in subsequent processing - only the column count (natts) is used. The actual type information is obtained dynamically via lookup_rowtype_tupdesc(). However, it's still worth fixing for code correctness and maintainability. --- src/backend/commands/analyze.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index ce642dc84e7..423ad51cf89 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -2758,7 +2758,7 @@ process_sample_rows(Portal portal, if (!attr->attisdropped) { - TupleDescInitEntry(funcTupleDesc, (AttrNumber) 4 + index, "", + TupleDescInitEntry(funcTupleDesc, (AttrNumber) NUM_SAMPLE_FIXED_COLS + 1 + index, "", typid, attr->atttypmod, attr->attndims); index++;