LCOV - code coverage report
Current view: top level - src/backend/nodes - outfuncs.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 81.1 % 370 300
Test Date: 2026-03-10 17:14:41 Functions: 80.0 % 30 24
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * outfuncs.c
       4              :  *    Output functions for Postgres tree nodes.
       5              :  *
       6              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7              :  * Portions Copyright (c) 1994, Regents of the University of California
       8              :  *
       9              :  *
      10              :  * IDENTIFICATION
      11              :  *    src/backend/nodes/outfuncs.c
      12              :  *
      13              :  *-------------------------------------------------------------------------
      14              :  */
      15              : #include "postgres.h"
      16              : 
      17              : #include <ctype.h>
      18              : 
      19              : #include "access/attnum.h"
      20              : #include "common/shortest_dec.h"
      21              : #include "lib/stringinfo.h"
      22              : #include "miscadmin.h"
      23              : #include "nodes/bitmapset.h"
      24              : #include "nodes/nodes.h"
      25              : #include "nodes/pg_list.h"
      26              : #include "utils/datum.h"
      27              : 
      28              : /* State flag that determines how nodeToStringInternal() should treat location fields */
      29              : static bool write_location_fields = false;
      30              : 
      31              : static void outChar(StringInfo str, char c);
      32              : static void outDouble(StringInfo str, double d);
      33              : 
      34              : 
      35              : /*
      36              :  * Macros to simplify output of different kinds of fields.  Use these
      37              :  * wherever possible to reduce the chance for silly typos.  Note that these
      38              :  * hard-wire conventions about the names of the local variables in an Out
      39              :  * routine.
      40              :  */
      41              : 
      42              : /* Write the label for the node type */
      43              : #define WRITE_NODE_TYPE(nodelabel) \
      44              :     appendStringInfoString(str, nodelabel)
      45              : 
      46              : /* Write an integer field (anything written as ":fldname %d") */
      47              : #define WRITE_INT_FIELD(fldname) \
      48              :     appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
      49              : 
      50              : /* Write an unsigned integer field (anything written as ":fldname %u") */
      51              : #define WRITE_UINT_FIELD(fldname) \
      52              :     appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
      53              : 
      54              : /* Write a signed integer field (anything written with INT64_FORMAT) */
      55              : #define WRITE_INT64_FIELD(fldname) \
      56              :     appendStringInfo(str, \
      57              :                      " :" CppAsString(fldname) " " INT64_FORMAT, \
      58              :                      node->fldname)
      59              : 
      60              : /* Write an unsigned integer field (anything written with UINT64_FORMAT) */
      61              : #define WRITE_UINT64_FIELD(fldname) \
      62              :     appendStringInfo(str, " :" CppAsString(fldname) " " UINT64_FORMAT, \
      63              :                      node->fldname)
      64              : 
      65              : /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
      66              : #define WRITE_OID_FIELD(fldname) \
      67              :     appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
      68              : 
      69              : /* Write a long-integer field */
      70              : #define WRITE_LONG_FIELD(fldname) \
      71              :     appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
      72              : 
      73              : /* Write a char field (ie, one ascii character) */
      74              : #define WRITE_CHAR_FIELD(fldname) \
      75              :     (appendStringInfo(str, " :" CppAsString(fldname) " "), \
      76              :      outChar(str, node->fldname))
      77              : 
      78              : /* Write an enumerated-type field as an integer code */
      79              : #define WRITE_ENUM_FIELD(fldname, enumtype) \
      80              :     appendStringInfo(str, " :" CppAsString(fldname) " %d", \
      81              :                      (int) node->fldname)
      82              : 
      83              : /* Write a float field (actually, they're double) */
      84              : #define WRITE_FLOAT_FIELD(fldname) \
      85              :     (appendStringInfo(str, " :" CppAsString(fldname) " "), \
      86              :      outDouble(str, node->fldname))
      87              : 
      88              : /* Write a boolean field */
      89              : #define WRITE_BOOL_FIELD(fldname) \
      90              :     appendStringInfo(str, " :" CppAsString(fldname) " %s", \
      91              :                      booltostr(node->fldname))
      92              : 
      93              : /* Write a character-string (possibly NULL) field */
      94              : #define WRITE_STRING_FIELD(fldname) \
      95              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
      96              :      outToken(str, node->fldname))
      97              : 
      98              : /* Write a parse location field (actually same as INT case) */
      99              : #define WRITE_LOCATION_FIELD(fldname) \
     100              :     appendStringInfo(str, " :" CppAsString(fldname) " %d", write_location_fields ? node->fldname : -1)
     101              : 
     102              : /* Write a Node field */
     103              : #define WRITE_NODE_FIELD(fldname) \
     104              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     105              :      outNode(str, node->fldname))
     106              : 
     107              : /* Write a bitmapset field */
     108              : #define WRITE_BITMAPSET_FIELD(fldname) \
     109              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     110              :      outBitmapset(str, node->fldname))
     111              : 
     112              : /* Write a variable-length array (not a List) of Node pointers */
     113              : #define WRITE_NODE_ARRAY(fldname, len) \
     114              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     115              :      writeNodeArray(str, (const Node * const *) node->fldname, len))
     116              : 
     117              : /* Write a variable-length array of AttrNumber */
     118              : #define WRITE_ATTRNUMBER_ARRAY(fldname, len) \
     119              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     120              :      writeAttrNumberCols(str, node->fldname, len))
     121              : 
     122              : /* Write a variable-length array of Oid */
     123              : #define WRITE_OID_ARRAY(fldname, len) \
     124              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     125              :      writeOidCols(str, node->fldname, len))
     126              : 
     127              : /* Write a variable-length array of Index */
     128              : #define WRITE_INDEX_ARRAY(fldname, len) \
     129              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     130              :      writeIndexCols(str, node->fldname, len))
     131              : 
     132              : /* Write a variable-length array of int */
     133              : #define WRITE_INT_ARRAY(fldname, len) \
     134              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     135              :      writeIntCols(str, node->fldname, len))
     136              : 
     137              : /* Write a variable-length array of bool */
     138              : #define WRITE_BOOL_ARRAY(fldname, len) \
     139              :     (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
     140              :      writeBoolCols(str, node->fldname, len))
     141              : 
     142              : #define booltostr(x)  ((x) ? "true" : "false")
     143              : 
     144              : 
     145              : /*
     146              :  * outToken
     147              :  *    Convert an ordinary string (eg, an identifier) into a form that
     148              :  *    will be decoded back to a plain token by read.c's functions.
     149              :  *
     150              :  *    If a null string pointer is given, it is encoded as '<>'.
     151              :  *    An empty string is encoded as '""'.  To avoid ambiguity, input
     152              :  *    strings beginning with '<' or '"' receive a leading backslash.
     153              :  */
     154              : void
     155     27030822 : outToken(StringInfo str, const char *s)
     156              : {
     157     27030822 :     if (s == NULL)
     158              :     {
     159      5368182 :         appendStringInfoString(str, "<>");
     160      5368182 :         return;
     161              :     }
     162     21662640 :     if (*s == '\0')
     163              :     {
     164          108 :         appendStringInfoString(str, "\"\"");
     165          108 :         return;
     166              :     }
     167              : 
     168              :     /*
     169              :      * Look for characters or patterns that are treated specially by read.c
     170              :      * (either in pg_strtok() or in nodeRead()), and therefore need a
     171              :      * protective backslash.
     172              :      */
     173              :     /* These characters only need to be quoted at the start of the string */
     174     21662532 :     if (*s == '<' ||
     175     21626702 :         *s == '"' ||
     176     21623583 :         isdigit((unsigned char) *s) ||
     177     21520512 :         ((*s == '+' || *s == '-') &&
     178        16412 :          (isdigit((unsigned char) s[1]) || s[1] == '.')))
     179       144769 :         appendStringInfoChar(str, '\\');
     180    195655693 :     while (*s)
     181              :     {
     182              :         /* These chars must be backslashed anywhere in the string */
     183    173993161 :         if (*s == ' ' || *s == '\n' || *s == '\t' ||
     184    173386525 :             *s == '(' || *s == ')' || *s == '{' || *s == '}' ||
     185    173269544 :             *s == '\\')
     186       729668 :             appendStringInfoChar(str, '\\');
     187    173993161 :         appendStringInfoChar(str, *s++);
     188              :     }
     189              : }
     190              : 
     191              : /*
     192              :  * Convert one char.  Goes through outToken() so that special characters are
     193              :  * escaped.
     194              :  */
     195              : static void
     196      1612977 : outChar(StringInfo str, char c)
     197              : {
     198              :     char        in[2];
     199              : 
     200              :     /* Traditionally, we've represented \0 as <>, so keep doing that */
     201      1612977 :     if (c == '\0')
     202              :     {
     203       470378 :         appendStringInfoString(str, "<>");
     204       470378 :         return;
     205              :     }
     206              : 
     207      1142599 :     in[0] = c;
     208      1142599 :     in[1] = '\0';
     209              : 
     210      1142599 :     outToken(str, in);
     211              : }
     212              : 
     213              : /*
     214              :  * Convert a double value, attempting to ensure the value is preserved exactly.
     215              :  */
     216              : static void
     217      2066336 : outDouble(StringInfo str, double d)
     218              : {
     219              :     char        buf[DOUBLE_SHORTEST_DECIMAL_LEN];
     220              : 
     221      2066336 :     double_to_shortest_decimal_buf(d, buf);
     222      2066336 :     appendStringInfoString(str, buf);
     223      2066336 : }
     224              : 
     225              : /*
     226              :  * common implementation for scalar-array-writing functions
     227              :  *
     228              :  * The data format is either "<>" for a NULL pointer or "(item item item)".
     229              :  * fmtstr must include a leading space, and the rest of it must produce
     230              :  * something that will be seen as a single simple token by pg_strtok().
     231              :  * convfunc can be empty, or the name of a conversion macro or function.
     232              :  */
     233              : #define WRITE_SCALAR_ARRAY(fnname, datatype, fmtstr, convfunc) \
     234              : static void \
     235              : fnname(StringInfo str, const datatype *arr, int len) \
     236              : { \
     237              :     if (arr != NULL) \
     238              :     { \
     239              :         appendStringInfoChar(str, '('); \
     240              :         for (int i = 0; i < len; i++) \
     241              :             appendStringInfo(str, fmtstr, convfunc(arr[i])); \
     242              :         appendStringInfoChar(str, ')'); \
     243              :     } \
     244              :     else \
     245              :         appendStringInfoString(str, "<>"); \
     246              : }
     247              : 
     248       291115 : WRITE_SCALAR_ARRAY(writeAttrNumberCols, AttrNumber, " %d",)
     249       351716 : WRITE_SCALAR_ARRAY(writeOidCols, Oid, " %u",)
     250            0 : WRITE_SCALAR_ARRAY(writeIndexCols, Index, " %u",)
     251         7452 : WRITE_SCALAR_ARRAY(writeIntCols, int, " %d",)
     252       129694 : WRITE_SCALAR_ARRAY(writeBoolCols, bool, " %s", booltostr)
     253              : 
     254              : /*
     255              :  * Print an array (not a List) of Node pointers.
     256              :  *
     257              :  * The decoration is identical to that of scalar arrays, but we can't
     258              :  * quite use appendStringInfo() in the loop.
     259              :  */
     260              : static void
     261            0 : writeNodeArray(StringInfo str, const Node *const *arr, int len)
     262              : {
     263            0 :     if (arr != NULL)
     264              :     {
     265            0 :         appendStringInfoChar(str, '(');
     266            0 :         for (int i = 0; i < len; i++)
     267              :         {
     268            0 :             appendStringInfoChar(str, ' ');
     269            0 :             outNode(str, arr[i]);
     270              :         }
     271            0 :         appendStringInfoChar(str, ')');
     272              :     }
     273              :     else
     274            0 :         appendStringInfoString(str, "<>");
     275            0 : }
     276              : 
     277              : /*
     278              :  * Print a List.
     279              :  */
     280              : static void
     281     10058744 : _outList(StringInfo str, const List *node)
     282              : {
     283              :     const ListCell *lc;
     284              : 
     285     10058744 :     appendStringInfoChar(str, '(');
     286              : 
     287     10058744 :     if (IsA(node, IntList))
     288       282150 :         appendStringInfoChar(str, 'i');
     289      9776594 :     else if (IsA(node, OidList))
     290       396441 :         appendStringInfoChar(str, 'o');
     291      9380153 :     else if (IsA(node, XidList))
     292            0 :         appendStringInfoChar(str, 'x');
     293              : 
     294     43637393 :     foreach(lc, node)
     295              :     {
     296              :         /*
     297              :          * For the sake of backward compatibility, we emit a slightly
     298              :          * different whitespace format for lists of nodes vs. other types of
     299              :          * lists. XXX: is this necessary?
     300              :          */
     301     33578649 :         if (IsA(node, List))
     302              :         {
     303     30181342 :             outNode(str, lfirst(lc));
     304     30181342 :             if (lnext(node, lc))
     305     20801189 :                 appendStringInfoChar(str, ' ');
     306              :         }
     307      3397307 :         else if (IsA(node, IntList))
     308      2563086 :             appendStringInfo(str, " %d", lfirst_int(lc));
     309       834221 :         else if (IsA(node, OidList))
     310       834221 :             appendStringInfo(str, " %u", lfirst_oid(lc));
     311            0 :         else if (IsA(node, XidList))
     312            0 :             appendStringInfo(str, " %u", lfirst_xid(lc));
     313              :         else
     314            0 :             elog(ERROR, "unrecognized list node type: %d",
     315              :                  (int) node->type);
     316              :     }
     317              : 
     318     10058744 :     appendStringInfoChar(str, ')');
     319     10058744 : }
     320              : 
     321              : /*
     322              :  * outBitmapset -
     323              :  *     converts a bitmap set of integers
     324              :  *
     325              :  * Note: the output format is "(b int int ...)", similar to an integer List.
     326              :  *
     327              :  * We export this function for use by extensions that define extensible nodes.
     328              :  * That's somewhat historical, though, because calling outNode() will work.
     329              :  */
     330              : void
     331     10846771 : outBitmapset(StringInfo str, const Bitmapset *bms)
     332              : {
     333              :     int         x;
     334              : 
     335     10846771 :     appendStringInfoChar(str, '(');
     336     10846771 :     appendStringInfoChar(str, 'b');
     337     10846771 :     x = -1;
     338     14003612 :     while ((x = bms_next_member(bms, x)) >= 0)
     339      3156841 :         appendStringInfo(str, " %d", x);
     340     10846771 :     appendStringInfoChar(str, ')');
     341     10846771 : }
     342              : 
     343              : /*
     344              :  * Print the value of a Datum given its type.
     345              :  */
     346              : void
     347      1360105 : outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
     348              : {
     349              :     Size        length;
     350              :     char       *s;
     351              : 
     352      1360105 :     length = datumGetSize(value, typbyval, typlen);
     353              : 
     354      1360105 :     if (typbyval)
     355              :     {
     356       887483 :         s = (char *) (&value);
     357       887483 :         appendStringInfo(str, "%zu [ ", length);
     358      7987347 :         for (Size i = 0; i < (Size) sizeof(Datum); i++)
     359      7099864 :             appendStringInfo(str, "%d ", (int) (s[i]));
     360       887483 :         appendStringInfoChar(str, ']');
     361              :     }
     362              :     else
     363              :     {
     364       472622 :         s = (char *) DatumGetPointer(value);
     365       472622 :         if (!s)
     366            0 :             appendStringInfoString(str, "0 [ ]");
     367              :         else
     368              :         {
     369       472622 :             appendStringInfo(str, "%zu [ ", length);
     370     60456997 :             for (Size i = 0; i < length; i++)
     371     59984375 :                 appendStringInfo(str, "%d ", (int) (s[i]));
     372       472622 :             appendStringInfoChar(str, ']');
     373              :         }
     374              :     }
     375      1360105 : }
     376              : 
     377              : 
     378              : #include "outfuncs.funcs.c"
     379              : 
     380              : 
     381              : /*
     382              :  * Support functions for nodes with custom_read_write attribute or
     383              :  * special_read_write attribute
     384              :  */
     385              : 
     386              : static void
     387      1498755 : _outConst(StringInfo str, const Const *node)
     388              : {
     389      1498755 :     WRITE_NODE_TYPE("CONST");
     390              : 
     391      1498755 :     WRITE_OID_FIELD(consttype);
     392      1498755 :     WRITE_INT_FIELD(consttypmod);
     393      1498755 :     WRITE_OID_FIELD(constcollid);
     394      1498755 :     WRITE_INT_FIELD(constlen);
     395      1498755 :     WRITE_BOOL_FIELD(constbyval);
     396      1498755 :     WRITE_BOOL_FIELD(constisnull);
     397      1498755 :     WRITE_LOCATION_FIELD(location);
     398              : 
     399      1498755 :     appendStringInfoString(str, " :constvalue ");
     400      1498755 :     if (node->constisnull)
     401       138648 :         appendStringInfoString(str, "<>");
     402              :     else
     403      1360107 :         outDatum(str, node->constvalue, node->constlen, node->constbyval);
     404      1498755 : }
     405              : 
     406              : static void
     407       229699 : _outBoolExpr(StringInfo str, const BoolExpr *node)
     408              : {
     409       229699 :     char       *opstr = NULL;
     410              : 
     411       229699 :     WRITE_NODE_TYPE("BOOLEXPR");
     412              : 
     413              :     /* do-it-yourself enum representation */
     414       229699 :     switch (node->boolop)
     415              :     {
     416       163615 :         case AND_EXPR:
     417       163615 :             opstr = "and";
     418       163615 :             break;
     419        30509 :         case OR_EXPR:
     420        30509 :             opstr = "or";
     421        30509 :             break;
     422        35575 :         case NOT_EXPR:
     423        35575 :             opstr = "not";
     424        35575 :             break;
     425              :     }
     426       229699 :     appendStringInfoString(str, " :boolop ");
     427       229699 :     outToken(str, opstr);
     428              : 
     429       229699 :     WRITE_NODE_FIELD(args);
     430       229699 :     WRITE_LOCATION_FIELD(location);
     431       229699 : }
     432              : 
     433              : static void
     434            0 : _outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
     435              : {
     436            0 :     WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
     437              : 
     438            0 :     WRITE_UINT_FIELD(con_relid);
     439            0 :     WRITE_UINT_FIELD(ref_relid);
     440            0 :     WRITE_INT_FIELD(nkeys);
     441            0 :     WRITE_ATTRNUMBER_ARRAY(conkey, node->nkeys);
     442            0 :     WRITE_ATTRNUMBER_ARRAY(confkey, node->nkeys);
     443            0 :     WRITE_OID_ARRAY(conpfeqop, node->nkeys);
     444            0 :     WRITE_INT_FIELD(nmatched_ec);
     445            0 :     WRITE_INT_FIELD(nconst_ec);
     446            0 :     WRITE_INT_FIELD(nmatched_rcols);
     447            0 :     WRITE_INT_FIELD(nmatched_ri);
     448              :     /* for compactness, just print the number of matches per column: */
     449            0 :     appendStringInfoString(str, " :eclass");
     450            0 :     for (int i = 0; i < node->nkeys; i++)
     451            0 :         appendStringInfo(str, " %d", (node->eclass[i] != NULL));
     452            0 :     appendStringInfoString(str, " :rinfos");
     453            0 :     for (int i = 0; i < node->nkeys; i++)
     454            0 :         appendStringInfo(str, " %d", list_length(node->rinfos[i]));
     455            0 : }
     456              : 
     457              : static void
     458            0 : _outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
     459              : {
     460              :     /*
     461              :      * To simplify reading, we just chase up to the topmost merged EC and
     462              :      * print that, without bothering to show the merge-ees separately.
     463              :      */
     464            0 :     while (node->ec_merged)
     465            0 :         node = node->ec_merged;
     466              : 
     467            0 :     WRITE_NODE_TYPE("EQUIVALENCECLASS");
     468              : 
     469            0 :     WRITE_NODE_FIELD(ec_opfamilies);
     470            0 :     WRITE_OID_FIELD(ec_collation);
     471            0 :     WRITE_INT_FIELD(ec_childmembers_size);
     472            0 :     WRITE_NODE_FIELD(ec_members);
     473            0 :     WRITE_NODE_ARRAY(ec_childmembers, node->ec_childmembers_size);
     474            0 :     WRITE_NODE_FIELD(ec_sources);
     475              :     /* Only ec_derives_list is written; hash is not serialized. */
     476            0 :     WRITE_NODE_FIELD(ec_derives_list);
     477            0 :     WRITE_BITMAPSET_FIELD(ec_relids);
     478            0 :     WRITE_BOOL_FIELD(ec_has_const);
     479            0 :     WRITE_BOOL_FIELD(ec_has_volatile);
     480            0 :     WRITE_BOOL_FIELD(ec_broken);
     481            0 :     WRITE_UINT_FIELD(ec_sortref);
     482            0 :     WRITE_UINT_FIELD(ec_min_security);
     483            0 :     WRITE_UINT_FIELD(ec_max_security);
     484            0 : }
     485              : 
     486              : static void
     487            0 : _outExtensibleNode(StringInfo str, const ExtensibleNode *node)
     488              : {
     489              :     const ExtensibleNodeMethods *methods;
     490              : 
     491            0 :     methods = GetExtensibleNodeMethods(node->extnodename, false);
     492              : 
     493            0 :     WRITE_NODE_TYPE("EXTENSIBLENODE");
     494              : 
     495            0 :     WRITE_STRING_FIELD(extnodename);
     496              : 
     497              :     /* serialize the private fields */
     498            0 :     methods->nodeOut(str, node);
     499            0 : }
     500              : 
     501              : static void
     502       962513 : _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
     503              : {
     504       962513 :     WRITE_NODE_TYPE("RANGETBLENTRY");
     505              : 
     506       962513 :     WRITE_NODE_FIELD(alias);
     507       962513 :     WRITE_NODE_FIELD(eref);
     508       962513 :     WRITE_ENUM_FIELD(rtekind, RTEKind);
     509              : 
     510       962513 :     switch (node->rtekind)
     511              :     {
     512       572999 :         case RTE_RELATION:
     513       572999 :             WRITE_OID_FIELD(relid);
     514       572999 :             WRITE_BOOL_FIELD(inh);
     515       572999 :             WRITE_CHAR_FIELD(relkind);
     516       572999 :             WRITE_INT_FIELD(rellockmode);
     517       572999 :             WRITE_UINT_FIELD(perminfoindex);
     518       572999 :             WRITE_NODE_FIELD(tablesample);
     519       572999 :             break;
     520        88326 :         case RTE_SUBQUERY:
     521        88326 :             WRITE_NODE_FIELD(subquery);
     522        88326 :             WRITE_BOOL_FIELD(security_barrier);
     523              :             /* we re-use these RELATION fields, too: */
     524        88326 :             WRITE_OID_FIELD(relid);
     525        88326 :             WRITE_BOOL_FIELD(inh);
     526        88326 :             WRITE_CHAR_FIELD(relkind);
     527        88326 :             WRITE_INT_FIELD(rellockmode);
     528        88326 :             WRITE_UINT_FIELD(perminfoindex);
     529        88326 :             break;
     530       115602 :         case RTE_JOIN:
     531       115602 :             WRITE_ENUM_FIELD(jointype, JoinType);
     532       115602 :             WRITE_INT_FIELD(joinmergedcols);
     533       115602 :             WRITE_NODE_FIELD(joinaliasvars);
     534       115602 :             WRITE_NODE_FIELD(joinleftcols);
     535       115602 :             WRITE_NODE_FIELD(joinrightcols);
     536       115602 :             WRITE_NODE_FIELD(join_using_alias);
     537       115602 :             break;
     538        56908 :         case RTE_FUNCTION:
     539        56908 :             WRITE_NODE_FIELD(functions);
     540        56908 :             WRITE_BOOL_FIELD(funcordinality);
     541        56908 :             break;
     542          646 :         case RTE_TABLEFUNC:
     543          646 :             WRITE_NODE_FIELD(tablefunc);
     544          646 :             break;
     545        11149 :         case RTE_VALUES:
     546        11149 :             WRITE_NODE_FIELD(values_lists);
     547        11149 :             WRITE_NODE_FIELD(coltypes);
     548        11149 :             WRITE_NODE_FIELD(coltypmods);
     549        11149 :             WRITE_NODE_FIELD(colcollations);
     550        11149 :             break;
     551         6746 :         case RTE_CTE:
     552         6746 :             WRITE_STRING_FIELD(ctename);
     553         6746 :             WRITE_UINT_FIELD(ctelevelsup);
     554         6746 :             WRITE_BOOL_FIELD(self_reference);
     555         6746 :             WRITE_NODE_FIELD(coltypes);
     556         6746 :             WRITE_NODE_FIELD(coltypmods);
     557         6746 :             WRITE_NODE_FIELD(colcollations);
     558         6746 :             break;
     559          474 :         case RTE_NAMEDTUPLESTORE:
     560          474 :             WRITE_STRING_FIELD(enrname);
     561          474 :             WRITE_FLOAT_FIELD(enrtuples);
     562          474 :             WRITE_NODE_FIELD(coltypes);
     563          474 :             WRITE_NODE_FIELD(coltypmods);
     564          474 :             WRITE_NODE_FIELD(colcollations);
     565              :             /* we re-use these RELATION fields, too: */
     566          474 :             WRITE_OID_FIELD(relid);
     567          474 :             break;
     568       104333 :         case RTE_RESULT:
     569              :             /* no extra fields */
     570       104333 :             break;
     571         5330 :         case RTE_GROUP:
     572         5330 :             WRITE_NODE_FIELD(groupexprs);
     573         5330 :             break;
     574            0 :         default:
     575            0 :             elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
     576              :             break;
     577              :     }
     578              : 
     579       962513 :     WRITE_BOOL_FIELD(lateral);
     580       962513 :     WRITE_BOOL_FIELD(inFromCl);
     581       962513 :     WRITE_NODE_FIELD(securityQuals);
     582       962513 : }
     583              : 
     584              : static void
     585       361194 : _outA_Expr(StringInfo str, const A_Expr *node)
     586              : {
     587       361194 :     WRITE_NODE_TYPE("A_EXPR");
     588              : 
     589       361194 :     switch (node->kind)
     590              :     {
     591       334628 :         case AEXPR_OP:
     592       334628 :             WRITE_NODE_FIELD(name);
     593       334628 :             break;
     594         8785 :         case AEXPR_OP_ANY:
     595         8785 :             appendStringInfoString(str, " ANY");
     596         8785 :             WRITE_NODE_FIELD(name);
     597         8785 :             break;
     598           72 :         case AEXPR_OP_ALL:
     599           72 :             appendStringInfoString(str, " ALL");
     600           72 :             WRITE_NODE_FIELD(name);
     601           72 :             break;
     602          724 :         case AEXPR_DISTINCT:
     603          724 :             appendStringInfoString(str, " DISTINCT");
     604          724 :             WRITE_NODE_FIELD(name);
     605          724 :             break;
     606           67 :         case AEXPR_NOT_DISTINCT:
     607           67 :             appendStringInfoString(str, " NOT_DISTINCT");
     608           67 :             WRITE_NODE_FIELD(name);
     609           67 :             break;
     610          382 :         case AEXPR_NULLIF:
     611          382 :             appendStringInfoString(str, " NULLIF");
     612          382 :             WRITE_NODE_FIELD(name);
     613          382 :             break;
     614        14897 :         case AEXPR_IN:
     615        14897 :             appendStringInfoString(str, " IN");
     616        14897 :             WRITE_NODE_FIELD(name);
     617        14897 :             break;
     618         1176 :         case AEXPR_LIKE:
     619         1176 :             appendStringInfoString(str, " LIKE");
     620         1176 :             WRITE_NODE_FIELD(name);
     621         1176 :             break;
     622          102 :         case AEXPR_ILIKE:
     623          102 :             appendStringInfoString(str, " ILIKE");
     624          102 :             WRITE_NODE_FIELD(name);
     625          102 :             break;
     626           62 :         case AEXPR_SIMILAR:
     627           62 :             appendStringInfoString(str, " SIMILAR");
     628           62 :             WRITE_NODE_FIELD(name);
     629           62 :             break;
     630          281 :         case AEXPR_BETWEEN:
     631          281 :             appendStringInfoString(str, " BETWEEN");
     632          281 :             WRITE_NODE_FIELD(name);
     633          281 :             break;
     634            6 :         case AEXPR_NOT_BETWEEN:
     635            6 :             appendStringInfoString(str, " NOT_BETWEEN");
     636            6 :             WRITE_NODE_FIELD(name);
     637            6 :             break;
     638            6 :         case AEXPR_BETWEEN_SYM:
     639            6 :             appendStringInfoString(str, " BETWEEN_SYM");
     640            6 :             WRITE_NODE_FIELD(name);
     641            6 :             break;
     642            6 :         case AEXPR_NOT_BETWEEN_SYM:
     643            6 :             appendStringInfoString(str, " NOT_BETWEEN_SYM");
     644            6 :             WRITE_NODE_FIELD(name);
     645            6 :             break;
     646            0 :         default:
     647            0 :             elog(ERROR, "unrecognized A_Expr_Kind: %d", (int) node->kind);
     648              :             break;
     649              :     }
     650              : 
     651       361194 :     WRITE_NODE_FIELD(lexpr);
     652       361194 :     WRITE_NODE_FIELD(rexpr);
     653       361194 :     WRITE_LOCATION_FIELD(rexpr_list_start);
     654       361194 :     WRITE_LOCATION_FIELD(rexpr_list_end);
     655       361194 :     WRITE_LOCATION_FIELD(location);
     656       361194 : }
     657              : 
     658              : static void
     659       257945 : _outInteger(StringInfo str, const Integer *node)
     660              : {
     661       257945 :     appendStringInfo(str, "%d", node->ival);
     662       257945 : }
     663              : 
     664              : static void
     665         6085 : _outFloat(StringInfo str, const Float *node)
     666              : {
     667              :     /*
     668              :      * We assume the value is a valid numeric literal and so does not need
     669              :      * quoting.
     670              :      */
     671         6085 :     appendStringInfoString(str, node->fval);
     672         6085 : }
     673              : 
     674              : static void
     675        49395 : _outBoolean(StringInfo str, const Boolean *node)
     676              : {
     677        49395 :     appendStringInfoString(str, node->boolval ? "true" : "false");
     678        49395 : }
     679              : 
     680              : static void
     681     15458248 : _outString(StringInfo str, const String *node)
     682              : {
     683              :     /*
     684              :      * We use outToken to provide escaping of the string's content, but we
     685              :      * don't want it to convert an empty string to '""', because we're putting
     686              :      * double quotes around the string already.
     687              :      */
     688     15458248 :     appendStringInfoChar(str, '"');
     689     15458248 :     if (node->sval[0] != '\0')
     690     15441515 :         outToken(str, node->sval);
     691     15458248 :     appendStringInfoChar(str, '"');
     692     15458248 : }
     693              : 
     694              : static void
     695         2050 : _outBitString(StringInfo str, const BitString *node)
     696              : {
     697              :     /*
     698              :      * The lexer will always produce a string starting with 'b' or 'x'.  There
     699              :      * might be characters following that that need escaping, but outToken
     700              :      * won't escape the 'b' or 'x'.  This is relied on by nodeTokenType.
     701              :      */
     702              :     Assert(node->bsval[0] == 'b' || node->bsval[0] == 'x');
     703         2050 :     outToken(str, node->bsval);
     704         2050 : }
     705              : 
     706              : static void
     707       778832 : _outA_Const(StringInfo str, const A_Const *node)
     708              : {
     709       778832 :     WRITE_NODE_TYPE("A_CONST");
     710              : 
     711       778832 :     if (node->isnull)
     712        44569 :         appendStringInfoString(str, " NULL");
     713              :     else
     714              :     {
     715       734263 :         appendStringInfoString(str, " :val ");
     716       734263 :         outNode(str, &node->val);
     717              :     }
     718       778832 :     WRITE_LOCATION_FIELD(location);
     719       778832 : }
     720              : 
     721              : 
     722              : /*
     723              :  * outNode -
     724              :  *    converts a Node into ascii string and append it to 'str'
     725              :  */
     726              : void
     727     81979015 : outNode(StringInfo str, const void *obj)
     728              : {
     729              :     /* Guard against stack overflow due to overly complex expressions */
     730     81979015 :     check_stack_depth();
     731              : 
     732     81979015 :     if (obj == NULL)
     733     29235028 :         appendStringInfoString(str, "<>");
     734     52743987 :     else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList) ||
     735     42685234 :              IsA(obj, XidList))
     736     10058753 :         _outList(str, obj);
     737              :     /* nodeRead does not want to see { } around these! */
     738     42685234 :     else if (IsA(obj, Integer))
     739       257945 :         _outInteger(str, (const Integer *) obj);
     740     42427289 :     else if (IsA(obj, Float))
     741         6085 :         _outFloat(str, (const Float *) obj);
     742     42421204 :     else if (IsA(obj, Boolean))
     743        49395 :         _outBoolean(str, (const Boolean *) obj);
     744     42371809 :     else if (IsA(obj, String))
     745     15458248 :         _outString(str, (const String *) obj);
     746     26913561 :     else if (IsA(obj, BitString))
     747         2050 :         _outBitString(str, (const BitString *) obj);
     748     26911511 :     else if (IsA(obj, Bitmapset))
     749         1412 :         outBitmapset(str, (const Bitmapset *) obj);
     750              :     else
     751              :     {
     752     26910099 :         appendStringInfoChar(str, '{');
     753     26910099 :         switch (nodeTag(obj))
     754              :         {
     755              : #include "outfuncs.switch.c"
     756              : 
     757            0 :             default:
     758              : 
     759              :                 /*
     760              :                  * This should be an ERROR, but it's too useful to be able to
     761              :                  * dump structures that outNode only understands part of.
     762              :                  */
     763            0 :                 elog(WARNING, "could not dump unrecognized node type: %d",
     764              :                      (int) nodeTag(obj));
     765            0 :                 break;
     766              :         }
     767     26910099 :         appendStringInfoChar(str, '}');
     768              :     }
     769     81979015 : }
     770              : 
     771              : /*
     772              :  * nodeToString -
     773              :  *     returns the ascii representation of the Node as a palloc'd string
     774              :  *
     775              :  * write_loc_fields determines whether location fields are output with their
     776              :  * actual value rather than -1.  The actual value can be useful for debugging,
     777              :  * but for most uses, the actual value is not useful, since the original query
     778              :  * string is no longer available.
     779              :  */
     780              : static char *
     781      1063890 : nodeToStringInternal(const void *obj, bool write_loc_fields)
     782              : {
     783              :     StringInfoData str;
     784              :     bool        save_write_location_fields;
     785              : 
     786      1063890 :     save_write_location_fields = write_location_fields;
     787      1063890 :     write_location_fields = write_loc_fields;
     788              : 
     789              :     /* see stringinfo.h for an explanation of this maneuver */
     790      1063890 :     initStringInfo(&str);
     791      1063890 :     outNode(&str, obj);
     792              : 
     793      1063890 :     write_location_fields = save_write_location_fields;
     794              : 
     795      1063890 :     return str.data;
     796              : }
     797              : 
     798              : /*
     799              :  * Externally visible entry points
     800              :  */
     801              : char *
     802        36789 : nodeToString(const void *obj)
     803              : {
     804        36789 :     return nodeToStringInternal(obj, false);
     805              : }
     806              : 
     807              : char *
     808      1027101 : nodeToStringWithLocations(const void *obj)
     809              : {
     810      1027101 :     return nodeToStringInternal(obj, true);
     811              : }
     812              : 
     813              : 
     814              : /*
     815              :  * bmsToString -
     816              :  *     returns the ascii representation of the Bitmapset as a palloc'd string
     817              :  */
     818              : char *
     819            0 : bmsToString(const Bitmapset *bms)
     820              : {
     821              :     StringInfoData str;
     822              : 
     823              :     /* see stringinfo.h for an explanation of this maneuver */
     824            0 :     initStringInfo(&str);
     825            0 :     outBitmapset(&str, bms);
     826            0 :     return str.data;
     827              : }
        

Generated by: LCOV version 2.0-1