Re: EXPLAIN: showing ReadStream / prefetch stats

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Lukas Fittl <lukas(at)fittl(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, 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-03-26 00:35:01
Message-ID: ab5b6aaf-90d1-4c35-b76b-6416385df6c6@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Here's a slightly improved v5, with a couple minor changes over v4.

Patches 0001 and 0002 are prerequisites from other threads. 0001 was
already included in v4. 0002 is new and comes from [1], and it adds
"flags" to TAM beginscan() methods. This allows 0003 to pass a new
SO_SCAN_INSTRUMENT flag, so that e.g. heap_beginscan() can initialize
the instrumentation only when executed in EXPLAIN ANALYZE. In v4 it had
to be done every time, which did not seem quite great.

This mimics what we do for index scans in the index prefetching, which
only allocates the instrumentation when needed.

0004 and 0005 are adjusted to do this for SeqScan and TidRangeScans too.

0006 is a minor adjustment of the explain output, based on the earlier
discussion about non-text formats. It removes the explain groups (to not
add nested output), and instead makes the labels more descriptive. It
also prints the items every time, even with io_count==0.

The last change is that I added the number of I/Os, instead of printing
just the number of stalls and average I/O size. Without the count it
seemed a bit difficult to interpret. It might be possible to deduce some
of this from buffers reads, but I found it a bit unclear.

0006 should be split and merged into the earlier parts, I mostly kept it
to make those changes obvious.

regards

https://www.postgresql.org/message-id/itvgqc6vncbjsjfmrptfvkkeg5vqzhalaguya2z77t6c6ctpc3%40wsdrgbn4bxaa

--
Tomas Vondra

Attachment Content-Type Size
v5-0006-adjust-explain-output.patch text/x-patch 14.9 KB
v5-0005-show-prefetch-stats-for-TidRangeScan.patch text/x-patch 10.5 KB
v5-0004-show-prefetch-stats-for-SeqScan.patch text/x-patch 38.3 KB
v5-0003-explain-show-prefetch-stats-in-EXPLAIN-ANALYZE.patch text/x-patch 71.5 KB
v5-0002-Thread-flags-through-begin-scan-APIs.patch text/x-patch 32.8 KB
v5-0001-bufmgr-Return-whether-WaitReadBuffers-needed-to-w.patch text/x-patch 2.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-03-26 00:35:57 Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions
Previous Message David Rowley 2026-03-26 00:28:16 Re: another autovacuum scheduling thread