pgsql: Change pgstat_report_vacuum() to use Relation

2025-12-16 Thread Michael Paquier
Change pgstat_report_vacuum() to use Relation This change makes pgstat_report_vacuum() more consistent with pgstat_report_analyze(), that also uses a Relation. This enforces a policy that callers of this routine should open and lock the relation whose statistics are updated before calling this ro

pgsql: Reorder two functions in inval.c

2025-12-16 Thread Noah Misch
Reorder two functions in inval.c This file separates public and static functions with a separator comment, but two routines were not defined in a location reflecting that, so reorder them. Back-patch commit c2bdd2c5b1d48a7e39e1a8d5e1d90b731b53c4c9 to v15 - v16. This avoids merge conflicts in the

pgsql: Assert lack of hazardous buffer locks before possible catalog re

2025-12-16 Thread Noah Misch
Assert lack of hazardous buffer locks before possible catalog read. Commit 0bada39c83a150079567a6e97b1a25a198f30ea3 fixed a bug of this kind, which existed in all branches for six days before detection. While the probability of reaching the trouble was low, the disruption was extreme. No new bac

pgsql: WAL-log inplace update before revealing it to other sessions.

2025-12-16 Thread Noah Misch
WAL-log inplace update before revealing it to other sessions. A buffer lock won't stop a reader having already checked tuple visibility. If a vac_update_datfrozenid() and then a crash happened during inplace update of a relfrozenxid value, datfrozenxid could overtake relfrozenxid. That could lea

pgsql: Reorder two functions in inval.c

2025-12-16 Thread Noah Misch
Reorder two functions in inval.c This file separates public and static functions with a separator comment, but two routines were not defined in a location reflecting that, so reorder them. Back-patch commit c2bdd2c5b1d48a7e39e1a8d5e1d90b731b53c4c9 to v15 - v16. This avoids merge conflicts in the

pgsql: For inplace update, send nontransactional invalidations.

2025-12-16 Thread Noah Misch
For inplace update, send nontransactional invalidations. The inplace update survives ROLLBACK. The inval didn't, so another backend's DDL could then update the row without incorporating the inplace update. In the test this fixes, a mix of CREATE INDEX and ALTER TABLE resulted in a table with an

pgsql: For inplace update, send nontransactional invalidations.

2025-12-16 Thread Noah Misch
For inplace update, send nontransactional invalidations. The inplace update survives ROLLBACK. The inval didn't, so another backend's DDL could then update the row without incorporating the inplace update. In the test this fixes, a mix of CREATE INDEX and ALTER TABLE resulted in a table with an

pgsql: WAL-log inplace update before revealing it to other sessions.

2025-12-16 Thread Noah Misch
WAL-log inplace update before revealing it to other sessions. A buffer lock won't stop a reader having already checked tuple visibility. If a vac_update_datfrozenid() and then a crash happened during inplace update of a relfrozenxid value, datfrozenxid could overtake relfrozenxid. That could lea

pgsql: For inplace update, send nontransactional invalidations.

2025-12-16 Thread Noah Misch
For inplace update, send nontransactional invalidations. The inplace update survives ROLLBACK. The inval didn't, so another backend's DDL could then update the row without incorporating the inplace update. In the test this fixes, a mix of CREATE INDEX and ALTER TABLE resulted in a table with an

pgsql: For inplace update, send nontransactional invalidations.

2025-12-16 Thread Noah Misch
For inplace update, send nontransactional invalidations. The inplace update survives ROLLBACK. The inval didn't, so another backend's DDL could then update the row without incorporating the inplace update. In the test this fixes, a mix of CREATE INDEX and ALTER TABLE resulted in a table with an

pgsql: Assert lack of hazardous buffer locks before possible catalog re

2025-12-16 Thread Noah Misch
Assert lack of hazardous buffer locks before possible catalog read. Commit 0bada39c83a150079567a6e97b1a25a198f30ea3 fixed a bug of this kind, which existed in all branches for six days before detection. While the probability of reaching the trouble was low, the disruption was extreme. No new bac

pgsql: WAL-log inplace update before revealing it to other sessions.

2025-12-16 Thread Noah Misch
WAL-log inplace update before revealing it to other sessions. A buffer lock won't stop a reader having already checked tuple visibility. If a vac_update_datfrozenid() and then a crash happened during inplace update of a relfrozenxid value, datfrozenxid could overtake relfrozenxid. That could lea

pgsql: Assert lack of hazardous buffer locks before possible catalog re

2025-12-16 Thread Noah Misch
Assert lack of hazardous buffer locks before possible catalog read. Commit 0bada39c83a150079567a6e97b1a25a198f30ea3 fixed a bug of this kind, which existed in all branches for six days before detection. While the probability of reaching the trouble was low, the disruption was extreme. No new bac

pgsql: WAL-log inplace update before revealing it to other sessions.

