Fix incorrect usage of TupleDescSize() in #7950, #8120, #8124, #8121 and #8114 (#8146)

In #7950, #8120, #8124, #8121 and #8114, TupleDescSize() was used to
check whether the tuple length is `Natts_<catalog_table_name>`. However
this was wrong because TupleDescSize() returns the size of the
tupledesc, not the length of it (i.e., number of attributes).

Actually `TupleDescSize(tupleDesc) == Natts_<catalog_table_name>` was
always returning false but this didn't cause any problems because using
`tupleDesc->natts - 1` when `tupleDesc->natts ==
Natts_<catalog_table_name>` too had the same effect as using
`Anum_<column_added_later> - 1` in that case.

So this also makes me thinking of always returning `tupleDesc->natts -
1` (or `tupleDesc->natts - 2` if it's the second to last attribute) but
being more explicit seems more useful.

Even more, in the future we should probably switch to a different
implementation if / when we think of adding more columns to those
tables. We should probably scan non-dropped attributes of the relation,
enumerate them and return the attribute number of the one that we're
looking for, but seems this is not needed right now.
pull/8147/head
Onur Tirtir 2025-08-22 14:46:06 +03:00 committed by GitHub
parent 785287c58f
commit 439870f3a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 6 deletions

View File

@ -36,7 +36,7 @@
* Fixes potential memory corruptions that could happen when accessing * Fixes potential memory corruptions that could happen when accessing
various catalog tables after a Citus downgrade is followed by a Citus various catalog tables after a Citus downgrade is followed by a Citus
upgrade (#7950, #8120, #8124, #8121, #8114) upgrade (#7950, #8120, #8124, #8121, #8114, #8146)
* Fixes UPDATE statements with indirection and array/jsonb subscripting with * Fixes UPDATE statements with indirection and array/jsonb subscripting with
more than one field (#7675) more than one field (#7675)

View File

@ -2132,7 +2132,7 @@ GetHighestUsedRowNumber(uint64 storageId)
static int static int
GetFirstRowNumberAttrIndexInColumnarStripe(TupleDesc tupleDesc) GetFirstRowNumberAttrIndexInColumnarStripe(TupleDesc tupleDesc)
{ {
return TupleDescSize(tupleDesc) == Natts_columnar_stripe return tupleDesc->natts == Natts_columnar_stripe
? (Anum_columnar_stripe_first_row_number - 1) ? (Anum_columnar_stripe_first_row_number - 1)
: tupleDesc->natts - 1; : tupleDesc->natts - 1;
} }

View File

@ -801,7 +801,7 @@ DistributedSequenceList(void)
int int
GetForceDelegationAttrIndexInPgDistObject(TupleDesc tupleDesc) GetForceDelegationAttrIndexInPgDistObject(TupleDesc tupleDesc)
{ {
return TupleDescSize(tupleDesc) == Natts_pg_dist_object return tupleDesc->natts == Natts_pg_dist_object
? (Anum_pg_dist_object_force_delegation - 1) ? (Anum_pg_dist_object_force_delegation - 1)
: tupleDesc->natts - 1; : tupleDesc->natts - 1;
} }

View File

@ -4486,7 +4486,7 @@ UnblockDependingBackgroundTasks(BackgroundTask *task)
int int
GetAutoConvertedAttrIndexInPgDistPartition(TupleDesc tupleDesc) GetAutoConvertedAttrIndexInPgDistPartition(TupleDesc tupleDesc)
{ {
return TupleDescSize(tupleDesc) == Natts_pg_dist_partition return tupleDesc->natts == Natts_pg_dist_partition
? (Anum_pg_dist_partition_autoconverted - 1) ? (Anum_pg_dist_partition_autoconverted - 1)
: tupleDesc->natts - 1; : tupleDesc->natts - 1;
} }
@ -4506,7 +4506,7 @@ GetAutoConvertedAttrIndexInPgDistPartition(TupleDesc tupleDesc)
int int
GetNodesInvolvedAttrIndexInPgDistBackgroundTask(TupleDesc tupleDesc) GetNodesInvolvedAttrIndexInPgDistBackgroundTask(TupleDesc tupleDesc)
{ {
return TupleDescSize(tupleDesc) == Natts_pg_dist_background_task return tupleDesc->natts == Natts_pg_dist_background_task
? (Anum_pg_dist_background_task_nodes_involved - 1) ? (Anum_pg_dist_background_task_nodes_involved - 1)
: tupleDesc->natts - 1; : tupleDesc->natts - 1;
} }

View File

@ -685,7 +685,7 @@ DeleteWorkerTransactions(WorkerNode *workerNode)
int int
GetOuterXidAttrIndexInPgDistTransaction(TupleDesc tupleDesc) GetOuterXidAttrIndexInPgDistTransaction(TupleDesc tupleDesc)
{ {
return TupleDescSize(tupleDesc) == Natts_pg_dist_transaction return tupleDesc->natts == Natts_pg_dist_transaction
? (Anum_pg_dist_transaction_outerxid - 1) ? (Anum_pg_dist_transaction_outerxid - 1)
: tupleDesc->natts - 1; : tupleDesc->natts - 1;
} }