Pretty byte size formatting in EXPLAIN

From: Gavin Wahl <gavinwahl(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Pretty byte size formatting in EXPLAIN
Date: 2025-10-22 23:42:15
Message-ID: CACPudh2PLmZ2pbSYN5jmBirqW0Jv4U39qRyHR0ySpMMjEaDZMg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

In EXPLAIN ANALYZE output, I find the disk/memory usage numbers to be
hard to read because they are always in kB. I'd like to have an option
to format them like pg_size_pretty does, choosing a more appropriate unit
based on the magnitude of the value being expressed. That is, instead of
`Batches: 1 Memory Usage: 163857kB`,
EXPLAIN (PRETTY) would show
`Batches: 1 Memory Usage: 160 MB`.

I see the formatting is done in src/backend/commands/explain.c, hardcoded
to kB. I understand the default output of EXPLAIN probably can't be
changed due to third-party tools that parse it, so I'd like to add an
option, something like PRETTY, to EXPLAIN, that would use pg_size_pretty
formatted values.

Would such a patch be accepted? If there's interest I can work on
writing it.

Also--while I think the pg_size_pretty improvement to be much more
important, so I don't want to derail this, I think thousands separators in
numbers would be useful as well, similar to `\pset numericlocale on`. Is
it possible for psql to do this conversion, or would another option to
EXPLAIN be necessary? Something like EXPLAIN (NUMERICLOCAL) would show
`Sort (cost=71,270.98..72,104.31 rows=333,333 width=40)`
instead of
`Sort (cost=71270.98..72104.31 rows=333333 width=40)`.

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-10-22 23:45:48 Re: Add copyright notice to 048_vacuum_horizon_floor.pl
Previous Message Matt Smith (matts3) 2025-10-22 23:27:47 Re: Meson install warnings when running postgres build from a sandbox