2025-12-16 Thread Noah Misch
WAL-log inplace update before revealing it to other sessions. A buffer lock won't stop a reader having already checked tuple visibility. If a vac_update_datfrozenid() and then a crash happened during inplace update of a relfrozenxid value, datfrozenxid could overtake relfrozenxid. That could lea

pgsql: Assert lack of hazardous buffer locks before possible catalog re

2025-12-16 Thread Noah Misch
Assert lack of hazardous buffer locks before possible catalog read. Commit 0bada39c83a150079567a6e97b1a25a198f30ea3 fixed a bug of this kind, which existed in all branches for six days before detection. While the probability of reaching the trouble was low, the disruption was extreme. No new bac

pgsql: Remove useless code in InjectionPointAttach()

2025-12-16 Thread Michael Paquier
Remove useless code in InjectionPointAttach() strlcpy() ensures that a target string is zero-terminated, so there is no need to enforce it a second time in this code. This simplification could have been done in 0eb23285a257. Author: Feilong Meng Reviewed-by: Chao Li Discussion: https://postgr

pgsql: Avoid global LC_CTYPE dependency in pg_locale_icu.c.

2025-12-16 Thread Jeff Davis
Avoid global LC_CTYPE dependency in pg_locale_icu.c. ICU still depends on libc for compatibility with certain historical behavior for single-byte encodings. Make the dependency explicit by holding a locale_t object when required. We should consider a better solution in the future, such as decodin

pgsql: downcase_identifier(): use method table from locale provider.

2025-12-16 Thread Jeff Davis
downcase_identifier(): use method table from locale provider. Previously, libc's tolower() was always used for lowercasing identifiers, regardless of the database locale (though only characters beyond 127 in single-byte encodings were affected). Refactor to allow each provider to supply its own im

pgsql: ltree: fix case-insensitive matching.

2025-12-16 Thread Jeff Davis
ltree: fix case-insensitive matching. Previously, ltree_prefix_eq_ci() used lowercasing with the default collation; while ltree_crc32_sz() used tolower() directly. These were equivalent only if the default collation provider was libc and the encoding was single-byte. Change both to use casefoldin

pgsql: ltree: fix case-insensitive matching.

2025-12-16 Thread Jeff Davis
ltree: fix case-insensitive matching. Previously, ltree_prefix_eq_ci() used lowercasing with the default collation; while ltree_crc32_sz() used tolower() directly. These were equivalent only if the default collation provider was libc and the encoding was single-byte. Change both to use casefoldin

pgsql: Clarify a #define introduced in 8d299052fe.

2025-12-16 Thread Jeff Davis
Clarify a #define introduced in 8d299052fe. The value is the same, but use the right symbol for clarity. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/24bf379cb15162514b01fc9fd05420a0203b82e9 Modified Files -- src/include/utils/pg_locale.h | 2 +- 1 fi

pgsql: Fix multibyte issue in ltree_strncasecmp().

