pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add parallelism support for TID Range Scans
Date: Thu, 27 Nov 2025 01:05:25 +0000
Message-ID: <E1vOQRo-001a6K-1k@gemulon.postgresql.org> (raw)

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0ca3b16973a8bb1c185f56e65edcadc0d9d2c406

Modified Files
--------------
doc/src/sgml/parallel.sgml                 |   9 ++
src/backend/access/heap/heapam.c           |   4 +-
src/backend/access/table/tableam.c         | 148 +++++++++++++++++++++--------
src/backend/executor/execParallel.c        |  21 ++++
src/backend/executor/nodeTidrangescan.c    |  80 ++++++++++++++++
src/backend/optimizer/path/costsize.c      |  34 +++++--
src/backend/optimizer/path/tidpath.c       |  24 ++++-
src/backend/optimizer/util/pathnode.c      |   7 +-
src/include/access/relscan.h               |   2 +
src/include/access/tableam.h               |  14 ++-
src/include/executor/nodeTidrangescan.h    |   7 ++
src/include/nodes/execnodes.h              |   2 +
src/include/optimizer/pathnode.h           |   3 +-
src/test/regress/expected/tidrangescan.out | 105 ++++++++++++++++++++
src/test/regress/sql/tidrangescan.sql      |  44 +++++++++
15 files changed, 446 insertions(+), 58 deletions(-)



Message-ID: <E1vOQRo-001a6K-1k@gemulon.postgresql.org>
Permalink:  ../E1vOQRo-001a6K-1k@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vOQRo-001a6K-1k@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Add parallelism support for TID Range Scans
  In-Reply-To: <E1vOQRo-001a6K-1k@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox