From 3158be824bfddfcfa7d32f641016fe678695773d Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Thu, 8 Feb 2024 20:24:22 +0100 Subject: [PATCH v6 5/8] nodeToString: omit serializing NULL datums in Const nodes This saves some bytes in certain cases, and aligns its serialization conditions with other field's serialization conditions. --- src/backend/nodes/outfuncs.c | 8 ++++---- src/backend/nodes/readfuncs.c | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index d1395b1940..bc57b7add6 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -504,11 +504,11 @@ _outConst(StringInfo str, const Const *node, bool omitLocation) WRITE_BOOL_FIELD(constisnull); WRITE_LOCATION_FIELD(location); - appendStringInfoString(str, " :constvalue "); - if (node->constisnull) - appendStringInfoString(str, "<>"); - else + if (!node->constisnull) + { + appendStringInfoString(str, " :constvalue "); outDatum(str, node->constvalue, node->constlen, node->constbyval); + } } static void diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 84df1c2868..bcdc39ba18 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -374,11 +374,13 @@ _readConst(void) READ_BOOL_FIELD(constisnull); READ_LOCATION_FIELD(location); - token = pg_strtok(&length); /* skip :constvalue */ - if (local_node->constisnull) - token = pg_strtok(&length); /* skip "<>" */ - else + if ((token = pg_strtok_fieldname(":constvalue", &length))) local_node->constvalue = readDatum(local_node->constbyval); + else + { + /* value was omitted */ + Assert(local_node->constisnull); + } READ_DONE(); } -- 2.40.1