2025-12-16 Thread Jeff Davis
Fix multibyte issue in ltree_strncasecmp(). Previously, the API for ltree_strncasecmp() took two inputs but only one length (that of the smaller input). It truncated the larger input to that length, but that could break a multibyte sequence. Change the API to be a check for prefix equality (possi

pgsql: Fix multibyte issue in ltree_strncasecmp().

2025-12-16 Thread Jeff Davis
Fix multibyte issue in ltree_strncasecmp(). Previously, the API for ltree_strncasecmp() took two inputs but only one length (that of the smaller input). It truncated the larger input to that length, but that could break a multibyte sequence. Change the API to be a check for prefix equality (possi

pgsql: Fix multibyte issue in ltree_strncasecmp().

2025-12-16 Thread Jeff Davis
Fix multibyte issue in ltree_strncasecmp(). Previously, the API for ltree_strncasecmp() took two inputs but only one length (that of the smaller input). It truncated the larger input to that length, but that could break a multibyte sequence. Change the API to be a check for prefix equality (possi

pgsql: Fix multibyte issue in ltree_strncasecmp().

2025-12-16 Thread Jeff Davis
Fix multibyte issue in ltree_strncasecmp(). Previously, the API for ltree_strncasecmp() took two inputs but only one length (that of the smaller input). It truncated the larger input to that length, but that could break a multibyte sequence. Change the API to be a check for prefix equality (possi

pgsql: Fix multibyte issue in ltree_strncasecmp().

2025-12-16 Thread Jeff Davis
Fix multibyte issue in ltree_strncasecmp(). Previously, the API for ltree_strncasecmp() took two inputs but only one length (that of the smaller input). It truncated the larger input to that length, but that could break a multibyte sequence. Change the API to be a check for prefix equality (possi

pgsql: Fix multibyte issue in ltree_strncasecmp().

2025-12-16 Thread Jeff Davis
Fix multibyte issue in ltree_strncasecmp(). Previously, the API for ltree_strncasecmp() took two inputs but only one length (that of the smaller input). It truncated the larger input to that length, but that could break a multibyte sequence. Change the API to be a check for prefix equality (possi

pgsql: Update .abi-compliance-history for CacheInvalidateHeapTupleInpla

2025-12-16 Thread Noah Misch
Update .abi-compliance-history for CacheInvalidateHeapTupleInplace(). Commit bae8ca82fd00603ebafa0658640d6e4dfe20af92 anticipated this: [C] 'function void CacheInvalidateHeapTupleInplace(Relation, HeapTuple, HeapTuple)' has some sub-type changes: parameter 3 of type 'typedef HeapTuple' was

pgsql: Switch memory contexts in ReinitializeParallelDSM.

2025-12-16 Thread Robert Haas
Switch memory contexts in ReinitializeParallelDSM. We already do this in CreateParallelContext, InitializeParallelDSM, and LaunchParallelWorkers. I suspect the reason why the matching logic was omitted from ReinitializeParallelDSM is that I failed to realize that any memory allocation was happenin

pgsql: Switch memory contexts in ReinitializeParallelDSM.

2025-12-16 Thread Robert Haas
Switch memory contexts in ReinitializeParallelDSM. We already do this in CreateParallelContext, InitializeParallelDSM, and LaunchParallelWorkers. I suspect the reason why the matching logic was omitted from ReinitializeParallelDSM is that I failed to realize that any memory allocation was happenin

pgsql: Switch memory contexts in ReinitializeParallelDSM.

2025-12-16 Thread Robert Haas
Switch memory contexts in ReinitializeParallelDSM. We already do this in CreateParallelContext, InitializeParallelDSM, and LaunchParallelWorkers. I suspect the reason why the matching logic was omitted from ReinitializeParallelDSM is that I failed to realize that any memory allocation was happenin

pgsql: Switch memory contexts in ReinitializeParallelDSM.

2025-12-16 Thread Robert Haas
Switch memory contexts in ReinitializeParallelDSM. We already do this in CreateParallelContext, InitializeParallelDSM, and LaunchParallelWorkers. I suspect the reason why the matching logic was omitted from ReinitializeParallelDSM is that I failed to realize that any memory allocation was happenin

pgsql: Switch memory contexts in ReinitializeParallelDSM.

2025-12-16 Thread Robert Haas
Switch memory contexts in ReinitializeParallelDSM. We already do this in CreateParallelContext, InitializeParallelDSM, and LaunchParallelWorkers. I suspect the reason why the matching logic was omitted from ReinitializeParallelDSM is that I failed to realize that any memory allocation was happenin

pgsql: Switch memory contexts in ReinitializeParallelDSM.

2025-12-16 Thread Robert Haas
Switch memory contexts in ReinitializeParallelDSM. We already do this in CreateParallelContext, InitializeParallelDSM, and LaunchParallelWorkers. I suspect the reason why the matching logic was omitted from ReinitializeParallelDSM is that I failed to realize that any memory allocation was happenin

pgsql: Test PRI* macros even when we can't test NLS translation.

2025-12-16 Thread Tom Lane
Test PRI* macros even when we can't test NLS translation. Further research shows that the reason commit 7db6809ce failed is that recent glibc versions short-circuit translation attempts when LC_MESSAGES is 'C.', not only when it's 'C'. There seems no way around that, so we'll have to live with onl

pgsql: Add explanatory comment to prune_freeze_setup()

2025-12-16 Thread Melanie Plageman
Add explanatory comment to prune_freeze_setup() heap_page_prune_and_freeze() fills in PruneState->deadoffsets, the array of OffsetNumbers of dead tuples. It is returned to the caller in the PruneFreezeResult. To avoid having two copies of the array, the PruneState saves only a pointer to the array

pgsql: Fix const qualification in prune_freeze_setup()

2025-12-16 Thread Melanie Plageman
Fix const qualification in prune_freeze_setup() The const qualification of the presult argument to prune_freeze_setup() is later cast away, so it was not correct. Remove it and add a comment explaining that presult should not be modified. Author: Peter Eisentraut Reviewed-by: Melanie Plageman D

pgsql: doc: Update header file mention for CompareType

2025-12-16 Thread Daniel Gustafsson
doc: Update header file mention for CompareType Commit 119fc30 moved CompareType to cmptype.h but the mention in the docs still refered to primnodes.h Author: Daisuke Higuchi Reviewed-by: Paul A Jungwirth Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/CAEVT6c8guXe5P=l_un5nuuzc

pgsql: doc: Update header file mention for CompareType

2025-12-16 Thread Daniel Gustafsson
doc: Update header file mention for CompareType Commit 119fc30 moved CompareType to cmptype.h but the mention in the docs still refered to primnodes.h Author: Daisuke Higuchi Reviewed-by: Paul A Jungwirth Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/CAEVT6c8guXe5P=l_un5nuuzc

pgsql: Separate out bytea sort support from varlena.c

2025-12-16 Thread John Naylor
Separate out bytea sort support from varlena.c In the wake of commit b45242fd3, bytea_sortsupport() still called out to varstr_sortsupport(). Treating bytea as a kind of text/varchar required varstr_sortsupport() to allow for the possibility of NUL bytes, but only for C collation. This was confusi