| From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
|---|---|
| To: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
| Cc: | Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com> |
| Subject: | Re: Reducing output size of nodeToString |
| Date: | 2026-11-25 17:33:05 |
| Message-ID: | CA+TgmoZoMhV0LrpqcojHEFZY3adASnsjqn8B6Z3Xuc2JdQKyhQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Fri, Mar 22, 2024 at 5:18 AM Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
> I think to proceed we need more buy-in on the "what do I want from my
> node dumps" side, and more performance numbers on the other side.
> Saving a few hundred kilobytes on view storage is fine but isn't by
> itself that useful, I think, if it potentially negatively affects other
> uses.
I'd like to revive this thread, because I was looking at this topic
today and then realized Matthias had already done a lot of work on it.
I see there's also a newer thread with a different subject line:
"Reducing relcache memory usage 2: shrink sizeof(RelationData)". But
just revisiting this thread, I have two main points to make:
[#1] Reducing the size of the textual representation does not only
help with the on-disk size of catalogs entries. The catcache holds
onto entire tuples, which means the nodeToString() output is included,
and the relcache also holds onto various things in string form: adbin,
ccbin, tgqual; plus indpred and indexprs inside rd_indextuple. Some of
these are stored uncompressed, which means making the format more
compact can help more here than it does on disk, after TOAST
compression. I think this is probably a bigger advantage than the
reduction in on-disk size, because in my experience cache memory
consumption is a significant operational problem for users.
The savings here aren't enormous, but they do add up. A kilobyte of
garbage in every relcache entry turns into a gigabyte of memory on a
setup with a million tables. That's not a crazy scenario; people run
systems like that. And importantly, it's mostly-orthogonal to other
ways that we might think about saving memory. For example, we've
repeatedly discussed timing out catcache or relcache entries, which is
nice, but there will still be cases that require many of them. The
other thread discusses deduplicating repeated catalog structure, but
it will still be nice if each individual piece of structure is
smaller, especially when deduplication doesn't work out. There are
ways of squeezing RelationData down to a smaller size, but doing this
makes that more valuable, because it saves a larger percentage of the
remaining memory, and conversely.
[#2] Readability for humans and compactness for computers are not
always at odds. In my experience, one of the biggest problems with
debug_print_plan output is that the VAR nodes are printed so verbosely
that it totally destroys readability. For every single plan node, you
get a target list, which is mostly Var nodes. Each one looks like
this, but split so that every field is on a separate line:
{VAR :varno 1 :varattno 1 :vartype 26 :vartypmod -1 :varcollid 0
:varnullingrels (b) :varlevelsup 0 :varreturningtype 0 :varnosyn 1
:varattnosyn 1 :location -1}
Obviously most of that is uninteresting. With what Matthias is
proposing, we could be instead printing this:
{VAR :varno 1 :varattno 1 :vartype 26}
I think that's a huge improvement. It takes up way less screen space
and it makes it obvious at a glance that the Var has no other
interesting properties; if it did, they'd be printed.
There are a variety of fairly obvious ways to do better. The fields
all start with "var"; we hardly need to repeat that on every line.
varno, varattno, and varlevelsup are the identity-defining fields;
there could be a special syntax for those, like {VAR 1/1 :type 26}
implying varlevelsup = 0, or {VAR 1/2/3 :type 26} for varlevelsup = 1,
varno = 2, varattno = 3. That's compact enough to print on one line,
and I don't even think that {VAR 1/2/3 26} would be excessive,
assuming that a human reader who spends a lot of time reading node
dumps can remember or guess that 26 is the vartype. I'd print %d(%d)
for a type with a typmod, when it's not -1.
VAR and CONST are super-common nodes, so just abbreviating for those
two would help a lot. And again, I argue it helps humans as much as it
helps computers. The only loss is that any particular reader will need
to acclimate to the new format, but I think that's a cost we should be
willing to accept.
--
Robert Haas
Databricks
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-25 17:43:09 | Re: OOM kill in xmlelement() with large arrays |
| Previous Message | Peter Eisentraut | 2026-11-25 17:04:23 | pg_rewind: Fix buffer size passed when building WAL file name |