Re: Reducing output size of nodeToString

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(at)eisentraut(dot)org>, 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-26 04:11:53
Message-ID: CAP53Pkx6x0+R2CZu92_TWtPFTKTHyevK71nv9oULj_iL8=uXMw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 25, 2026 at 7:01 PM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> That said, if we do go to a binary format, we ought to think hard
> about making it protobuf-compatible -- not using their library, but
> their wire format. That would let people easily use tools not written
> by us to decode our binary blobs, if they want.

FWIW, I'd be happy to help on that task if we want to go that route -
we've been using a Protobuf-based raw parse tree representation in
libpg_query [0] since 2021, and are in the process of switching to
auto-generating the decoding/encoding method calls using Postgres'
gen_node_support.pl infrastructure.

The tradeoffs we have in libpg_query vs what Postgres needs for stored
trees in the catalog are a bit different, since we didn't actually
need a stable Protobuf representation across major versions. But I
feel if Postgres moves to a binary format, a schema-based binary
mechanism like Protobuf seems better than a schemaless one like
msgpack. One benefit is that Protobuf makes it easy to clarify
naming/intent by renaming fields in a release whilst preserving binary
compatibility from old releases, as long as field numbers stay stable.

It's worth noting that one challenge we've found is which Protobuf
library to use in C, since Google's main Protobuf library is written
in C++, and protobuf-c [1], which we used initially, is mostly
unmaintained and doesn't deal well with deeply nested input.

For libpg_query we recently switched to vendoring upb [2], which is a
pure C library (BSD-licensed) and also part of Google's upstream
protobuf repository. upb has been pretty good so far, with the main
downside being that it's intentionally marked as not having a stable
API (it's intended for use in Google protobuf's own language-specific
libraries).

The other curiosity is that upb has an "amalgamation" script that
bundles the runtime into a single C file, and through that you can
limit it to the features needed, e.g. encoding/decoding only (no
reflection, JSON or text format). For us that comes to about 11k lines
of C [3], plus about 10k lines of headers, excluding the generated
field definitions themselves.

Thanks,
Lukas

[0]: https://github.com/pganalyze/libpg_query/
[1]: https://github.com/protobuf-c/protobuf-c
[2]: https://github.com/protocolbuffers/protobuf/tree/main/upb
[3]: https://github.com/pganalyze/libpg_query/tree/18-latest/vendor/upb

--
Lukas Fittl

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-11-26 04:18:25 DOC: Minor updates for logical replication conflicts
Previous Message shveta malik 2026-11-26 03:37:15 Re: Proposal: Conflict log history table for Logical Replication