pgsql: Make serialization of Nodes' scalar-array fields more robust.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make serialization of Nodes' scalar-array fields more robust.
Date: 2022-07-20 17:05:26
Message-ID: E1oED8X-000S56-Om@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make serialization of Nodes' scalar-array fields more robust.

When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.

Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.

Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.

I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.

Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2d04277121f2f8e18b65190f0dfa8ca97e9c29cb

Modified Files
--------------
src/backend/nodes/outfuncs.c | 81 +++++++++++++++----------
src/backend/nodes/readfuncs.c | 128 ++++++++++++---------------------------
src/include/catalog/catversion.h | 2 +-
3 files changed, 88 insertions(+), 123 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2022-07-20 17:17:26 pgsql: Process shared_preload_libraries in single-user mode.
Previous Message Dave Page 2022-07-20 15:58:24 Re: pgsql: Default to hidden visibility for extension libraries where possi