From: | "Sophie Alpert" <pg(at)sophiebits(dot)com> |
---|---|
To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Fix missing EvalPlanQual recheck for TID scans |
Date: | 2025-09-06 07:54:08 |
Message-ID: | 4a6268ff-3340-453a-9bf5-c98d51a6f729@app.fastmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi all,
I learned that the TID Scan node does not properly implement EvalPlanQual recheck, which has already been noted in comment added in 2002 (commit 6799a6ca21). This does seem to have the potential to manifest in observable and surprising ways when queries are filtering on `ctid`, like for optimistic concurrency control as in https://stackoverflow.com/q/78487441.
Attached is an attempt from me at fixing this issue for TID Scan as well as TID Range Scan which appears to have the same issue.
This is my first time looking at the Postgres source (nor do I work with C on a regular basis), so I will not be surprised to hear that I've done things wrong, but I'm hopeful that this is usable as written. Running `meson test` passes for me, including the added isolation tests, and I confirmed that both of the tests that now result in a negative recheck were previously failing.
In my implementation I am calling TidRangeEval every time TidRangeRecheck is called; let me know if this is a performance concern. It didn't seem that any of the existing TidRangeScanState flags are quite right to know if the bounds have been initialized, but I am happy to add one.
The original issue appears to have been present since the introduction of TID scans in 1999 (commit 6f9ff92cc0) so I imagine it may make sense to backport the fix, although evidently not many people are running into this.
Thanks,
Sophie
Attachment | Content-Type | Size |
---|---|---|
0001-Fix-missing-EvalPlanQual-recheck-for-TID-scans.v1.patch | application/octet-stream | 6.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Dilip Kumar | 2025-09-06 09:38:00 | Re: Proposal: Conflict log history table for Logical Replication |
Previous Message | Jelte Fennema-Nio | 2025-09-06 07:35:10 | Re: Extension security improvement: Add support for extensions with an owned schema |