Analysis: Trivial Comment Fix in pgstat_assoc_relation()
Core Problem
This is a minor code hygiene issue in PostgreSQL's statistics subsystem. The function pgstat_assoc_relation() contains a comment that begins with "Else find or make the PgStat_TableStatus entry, and update link". The word "Else" is a vestigial artifact from when this code was part of a larger function (pgstat_init_relation()), where the comment made sense as part of an if/else control flow narrative. After commit 5891c7a8ed8f refactored the code by splitting pgstat_assoc_relation() out as its own function, the "Else" prefix no longer has any logical antecedent within the function's scope and is misleading to readers.
Technical Context
The pgstat Subsystem
PostgreSQL's pgstat (statistics collector) subsystem tracks per-relation activity statistics (tuples inserted, updated, deleted, sequential/index scans, etc.). These statistics are critical for the autovacuum launcher and for the query planner's cost estimation.
Key structures involved:
- PgStat_TableStatus: A per-relation structure that accumulates statistics changes during a transaction (counts of inserts, updates, deletes, etc.)
- pgstat_assoc_relation(): Associates a relation (opened table) with its corresponding
PgStat_TableStatusentry, establishing the link that allows DML operations to efficiently update statistics counters. - pgstat_init_relation(): Initializes statistics tracking for a relation when it's first opened in a transaction.
The Refactoring (Commit 5891c7a8ed8f)
The original pgstat_init_relation() likely had a structure like:
if (some_condition) {
/* Handle case where relation already has stats entry */
...
} else {
/* Else find or make the PgStat_TableStatus entry, and update link */
...
}
When the "else" branch was extracted into pgstat_assoc_relation(), the comment was copied verbatim without updating it to reflect its new standalone context. The fix is trivially removing the word "Else" from the comment.
Proposed Solution
Remove the word "Else" from the comment, changing:
/* Else find or make the PgStat_TableStatus entry, and update link */
to:
/* Find or make the PgStat_TableStatus entry, and update link */
Significance
While the fix itself is trivial (a single-word deletion), it represents good code maintenance practice:
- Readability: Comments that reference non-existent control flow confuse new contributors trying to understand the code.
- Refactoring hygiene: When code is moved between functions, comments should be updated to match the new context.
- Low risk: This change has zero functional impact, making it a safe cleanup.
Assessment
This is a straightforward cosmetic fix that would typically be applied by a committer as a trivial patch without requiring formal review or a commitfest entry. It requires no testing beyond compilation verification. The patch is uncontroversial and likely to be committed quickly, possibly as part of a batch of small cleanups.