Skip to content

Commit f386291

Browse files
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.
1 parent 9c8351f commit f386291

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/backend/commands/analyze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,7 @@ process_sample_rows(Portal portal,
27532753

27542754
if (!attr->attisdropped)
27552755
{
2756-
TupleDescInitEntry(funcTupleDesc, (AttrNumber) 4 + index, "",
2756+
TupleDescInitEntry(funcTupleDesc, (AttrNumber) NUM_SAMPLE_FIXED_COLS + 1 + index, "",
27572757
typid, attr->atttypmod, attr->attndims);
27582758

27592759
index++;

0 commit comments

Comments
 (0)