Preserve dml_adaptive state on ROLLBACK TO SAVEPOINT

From: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
To: "pgpool-hackers(at)lists(dot)postgresql(dot)org" <pgpool-hackers(at)lists(dot)postgresql(dot)org>
Subject: Preserve dml_adaptive state on ROLLBACK TO SAVEPOINT
Date: 2026-10-05 07:36:30
Message-ID: OS9P286MB6486F7318381295750F921DF94962@OS9P286MB6486.JPNP286.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-hackers

Hi,
I'd like to submit a patch to fix an issue in dml_adaptive load balancing when ROLLBACK TO SAVEPOINT is used.
Currently, dml_adaptive() uses is_commit_or_rollback_query() to determine whether a transaction has ended. However, this function also returns true for ROLLBACK TO SAVEPOINT, even though the transaction itself is still active.
As a result, ROLLBACK TO SAVEPOINT clears is_in_transaction and the accumulated transaction write list. A subsequent SELECT on a table modified earlier in the same transaction may then be load balanced to a standby, potentially returning stale data.
This patch changes the transaction-end check so that only COMMIT and normal ROLLBACK clear the transaction state. ROLLBACK TO SAVEPOINT now preserves the accumulated write list.
I also added a regression test to confirm that a SELECT after ROLLBACK TO SAVEPOINT is still sent to the primary when the table was modified earlier in the transaction.
The patch is attached.
Discussion:
https://github.com/pgpool/pgpool2/issues/173
Best Regards,

Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

Attachment Content-Type Size
v3-0001-Preserve-dml_adaptive-state-on-ROLLBACK-TO-SAVEPO.patch application/octet-stream 3.6 KB

Browse pgpool-hackers by date

  From Date Subject
Next Message Nadav Shatz 2026-10-06 14:05:54 Re: Removing support for FE/BE protocol version 2
Previous Message Tatsuo Ishii 2026-10-05 05:43:22 Re: Removing support for FE/BE protocol version 2