pgsql: Add missing EPQ recheck for TID Range Scan

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add missing EPQ recheck for TID Range Scan
Date: 2025-09-17 00:21:43
Message-ID: E1uyfva-0015AG-1g@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add missing EPQ recheck for TID Range Scan

The EvalPlanQual recheck for TID Range Scan wasn't rechecking the TID qual
still passed after following update chains. This could result in tuples
being updated or deleted by plans using TID Range Scans where the ctid of
the new (updated) tuple no longer matches the clause of the scan. This
isn't desired behavior, and isn't consistent with what would happen if the
chosen plan had used an Index or Seq Scan, and that could lead to hard to
predict behavior for scans that contain TID quals and other quals as the
planner has freedom to choose TID Range or some other non-TID scan method
for such queries, and the chosen plan could change at any moment.

Here we fix this by properly implementing the recheck function for TID
Range Scans.

Backpatch to 14, where TID Range Scans were added

Reported-by: Sophie Alpert <pg(at)sophiebits(dot)com>
Author: Sophie Alpert <pg(at)sophiebits(dot)com>
Author: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://postgr.es/m/4a6268ff-3340-453a-9bf5-c98d51a6f729@app.fastmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f78a69034740687669c72f15382a113ee4c482db

Modified Files
--------------
src/backend/executor/nodeTidrangescan.c | 10 ++++++++++
src/test/isolation/expected/eval-plan-qual.out | 23 +++++++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec | 5 ++++-
3 files changed, 37 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-09-17 00:33:51 pgsql: Fix shared memory calculation size of PgAioCtl
Previous Message David Rowley 2025-09-17 00:21:22 pgsql: Add missing EPQ recheck for TID Range Scan