On Wed, Dec 8, 2021 at 4:05 PM Masahiko Sawada <sawada.m...@gmail.com> wrote: > > Okay, I understand those cases but note always checking if the > > prepared xact exists during commit prepared has a cost and that is why > > we avoided it at the first place.
BTW what costs were we concerned about? Looking at LookupGXact(), we look for the 2PC state data on shmem while acquiring TwoPhaseStateLock in shared mode. And we check origin_lsn and origin_timestamp of 2PC by reading WAL or 2PC state file only if gid matched. On the other hand, committing the prepared transaction does WAL logging, waits for synchronous replication, and calls post-commit callbacks, and removes 2PC state file etc. And it requires acquiring TwoPhaseStateLock in exclusive mode to remove 2PC state entry. So it looks like always checking if the prepared transaction exists and skipping it if not is cheaper than always committing prepared transactions. Regards, -- Masahiko Sawada EDB: https://www.enterprisedb.com/