Re: EXPLAIN: showing ReadStream / prefetch stats

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Lukas Fittl <lukas(at)fittl(dot)com>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: EXPLAIN: showing ReadStream / prefetch stats
Date: 2026-04-03 19:01:05
Message-ID: fce326bb-1210-4d48-8c97-bb3bca396eba@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Here's v8, with a couple improvements:

1) stats for non-parallel-aware scans

It correctly shows stats for scans that are not parallel-aware.

I'd argue for BitmapHeapScan this is a live bug in 5a1e6df3b84c, so I
kept it in a separate commit 0002. It probably should be backpatched to
PG18, even if no one complained about it.

For SeqScan/TidRangeScan I've merged the changes into 0004 and 0005.

I have to admit I'm not a huge fan of the changes required to fix this.
The logic with all these instument/parallel_aware conditions seems much
less readable to me, but I don't know how else to do this. The approach
is copied from nodeIndexscan.c, which already did that in 0fbceae841cb.

2) worker stats

While working on fixing the BHS, I realized it prints the worker stats
using ExplainOpenWorker/ExplainCloseWorker, which puts-aside the worker
stats. Which is better than the original approach - it does not require
a separate function (with a lot of duplication).

The bad thing is this gives us even less control over the order of items
in the explain output.

I'm mostly happy with this, except for the decreased readability due to
the various checks of instrument/parallel_aware.

I'm also attaching SQL scripts for the three scans, with plans that
include them in places with parallel_aware=false. All plans should have
the relevant explain stats for all the scans.

regards

--
Tomas Vondra

Attachment Content-Type Size
v8-0001-switch-explain-to-unaligned-for-json-xml-yaml.patch text/x-patch 12.9 KB
v8-0002-Show-Bitmap-Heap-Scan-stats-for-non-parallel-awar.patch text/x-patch 7.3 KB
v8-0003-explain-show-prefetch-stats-in-EXPLAIN-ANALYZE.patch text/x-patch 58.5 KB
v8-0004-show-prefetch-stats-for-SeqScan.patch text/x-patch 42.4 KB
v8-0005-show-prefetch-stats-for-TidRangeScan.patch text/x-patch 13.0 KB
test-bitmapscan.sql application/sql 1.7 KB
test-seqscan.sql application/sql 1.8 KB
test-tidrangescan.sql application/sql 1.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-04-03 19:01:13 Re: AIO / read stream heuristics adjustments for index prefetching
Previous Message Tom Lane 2026-04-03 18:35:22 Re: CREATE SCHEMA ... CREATE DOMAIN support