Add missing EPQ recheck for TID Range Scan
authorDavid Rowley <drowley@postgresql.org>
Wed, 17 Sep 2025 00:21:29 +0000 (12:21 +1200)
committerDavid Rowley <drowley@postgresql.org>
Wed, 17 Sep 2025 00:21:29 +0000 (12:21 +1200)
commitf78a69034740687669c72f15382a113ee4c482db
treeb75535687bc0010660a2a8f9ea52304e45121c18
parent2eb7ea97d8af4f4a8c65ff9f95fcbe4e4ab8e7a8
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@sophiebits.com>
Author: Sophie Alpert <pg@sophiebits.com>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/4a6268ff-3340-453a-9bf5-c98d51a6f729@app.fastmail.com
Backpatch-through: 14
src/backend/executor/nodeTidrangescan.c
src/test/isolation/expected/eval-plan-qual.out
src/test/isolation/specs/eval-plan-qual.spec