Add parallelism support for TID Range Scans
authorDavid Rowley <drowley@postgresql.org>
Thu, 27 Nov 2025 01:05:04 +0000 (14:05 +1300)
committerDavid Rowley <drowley@postgresql.org>
Thu, 27 Nov 2025 01:05:04 +0000 (14:05 +1300)
commit0ca3b16973a8bb1c185f56e65edcadc0d9d2c406
treeab3bcbea310c7cb3650ab5dbde4c5121736ce966
parent42473b3b31238b15cc3c030b4416b2ee79508d8c
Add parallelism support for TID Range Scans

In v14, bb437f995 added support for scanning for ranges of TIDs using a
dedicated executor node for the purpose.  Here, we allow these scans to
be parallelized.  The range of blocks to scan is divvied up similarly to
how a Parallel Seq Scans does that, where 'chunks' of blocks are
allocated to each worker and the size of those chunks is slowly reduced
down to 1 block per worker by the time we're nearing the end of the
scan.  Doing that means workers finish at roughly the same time.

Allowing TID Range Scans to be parallelized removes the dilemma from the
planner as to whether a Parallel Seq Scan will cost less than a
non-parallel TID Range Scan due to the CPU concurrency of the Seq Scan
(disk costs are not divided by the number of workers).  It was possible
the planner could choose the Parallel Seq Scan which would result in
reading additional blocks during execution than the TID Scan would have.
Allowing Parallel TID Range Scans removes the trade-off the planner
makes when choosing between reduced CPU costs due to parallelism vs
additional I/O from the Parallel Seq Scan due to it scanning blocks from
outside of the required TID range.  There is also, of course, the
traditional parallelism performance benefits to be gained as well, which
likely doesn't need to be explained here.

Author: Cary Huang <cary.huang@highgo.ca>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Reviewed-by: Rafia Sabih <rafia.pghackers@gmail.com>
Reviewed-by: Steven Niu <niushiji@gmail.com>
Discussion: https://postgr.es/m/18f2c002a24.11bc2ab825151706.3749144144619388582@highgo.ca
15 files changed:
doc/src/sgml/parallel.sgml
src/backend/access/heap/heapam.c
src/backend/access/table/tableam.c
src/backend/executor/execParallel.c
src/backend/executor/nodeTidrangescan.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/tidpath.c
src/backend/optimizer/util/pathnode.c
src/include/access/relscan.h
src/include/access/tableam.h
src/include/executor/nodeTidrangescan.h
src/include/nodes/execnodes.h
src/include/optimizer/pathnode.h
src/test/regress/expected/tidrangescan.out
src/test/regress/sql/tidrangescan.sql