pgsql: Fix slot synchronization for two_phase enabled slots.

2025-04-02 Thread Amit Kapila
Fix slot synchronization for two_phase enabled slots. The issue is that the transactions prepared before two-phase decoding is enabled can fail to replicate to the subscriber after being committed on a promoted standby following a failover. This is because the two_phase_at field of a slot, which t

pgsql: Remove unnecessary type violation in tsvectorrecv().

2025-04-02 Thread Tom Lane
Remove unnecessary type violation in tsvectorrecv(). compareentry() is declared to work on WordEntryIN structs, but tsvectorrecv() is using it in two places to work on WordEntry structs. This is almost okay, since WordEntry is the first field of WordEntryIN. But on machines with 8-byte pointers,

pgsql: Remove unnecessary type violation in tsvectorrecv().

2025-04-02 Thread Tom Lane
Remove unnecessary type violation in tsvectorrecv(). compareentry() is declared to work on WordEntryIN structs, but tsvectorrecv() is using it in two places to work on WordEntry structs. This is almost okay, since WordEntry is the first field of WordEntryIN. But on machines with 8-byte pointers,

pgsql: Remove unnecessary type violation in tsvectorrecv().

2025-04-02 Thread Tom Lane
Remove unnecessary type violation in tsvectorrecv(). compareentry() is declared to work on WordEntryIN structs, but tsvectorrecv() is using it in two places to work on WordEntry structs. This is almost okay, since WordEntry is the first field of WordEntryIN. But on machines with 8-byte pointers,

pgsql: Remove unnecessary type violation in tsvectorrecv().

2025-04-02 Thread Tom Lane
Remove unnecessary type violation in tsvectorrecv(). compareentry() is declared to work on WordEntryIN structs, but tsvectorrecv() is using it in two places to work on WordEntry structs. This is almost okay, since WordEntry is the first field of WordEntryIN. But on machines with 8-byte pointers,

pgsql: Remove unnecessary type violation in tsvectorrecv().

2025-04-02 Thread Tom Lane
Remove unnecessary type violation in tsvectorrecv(). compareentry() is declared to work on WordEntryIN structs, but tsvectorrecv() is using it in two places to work on WordEntry structs. This is almost okay, since WordEntry is the first field of WordEntryIN. But on machines with 8-byte pointers,

pgsql: Remove unnecessary type violation in tsvectorrecv().

2025-04-02 Thread Tom Lane
Remove unnecessary type violation in tsvectorrecv(). compareentry() is declared to work on WordEntryIN structs, but tsvectorrecv() is using it in two places to work on WordEntry structs. This is almost okay, since WordEntry is the first field of WordEntryIN. But on machines with 8-byte pointers,

pgsql: Remove HeapBitmapScan's skip_fetch optimization

2025-04-02 Thread Andres Freund
Remove HeapBitmapScan's skip_fetch optimization The optimization does not take the removal of TIDs by a concurrent vacuum into account. The concurrent vacuum can remove dead TIDs and make pages ALL_VISIBLE while those dead TIDs are referenced in the bitmap. This can lead to a skip_fetch scan retur

pgsql: Remove HeapBitmapScan's skip_fetch optimization

2025-04-02 Thread Andres Freund
Remove HeapBitmapScan's skip_fetch optimization The optimization does not take the removal of TIDs by a concurrent vacuum into account. The concurrent vacuum can remove dead TIDs and make pages ALL_VISIBLE while those dead TIDs are referenced in the bitmap. This can lead to a skip_fetch scan retur

pgsql: Remove HeapBitmapScan's skip_fetch optimization

2025-04-02 Thread Andres Freund
Remove HeapBitmapScan's skip_fetch optimization The optimization does not take the removal of TIDs by a concurrent vacuum into account. The concurrent vacuum can remove dead TIDs and make pages ALL_VISIBLE while those dead TIDs are referenced in the bitmap. This can lead to a skip_fetch scan retur

pgsql: Add test for HeapBitmapScan's broken skip_fetch optimization

