On Wed, Nov 25, 2026 at 7:01 PM Robert Haas <[email protected]> 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
