Add WRITE_INDEX_ARRAY
authorPeter Eisentraut <[email protected]>
Tue, 14 Sep 2021 07:34:50 +0000 (09:34 +0200)
committerPeter Eisentraut <[email protected]>
Tue, 14 Sep 2021 08:27:38 +0000 (10:27 +0200)
We have a few WRITE_{name of type}_ARRAY macros, but the one case
using the Index type was hand-coded.  Wrap it into a macro as well.

This also changes the behavior slightly: Before, the field name was
skipped if the length was zero.  Now it prints the field name even in
that case.  This is more consistent with how other array fields are
handled.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/c091e5cd-45f8-69ee-6a9b-de86912cc7e7@enterprisedb.com

src/backend/nodes/outfuncs.c

index 36e618611fd16125a4a72e4fbeedc703e598c9d3..f2a6a6e7a08f76e58131e4e6c04a1a60eb1b6949 100644 (file)
@@ -124,6 +124,13 @@ static void outChar(StringInfo str, char c);
                        appendStringInfo(str, " %u", node->fldname[i]); \
        } while(0)
 
+#define WRITE_INDEX_ARRAY(fldname, len) \
+       do { \
+               appendStringInfoString(str, " :" CppAsString(fldname) " "); \
+               for (int i = 0; i < len; i++) \
+                       appendStringInfo(str, " %u", node->fldname[i]); \
+       } while(0)
+
 #define WRITE_INT_ARRAY(fldname, len) \
        do { \
                appendStringInfoString(str, " :" CppAsString(fldname) " "); \
@@ -2510,14 +2517,7 @@ _outPathTarget(StringInfo str, const PathTarget *node)
        WRITE_NODE_TYPE("PATHTARGET");
 
        WRITE_NODE_FIELD(exprs);
-       if (node->sortgrouprefs)
-       {
-               int                     i;
-
-               appendStringInfoString(str, " :sortgrouprefs");
-               for (i = 0; i < list_length(node->exprs); i++)
-                       appendStringInfo(str, " %u", node->sortgrouprefs[i]);
-       }
+       WRITE_INDEX_ARRAY(sortgrouprefs, list_length(node->exprs));
        WRITE_FLOAT_FIELD(cost.startup, "%.2f");
        WRITE_FLOAT_FIELD(cost.per_tuple, "%.2f");
        WRITE_INT_FIELD(width);