2025-04-02 Thread Andres Freund
Add test for HeapBitmapScan's broken skip_fetch optimization In the previous commit HeapBitmapScan's skip_fetch optimization was removed, due to being broken in not easily fixable ways. Add a test that verifies we don't re-introduce this bug if somebody tries to re-add the feature. Only add the t

pgsql: Remove HeapBitmapScan's skip_fetch optimization

2025-04-02 Thread Andres Freund
Remove HeapBitmapScan's skip_fetch optimization The optimization does not take the removal of TIDs by a concurrent vacuum into account. The concurrent vacuum can remove dead TIDs and make pages ALL_VISIBLE while those dead TIDs are referenced in the bitmap. This can lead to a skip_fetch scan retur

pgsql: Remove HeapBitmapScan's skip_fetch optimization

2025-04-02 Thread Andres Freund
Remove HeapBitmapScan's skip_fetch optimization The optimization does not take the removal of TIDs by a concurrent vacuum into account. The concurrent vacuum can remove dead TIDs and make pages ALL_VISIBLE while those dead TIDs are referenced in the bitmap. This can lead to a skip_fetch scan retur

pgsql: Change SQL-language functions to use the plan cache.

2025-04-02 Thread Tom Lane
Change SQL-language functions to use the plan cache. In the historical implementation of SQL functions (if they don't get inlined), we built plans for all the contained queries at first call within an outer query, and then re-used those plans for the duration of the outer query, and then forgot ev

pgsql: Add GiST and btree sortsupport routines for range types

2025-04-02 Thread Heikki Linnakangas
Add GiST and btree sortsupport routines for range types For GiST, having a sortsupport function allows building the index using the "sorted build" method, which is much faster. For b-tree, the sortsupport routine doesn't give any new functionality, but speeds up sorting a tiny bit. The difference

pgsql: Need to do CommandCounterIncrement after StoreAttrMissingVal.

2025-04-02 Thread Tom Lane
Need to do CommandCounterIncrement after StoreAttrMissingVal. Without this, an additional change to the same pg_attribute row within the same command will fail. This is possible at least with ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure. (Another potential hazard is that imm

pgsql: Need to do CommandCounterIncrement after StoreAttrMissingVal.

2025-04-02 Thread Tom Lane
Need to do CommandCounterIncrement after StoreAttrMissingVal. Without this, an additional change to the same pg_attribute row within the same command will fail. This is possible at least with ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure. (Another potential hazard is that imm

pgsql: Need to do CommandCounterIncrement after StoreAttrMissingVal.

2025-04-02 Thread Tom Lane
Need to do CommandCounterIncrement after StoreAttrMissingVal. Without this, an additional change to the same pg_attribute row within the same command will fail. This is possible at least with ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure. (Another potential hazard is that imm

pgsql: docs: Fix column count attribute in table

2025-04-02 Thread Heikki Linnakangas
docs: Fix column count attribute in table Nothing seems to actually depend on the attribute, as the docs built successfully, but let's be tidy. Reported offlist by Matthias van de Meent Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/ea3f9b6da34a1a4dc2c0c118789587c

Re: pgsql: docs: Fix column count attribute in table

2025-04-02 Thread Tom Lane
Heikki Linnakangas writes: > docs: Fix column count attribute in table > Nothing seems to actually depend on the attribute, as the docs built > successfully, but let's be tidy. Actually, it broke the PDF docs build, as per crake. regards, tom lane

pgsql: Improve accounting for PredXactList, RWConflictPool and PGPROC

2025-04-02 Thread Tomas Vondra
Improve accounting for PredXactList, RWConflictPool and PGPROC Various places allocated shared memory by first allocating a small chunk using ShmemInitStruct(), followed by ShmemAlloc() calls to allocate more memory. Unfortunately, ShmemAlloc() does not update ShmemIndex, so this affected pg_shmem

pgsql: Need to do CommandCounterIncrement after StoreAttrMissingVal.

2025-04-02 Thread Tom Lane
Need to do CommandCounterIncrement after StoreAttrMissingVal. Without this, an additional change to the same pg_attribute row within the same command will fail. This is possible at least with ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure. (Another potential hazard is that imm

Re: pgsql: Allow parallel CREATE INDEX for GIN indexes

2025-04-02 Thread Tomas Vondra
On 4/1/25 15:30, Peter Eisentraut wrote: > On 07.03.25 22:22, Peter Eisentraut wrote: >> The new tuplesort_getgintuple() in tuplesortvariants.c has a branch >> that does "return false" even though the function's return type is >> GinTuple *.  That is probably a mistake.  Check please. >> >> Also, t

pgsql: Make cancel request keys longer

2025-04-02 Thread Heikki Linnakangas
Make cancel request keys longer Currently, the cancel request key is a 32-bit token, which isn't very much entropy. If you want to cancel another session's query, you can brute-force it. In most environments, an unauthorized cancellation of a query isn't very serious, but it nevertheless would be

pgsql: libpq: Handle NegotiateProtocolVersion message differently

2025-04-02 Thread Heikki Linnakangas
libpq: Handle NegotiateProtocolVersion message differently Previously libpq would always error out if the server sends a NegotiateProtocolVersion message. This was fine because libpq only supported a single protocol version and did not support any protocol parameters. But in the upcoming commits,

pgsql: docs: Add a new section and a table listing protocol versions

2025-04-02 Thread Heikki Linnakangas
docs: Add a new section and a table listing protocol versions Move the discussion on protocol versions and version negotiation to a new "Protocol versions" section. Add a table listing all the different protocol versions, starting from the obsolete protocol version 2, and the PostgreSQL versions t

pgsql: Add support for NOT ENFORCED in foreign key constraints

2025-04-02 Thread Peter Eisentraut
Add support for NOT ENFORCED in foreign key constraints This expands the NOT ENFORCED constraint flag, previously only supported for CHECK constraints (commit ca87c415e2f), to foreign key constraints. Normally, when a foreign key constraint is created on a table, action and check triggers are add

pgsql: Fix code comment

2025-04-02 Thread Peter Eisentraut
Fix code comment The changes made in commit d2b4b4c2259 contained incorrect comments: They said that certain forward declarations were necessary to "avoid including pathnodes.h here", but the file is itself pathnodes.h! So change the comment to just say it's a forward declaration in one case, and

pgsql: Fix code comment

2025-04-02 Thread Peter Eisentraut
Fix code comment The changes made in commit d2b4b4c2259 contained incorrect comments: They said that certain forward declarations were necessary to "avoid including pathnodes.h here", but the file is itself pathnodes.h! So change the comment to just say it's a forward declaration in one case, and

pgsql: Add timingsafe_bcmp(), for constant-time memory comparison

2025-04-02 Thread Heikki Linnakangas
Add timingsafe_bcmp(), for constant-time memory comparison timingsafe_bcmp() should be used instead of memcmp() or a naive for-loop, when comparing passwords or secret tokens, to avoid leaking information about the secret token by timing. This commit just introduces the function but does not chang

pgsql: tests: Fix incompatibility of test_aio with *_FORCE_RELEASE

2025-04-02 Thread Andres Freund
tests: Fix incompatibility of test_aio with *_FORCE_RELEASE The test added in 93bc3d75d8e failed in a build with RELCACHE_FORCE_RELEASE and CATCACHE_FORCE_RELEASE defined. The test intentionally forgets to exit batchmode - normally that would trigger an error at the end of the transaction, which t

pgsql: tests: Cope with WARNINGs during failed CREATE DB on windows

2025-04-02 Thread Andres Freund
tests: Cope with WARNINGs during failed CREATE DB on windows The test added in 93bc3d75d8e sometimes fails on windows, due to warnings like WARNING: some useless files may be left behind in old database directory "base/16514" The reason for that is createdb_failure_callback() does not ensure th

pgsql: tests: Cope with io_method in TEMP_CONFIG in test_aio

2025-04-02 Thread Andres Freund
tests: Cope with io_method in TEMP_CONFIG in test_aio If io_method is set in TEMP_CONFIG the test added in 93bc3d75d8e fails, because it assumes the io_method specified at initdb is actually used. Fix that by appending the io_method again, after initdb (and thus after TEMP_CONFIG has been added b