LCOV - code coverage report
Current view: top level - src/backend/nodes - readfuncs.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 88.3 % 257 227
Test Date: 2026-02-17 17:20:33 Functions: 86.7 % 15 13
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * readfuncs.c
       4              :  *    Reader 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/readfuncs.c
      12              :  *
      13              :  * NOTES
      14              :  *    Parse location fields are written out by outfuncs.c, but only for
      15              :  *    debugging use.  When reading a location field, we normally discard
      16              :  *    the stored value and set the location field to -1 (ie, "unknown").
      17              :  *    This is because nodes coming from a stored rule should not be thought
      18              :  *    to have a known location in the current query's text.
      19              :  *
      20              :  *    However, if restore_location_fields is true, we do restore location
      21              :  *    fields from the string.  This is currently intended only for use by the
      22              :  *    debug_write_read_parse_plan_trees test code, which doesn't want to cause
      23              :  *    any change in the node contents.
      24              :  *
      25              :  *-------------------------------------------------------------------------
      26              :  */
      27              : #include "postgres.h"
      28              : 
      29              : #include "miscadmin.h"
      30              : #include "nodes/bitmapset.h"
      31              : #include "nodes/readfuncs.h"
      32              : 
      33              : 
      34              : /*
      35              :  * Macros to simplify reading of different kinds of fields.  Use these
      36              :  * wherever possible to reduce the chance for silly typos.  Note that these
      37              :  * hard-wire conventions about the names of the local variables in a Read
      38              :  * routine.
      39              :  */
      40              : 
      41              : /* Macros for declaring appropriate local variables */
      42              : 
      43              : /* A few guys need only local_node */
      44              : #define READ_LOCALS_NO_FIELDS(nodeTypeName) \
      45              :     nodeTypeName *local_node = makeNode(nodeTypeName)
      46              : 
      47              : /* And a few guys need only the pg_strtok support fields */
      48              : #define READ_TEMP_LOCALS()  \
      49              :     const char *token;      \
      50              :     int         length
      51              : 
      52              : /* ... but most need both */
      53              : #define READ_LOCALS(nodeTypeName)           \
      54              :     READ_LOCALS_NO_FIELDS(nodeTypeName);    \
      55              :     READ_TEMP_LOCALS()
      56              : 
      57              : /* Read an integer field (anything written as ":fldname %d") */
      58              : #define READ_INT_FIELD(fldname) \
      59              :     token = pg_strtok(&length);     /* skip :fldname */ \
      60              :     token = pg_strtok(&length);     /* get field value */ \
      61              :     local_node->fldname = atoi(token)
      62              : 
      63              : /* Read an unsigned integer field (anything written as ":fldname %u") */
      64              : #define READ_UINT_FIELD(fldname) \
      65              :     token = pg_strtok(&length);     /* skip :fldname */ \
      66              :     token = pg_strtok(&length);     /* get field value */ \
      67              :     local_node->fldname = atoui(token)
      68              : 
      69              : /* Read a signed integer field (anything written using INT64_FORMAT) */
      70              : #define READ_INT64_FIELD(fldname) \
      71              :     token = pg_strtok(&length); /* skip :fldname */ \
      72              :     token = pg_strtok(&length); /* get field value */ \
      73              :     local_node->fldname = strtoi64(token, NULL, 10)
      74              : 
      75              : /* Read an unsigned integer field (anything written using UINT64_FORMAT) */
      76              : #define READ_UINT64_FIELD(fldname) \
      77              :     token = pg_strtok(&length);     /* skip :fldname */ \
      78              :     token = pg_strtok(&length);     /* get field value */ \
      79              :     local_node->fldname = strtou64(token, NULL, 10)
      80              : 
      81              : /* Read a long integer field (anything written as ":fldname %ld") */
      82              : #define READ_LONG_FIELD(fldname) \
      83              :     token = pg_strtok(&length);     /* skip :fldname */ \
      84              :     token = pg_strtok(&length);     /* get field value */ \
      85              :     local_node->fldname = atol(token)
      86              : 
      87              : /* Read an OID field (don't hard-wire assumption that OID is same as uint) */
      88              : #define READ_OID_FIELD(fldname) \
      89              :     token = pg_strtok(&length);     /* skip :fldname */ \
      90              :     token = pg_strtok(&length);     /* get field value */ \
      91              :     local_node->fldname = atooid(token)
      92              : 
      93              : /* Read a char field (ie, one ascii character) */
      94              : #define READ_CHAR_FIELD(fldname) \
      95              :     token = pg_strtok(&length);     /* skip :fldname */ \
      96              :     token = pg_strtok(&length);     /* get field value */ \
      97              :     /* avoid overhead of calling debackslash() for one char */ \
      98              :     local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
      99              : 
     100              : /* Read an enumerated-type field that was written as an integer code */
     101              : #define READ_ENUM_FIELD(fldname, enumtype) \
     102              :     token = pg_strtok(&length);     /* skip :fldname */ \
     103              :     token = pg_strtok(&length);     /* get field value */ \
     104              :     local_node->fldname = (enumtype) atoi(token)
     105              : 
     106              : /* Read a float field */
     107              : #define READ_FLOAT_FIELD(fldname) \
     108              :     token = pg_strtok(&length);     /* skip :fldname */ \
     109              :     token = pg_strtok(&length);     /* get field value */ \
     110              :     local_node->fldname = atof(token)
     111              : 
     112              : /* Read a boolean field */
     113              : #define READ_BOOL_FIELD(fldname) \
     114              :     token = pg_strtok(&length);     /* skip :fldname */ \
     115              :     token = pg_strtok(&length);     /* get field value */ \
     116              :     local_node->fldname = strtobool(token)
     117              : 
     118              : /* Read a character-string field */
     119              : #define READ_STRING_FIELD(fldname) \
     120              :     token = pg_strtok(&length);     /* skip :fldname */ \
     121              :     token = pg_strtok(&length);     /* get field value */ \
     122              :     local_node->fldname = nullable_string(token, length)
     123              : 
     124              : /* Read a parse location field (and possibly throw away the value) */
     125              : #ifdef DEBUG_NODE_TESTS_ENABLED
     126              : #define READ_LOCATION_FIELD(fldname) \
     127              :     token = pg_strtok(&length);     /* skip :fldname */ \
     128              :     token = pg_strtok(&length);     /* get field value */ \
     129              :     local_node->fldname = restore_location_fields ? atoi(token) : -1
     130              : #else
     131              : #define READ_LOCATION_FIELD(fldname) \
     132              :     token = pg_strtok(&length);     /* skip :fldname */ \
     133              :     token = pg_strtok(&length);     /* get field value */ \
     134              :     (void) token;               /* in case not used elsewhere */ \
     135              :     local_node->fldname = -1 /* set field to "unknown" */
     136              : #endif
     137              : 
     138              : /* Read a Node field */
     139              : #define READ_NODE_FIELD(fldname) \
     140              :     token = pg_strtok(&length);     /* skip :fldname */ \
     141              :     (void) token;               /* in case not used elsewhere */ \
     142              :     local_node->fldname = nodeRead(NULL, 0)
     143              : 
     144              : /* Read a bitmapset field */
     145              : #define READ_BITMAPSET_FIELD(fldname) \
     146              :     token = pg_strtok(&length);     /* skip :fldname */ \
     147              :     (void) token;               /* in case not used elsewhere */ \
     148              :     local_node->fldname = _readBitmapset()
     149              : 
     150              : /* Read an attribute number array */
     151              : #define READ_ATTRNUMBER_ARRAY(fldname, len) \
     152              :     token = pg_strtok(&length);     /* skip :fldname */ \
     153              :     local_node->fldname = readAttrNumberCols(len)
     154              : 
     155              : /* Read an oid array */
     156              : #define READ_OID_ARRAY(fldname, len) \
     157              :     token = pg_strtok(&length);     /* skip :fldname */ \
     158              :     local_node->fldname = readOidCols(len)
     159              : 
     160              : /* Read an int array */
     161              : #define READ_INT_ARRAY(fldname, len) \
     162              :     token = pg_strtok(&length);     /* skip :fldname */ \
     163              :     local_node->fldname = readIntCols(len)
     164              : 
     165              : /* Read a bool array */
     166              : #define READ_BOOL_ARRAY(fldname, len) \
     167              :     token = pg_strtok(&length);     /* skip :fldname */ \
     168              :     local_node->fldname = readBoolCols(len)
     169              : 
     170              : /* Routine exit */
     171              : #define READ_DONE() \
     172              :     return local_node
     173              : 
     174              : 
     175              : /*
     176              :  * NOTE: use atoi() to read values written with %d, or atoui() to read
     177              :  * values written with %u in outfuncs.c.  An exception is OID values,
     178              :  * for which use atooid().  (As of 7.1, outfuncs.c writes OIDs as %u,
     179              :  * but this will probably change in the future.)
     180              :  */
     181              : #define atoui(x)  ((unsigned int) strtoul((x), NULL, 10))
     182              : 
     183              : #define strtobool(x)  ((*(x) == 't') ? true : false)
     184              : 
     185              : static char *
     186     10059297 : nullable_string(const char *token, int length)
     187              : {
     188              :     /* outToken emits <> for NULL, and pg_strtok makes that an empty string */
     189     10059297 :     if (length == 0)
     190      5222966 :         return NULL;
     191              :     /* outToken emits "" for empty string */
     192      4836331 :     if (length == 2 && token[0] == '"' && token[1] == '"')
     193           96 :         return pstrdup("");
     194              :     /* otherwise, we must remove protective backslashes added by outToken */
     195      4836235 :     return debackslash(token, length);
     196              : }
     197              : 
     198              : 
     199              : /*
     200              :  * _readBitmapset
     201              :  *
     202              :  * Note: this code is used in contexts where we know that a Bitmapset
     203              :  * is expected.  There is equivalent code in nodeRead() that can read a
     204              :  * Bitmapset when we come across one in other contexts.
     205              :  */
     206              : static Bitmapset *
     207     10839087 : _readBitmapset(void)
     208              : {
     209     10839087 :     Bitmapset  *result = NULL;
     210              : 
     211              :     READ_TEMP_LOCALS();
     212              : 
     213     10839087 :     token = pg_strtok(&length);
     214     10839087 :     if (token == NULL)
     215            0 :         elog(ERROR, "incomplete Bitmapset structure");
     216     10839087 :     if (length != 1 || token[0] != '(')
     217            0 :         elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
     218              : 
     219     10839087 :     token = pg_strtok(&length);
     220     10839087 :     if (token == NULL)
     221            0 :         elog(ERROR, "incomplete Bitmapset structure");
     222     10839087 :     if (length != 1 || token[0] != 'b')
     223            0 :         elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
     224              : 
     225              :     for (;;)
     226      3091598 :     {
     227              :         int         val;
     228              :         char       *endptr;
     229              : 
     230     13930685 :         token = pg_strtok(&length);
     231     13930685 :         if (token == NULL)
     232            0 :             elog(ERROR, "unterminated Bitmapset structure");
     233     13930685 :         if (length == 1 && token[0] == ')')
     234     10839087 :             break;
     235      3091598 :         val = (int) strtol(token, &endptr, 10);
     236      3091598 :         if (endptr != token + length)
     237            0 :             elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
     238      3091598 :         result = bms_add_member(result, val);
     239              :     }
     240              : 
     241     10839087 :     return result;
     242              : }
     243              : 
     244              : /*
     245              :  * We export this function for use by extensions that define extensible nodes.
     246              :  * That's somewhat historical, though, because calling nodeRead() will work.
     247              :  */
     248              : Bitmapset *
     249            0 : readBitmapset(void)
     250              : {
     251            0 :     return _readBitmapset();
     252              : }
     253              : 
     254              : #include "readfuncs.funcs.c"
     255              : 
     256              : 
     257              : /*
     258              :  * Support functions for nodes with custom_read_write attribute or
     259              :  * special_read_write attribute
     260              :  */
     261              : 
     262              : static Const *
     263      1609769 : _readConst(void)
     264              : {
     265      1609769 :     READ_LOCALS(Const);
     266              : 
     267      1609769 :     READ_OID_FIELD(consttype);
     268      1609769 :     READ_INT_FIELD(consttypmod);
     269      1609769 :     READ_OID_FIELD(constcollid);
     270      1609769 :     READ_INT_FIELD(constlen);
     271      1609769 :     READ_BOOL_FIELD(constbyval);
     272      1609769 :     READ_BOOL_FIELD(constisnull);
     273      1609769 :     READ_LOCATION_FIELD(location);
     274              : 
     275      1609769 :     token = pg_strtok(&length); /* skip :constvalue */
     276      1609769 :     if (local_node->constisnull)
     277       155106 :         token = pg_strtok(&length); /* skip "<>" */
     278              :     else
     279      1454663 :         local_node->constvalue = readDatum(local_node->constbyval);
     280              : 
     281      1609769 :     READ_DONE();
     282              : }
     283              : 
     284              : static BoolExpr *
     285       202884 : _readBoolExpr(void)
     286              : {
     287       202884 :     READ_LOCALS(BoolExpr);
     288              : 
     289              :     /* do-it-yourself enum representation */
     290       202884 :     token = pg_strtok(&length); /* skip :boolop */
     291       202884 :     token = pg_strtok(&length); /* get field value */
     292       202884 :     if (length == 3 && strncmp(token, "and", 3) == 0)
     293       153623 :         local_node->boolop = AND_EXPR;
     294        49261 :     else if (length == 2 && strncmp(token, "or", 2) == 0)
     295        24069 :         local_node->boolop = OR_EXPR;
     296        25192 :     else if (length == 3 && strncmp(token, "not", 3) == 0)
     297        25192 :         local_node->boolop = NOT_EXPR;
     298              :     else
     299            0 :         elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
     300              : 
     301       202884 :     READ_NODE_FIELD(args);
     302       202884 :     READ_LOCATION_FIELD(location);
     303              : 
     304       202884 :     READ_DONE();
     305              : }
     306              : 
     307              : static A_Const *
     308       751865 : _readA_Const(void)
     309              : {
     310       751865 :     READ_LOCALS(A_Const);
     311              : 
     312              :     /* We expect either NULL or :val here */
     313       751865 :     token = pg_strtok(&length);
     314       751865 :     if (length == 4 && strncmp(token, "NULL", 4) == 0)
     315        44042 :         local_node->isnull = true;
     316              :     else
     317              :     {
     318       707823 :         union ValUnion *tmp = nodeRead(NULL, 0);
     319              : 
     320              :         /* To forestall valgrind complaints, copy only the valid data */
     321       707823 :         switch (nodeTag(tmp))
     322              :         {
     323       229979 :             case T_Integer:
     324       229979 :                 memcpy(&local_node->val, tmp, sizeof(Integer));
     325       229979 :                 break;
     326         6053 :             case T_Float:
     327         6053 :                 memcpy(&local_node->val, tmp, sizeof(Float));
     328         6053 :                 break;
     329        36124 :             case T_Boolean:
     330        36124 :                 memcpy(&local_node->val, tmp, sizeof(Boolean));
     331        36124 :                 break;
     332       433632 :             case T_String:
     333       433632 :                 memcpy(&local_node->val, tmp, sizeof(String));
     334       433632 :                 break;
     335         2035 :             case T_BitString:
     336         2035 :                 memcpy(&local_node->val, tmp, sizeof(BitString));
     337         2035 :                 break;
     338            0 :             default:
     339            0 :                 elog(ERROR, "unrecognized node type: %d",
     340              :                      (int) nodeTag(tmp));
     341              :                 break;
     342              :         }
     343              :     }
     344              : 
     345       751865 :     READ_LOCATION_FIELD(location);
     346              : 
     347       751865 :     READ_DONE();
     348              : }
     349              : 
     350              : static RangeTblEntry *
     351       957688 : _readRangeTblEntry(void)
     352              : {
     353       957688 :     READ_LOCALS(RangeTblEntry);
     354              : 
     355       957688 :     READ_NODE_FIELD(alias);
     356       957688 :     READ_NODE_FIELD(eref);
     357       957688 :     READ_ENUM_FIELD(rtekind, RTEKind);
     358              : 
     359       957688 :     switch (local_node->rtekind)
     360              :     {
     361       566562 :         case RTE_RELATION:
     362       566562 :             READ_OID_FIELD(relid);
     363       566562 :             READ_BOOL_FIELD(inh);
     364       566562 :             READ_CHAR_FIELD(relkind);
     365       566562 :             READ_INT_FIELD(rellockmode);
     366       566562 :             READ_UINT_FIELD(perminfoindex);
     367       566562 :             READ_NODE_FIELD(tablesample);
     368       566562 :             break;
     369        90626 :         case RTE_SUBQUERY:
     370        90626 :             READ_NODE_FIELD(subquery);
     371        90626 :             READ_BOOL_FIELD(security_barrier);
     372              :             /* we re-use these RELATION fields, too: */
     373        90626 :             READ_OID_FIELD(relid);
     374        90626 :             READ_BOOL_FIELD(inh);
     375        90626 :             READ_CHAR_FIELD(relkind);
     376        90626 :             READ_INT_FIELD(rellockmode);
     377        90626 :             READ_UINT_FIELD(perminfoindex);
     378        90626 :             break;
     379       114746 :         case RTE_JOIN:
     380       114746 :             READ_ENUM_FIELD(jointype, JoinType);
     381       114746 :             READ_INT_FIELD(joinmergedcols);
     382       114746 :             READ_NODE_FIELD(joinaliasvars);
     383       114746 :             READ_NODE_FIELD(joinleftcols);
     384       114746 :             READ_NODE_FIELD(joinrightcols);
     385       114746 :             READ_NODE_FIELD(join_using_alias);
     386       114746 :             break;
     387        59091 :         case RTE_FUNCTION:
     388        59091 :             READ_NODE_FIELD(functions);
     389        59091 :             READ_BOOL_FIELD(funcordinality);
     390        59091 :             break;
     391          744 :         case RTE_TABLEFUNC:
     392          744 :             READ_NODE_FIELD(tablefunc);
     393              :             /* The RTE must have a copy of the column type info, if any */
     394          744 :             if (local_node->tablefunc)
     395              :             {
     396          431 :                 TableFunc  *tf = local_node->tablefunc;
     397              : 
     398          431 :                 local_node->coltypes = tf->coltypes;
     399          431 :                 local_node->coltypmods = tf->coltypmods;
     400          431 :                 local_node->colcollations = tf->colcollations;
     401              :             }
     402          744 :             break;
     403        11579 :         case RTE_VALUES:
     404        11579 :             READ_NODE_FIELD(values_lists);
     405        11579 :             READ_NODE_FIELD(coltypes);
     406        11579 :             READ_NODE_FIELD(coltypmods);
     407        11579 :             READ_NODE_FIELD(colcollations);
     408        11579 :             break;
     409         6473 :         case RTE_CTE:
     410         6473 :             READ_STRING_FIELD(ctename);
     411         6473 :             READ_UINT_FIELD(ctelevelsup);
     412         6473 :             READ_BOOL_FIELD(self_reference);
     413         6473 :             READ_NODE_FIELD(coltypes);
     414         6473 :             READ_NODE_FIELD(coltypmods);
     415         6473 :             READ_NODE_FIELD(colcollations);
     416         6473 :             break;
     417          474 :         case RTE_NAMEDTUPLESTORE:
     418          474 :             READ_STRING_FIELD(enrname);
     419          474 :             READ_FLOAT_FIELD(enrtuples);
     420          474 :             READ_NODE_FIELD(coltypes);
     421          474 :             READ_NODE_FIELD(coltypmods);
     422          474 :             READ_NODE_FIELD(colcollations);
     423              :             /* we re-use these RELATION fields, too: */
     424          474 :             READ_OID_FIELD(relid);
     425          474 :             break;
     426       101392 :         case RTE_RESULT:
     427              :             /* no extra fields */
     428       101392 :             break;
     429         6001 :         case RTE_GROUP:
     430         6001 :             READ_NODE_FIELD(groupexprs);
     431         6001 :             break;
     432            0 :         default:
     433            0 :             elog(ERROR, "unrecognized RTE kind: %d",
     434              :                  (int) local_node->rtekind);
     435              :             break;
     436              :     }
     437              : 
     438       957688 :     READ_BOOL_FIELD(lateral);
     439       957688 :     READ_BOOL_FIELD(inFromCl);
     440       957688 :     READ_NODE_FIELD(securityQuals);
     441              : 
     442       957688 :     READ_DONE();
     443              : }
     444              : 
     445              : static A_Expr *
     446       338433 : _readA_Expr(void)
     447              : {
     448       338433 :     READ_LOCALS(A_Expr);
     449              : 
     450       338433 :     token = pg_strtok(&length);
     451              : 
     452       338433 :     if (length == 3 && strncmp(token, "ANY", 3) == 0)
     453              :     {
     454         8446 :         local_node->kind = AEXPR_OP_ANY;
     455         8446 :         READ_NODE_FIELD(name);
     456              :     }
     457       329987 :     else if (length == 3 && strncmp(token, "ALL", 3) == 0)
     458              :     {
     459           72 :         local_node->kind = AEXPR_OP_ALL;
     460           72 :         READ_NODE_FIELD(name);
     461              :     }
     462       329915 :     else if (length == 8 && strncmp(token, "DISTINCT", 8) == 0)
     463              :     {
     464          585 :         local_node->kind = AEXPR_DISTINCT;
     465          585 :         READ_NODE_FIELD(name);
     466              :     }
     467       329330 :     else if (length == 12 && strncmp(token, "NOT_DISTINCT", 12) == 0)
     468              :     {
     469           67 :         local_node->kind = AEXPR_NOT_DISTINCT;
     470           67 :         READ_NODE_FIELD(name);
     471              :     }
     472       329263 :     else if (length == 6 && strncmp(token, "NULLIF", 6) == 0)
     473              :     {
     474          316 :         local_node->kind = AEXPR_NULLIF;
     475          316 :         READ_NODE_FIELD(name);
     476              :     }
     477       328947 :     else if (length == 2 && strncmp(token, "IN", 2) == 0)
     478              :     {
     479        14429 :         local_node->kind = AEXPR_IN;
     480        14429 :         READ_NODE_FIELD(name);
     481              :     }
     482       314518 :     else if (length == 4 && strncmp(token, "LIKE", 4) == 0)
     483              :     {
     484         1175 :         local_node->kind = AEXPR_LIKE;
     485         1175 :         READ_NODE_FIELD(name);
     486              :     }
     487       313343 :     else if (length == 5 && strncmp(token, "ILIKE", 5) == 0)
     488              :     {
     489          101 :         local_node->kind = AEXPR_ILIKE;
     490          101 :         READ_NODE_FIELD(name);
     491              :     }
     492       313242 :     else if (length == 7 && strncmp(token, "SIMILAR", 7) == 0)
     493              :     {
     494           62 :         local_node->kind = AEXPR_SIMILAR;
     495           62 :         READ_NODE_FIELD(name);
     496              :     }
     497       313180 :     else if (length == 7 && strncmp(token, "BETWEEN", 7) == 0)
     498              :     {
     499          281 :         local_node->kind = AEXPR_BETWEEN;
     500          281 :         READ_NODE_FIELD(name);
     501              :     }
     502       312899 :     else if (length == 11 && strncmp(token, "NOT_BETWEEN", 11) == 0)
     503              :     {
     504            6 :         local_node->kind = AEXPR_NOT_BETWEEN;
     505            6 :         READ_NODE_FIELD(name);
     506              :     }
     507       312893 :     else if (length == 11 && strncmp(token, "BETWEEN_SYM", 11) == 0)
     508              :     {
     509            6 :         local_node->kind = AEXPR_BETWEEN_SYM;
     510            6 :         READ_NODE_FIELD(name);
     511              :     }
     512       312887 :     else if (length == 15 && strncmp(token, "NOT_BETWEEN_SYM", 15) == 0)
     513              :     {
     514            6 :         local_node->kind = AEXPR_NOT_BETWEEN_SYM;
     515            6 :         READ_NODE_FIELD(name);
     516              :     }
     517       312881 :     else if (length == 5 && strncmp(token, ":name", 5) == 0)
     518              :     {
     519       312881 :         local_node->kind = AEXPR_OP;
     520       312881 :         local_node->name = nodeRead(NULL, 0);
     521              :     }
     522              :     else
     523            0 :         elog(ERROR, "unrecognized A_Expr kind: \"%.*s\"", length, token);
     524              : 
     525       338433 :     READ_NODE_FIELD(lexpr);
     526       338433 :     READ_NODE_FIELD(rexpr);
     527       338433 :     READ_LOCATION_FIELD(rexpr_list_start);
     528       338433 :     READ_LOCATION_FIELD(rexpr_list_end);
     529       338433 :     READ_LOCATION_FIELD(location);
     530              : 
     531       338433 :     READ_DONE();
     532              : }
     533              : 
     534              : static ExtensibleNode *
     535            0 : _readExtensibleNode(void)
     536              : {
     537              :     const ExtensibleNodeMethods *methods;
     538              :     ExtensibleNode *local_node;
     539              :     const char *extnodename;
     540              : 
     541              :     READ_TEMP_LOCALS();
     542              : 
     543            0 :     token = pg_strtok(&length); /* skip :extnodename */
     544            0 :     token = pg_strtok(&length); /* get extnodename */
     545              : 
     546            0 :     extnodename = nullable_string(token, length);
     547            0 :     if (!extnodename)
     548            0 :         elog(ERROR, "extnodename has to be supplied");
     549            0 :     methods = GetExtensibleNodeMethods(extnodename, false);
     550              : 
     551            0 :     local_node = (ExtensibleNode *) newNode(methods->node_size,
     552              :                                             T_ExtensibleNode);
     553            0 :     local_node->extnodename = extnodename;
     554              : 
     555              :     /* deserialize the private fields */
     556            0 :     methods->nodeRead(local_node);
     557              : 
     558            0 :     READ_DONE();
     559              : }
     560              : 
     561              : 
     562              : /*
     563              :  * parseNodeString
     564              :  *
     565              :  * Given a character string representing a node tree, parseNodeString creates
     566              :  * the internal node structure.
     567              :  *
     568              :  * The string to be read must already have been loaded into pg_strtok().
     569              :  */
     570              : Node *
     571     26912332 : parseNodeString(void)
     572              : {
     573              :     READ_TEMP_LOCALS();
     574              : 
     575              :     /* Guard against stack overflow due to overly complex expressions */
     576     26912332 :     check_stack_depth();
     577              : 
     578     26912332 :     token = pg_strtok(&length);
     579              : 
     580              : #define MATCH(tokname, namelen) \
     581              :     (length == namelen && memcmp(token, tokname, namelen) == 0)
     582              : 
     583              : #include "readfuncs.switch.c"
     584              : 
     585            0 :     elog(ERROR, "badly formatted node string \"%.32s\"...", token);
     586              :     return NULL;                /* keep compiler quiet */
     587              : }
     588              : 
     589              : 
     590              : /*
     591              :  * readDatum
     592              :  *
     593              :  * Given a string representation of a constant, recreate the appropriate
     594              :  * Datum.  The string representation embeds length info, but not byValue,
     595              :  * so we must be told that.
     596              :  */
     597              : Datum
     598      1454663 : readDatum(bool typbyval)
     599              : {
     600              :     Size        length;
     601              :     int         tokenLength;
     602              :     const char *token;
     603              :     Datum       res;
     604              :     char       *s;
     605              : 
     606              :     /*
     607              :      * read the actual length of the value
     608              :      */
     609      1454663 :     token = pg_strtok(&tokenLength);
     610      1454663 :     length = atoui(token);
     611              : 
     612      1454663 :     token = pg_strtok(&tokenLength);    /* read the '[' */
     613      1454663 :     if (token == NULL || token[0] != '[')
     614            0 :         elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
     615              :              token ? token : "[NULL]", length);
     616              : 
     617      1454663 :     if (typbyval)
     618              :     {
     619       958374 :         if (length > (Size) sizeof(Datum))
     620            0 :             elog(ERROR, "byval datum but length = %zu", length);
     621       958374 :         res = (Datum) 0;
     622       958374 :         s = (char *) (&res);
     623      8625366 :         for (Size i = 0; i < (Size) sizeof(Datum); i++)
     624              :         {
     625      7666992 :             token = pg_strtok(&tokenLength);
     626      7666992 :             s[i] = (char) atoi(token);
     627              :         }
     628              :     }
     629       496289 :     else if (length <= 0)
     630            0 :         res = (Datum) 0;
     631              :     else
     632              :     {
     633       496289 :         s = (char *) palloc(length);
     634     61144330 :         for (Size i = 0; i < length; i++)
     635              :         {
     636     60648041 :             token = pg_strtok(&tokenLength);
     637     60648041 :             s[i] = (char) atoi(token);
     638              :         }
     639       496289 :         res = PointerGetDatum(s);
     640              :     }
     641              : 
     642      1454663 :     token = pg_strtok(&tokenLength);    /* read the ']' */
     643      1454663 :     if (token == NULL || token[0] != ']')
     644            0 :         elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
     645              :              token ? token : "[NULL]", length);
     646              : 
     647      1454663 :     return res;
     648              : }
     649              : 
     650              : /*
     651              :  * common implementation for scalar-array-reading functions
     652              :  *
     653              :  * The data format is either "<>" for a NULL pointer (in which case numCols
     654              :  * is ignored) or "(item item item)" where the number of items must equal
     655              :  * numCols.  The convfunc must be okay with stopping at whitespace or a
     656              :  * right parenthesis, since pg_strtok won't null-terminate the token.
     657              :  */
     658              : #define READ_SCALAR_ARRAY(fnname, datatype, convfunc) \
     659              : datatype * \
     660              : fnname(int numCols) \
     661              : { \
     662              :     datatype   *vals; \
     663              :     READ_TEMP_LOCALS(); \
     664              :     token = pg_strtok(&length); \
     665              :     if (token == NULL) \
     666              :         elog(ERROR, "incomplete scalar array"); \
     667              :     if (length == 0) \
     668              :         return NULL;            /* it was "<>", so return NULL pointer */ \
     669              :     if (length != 1 || token[0] != '(') \
     670              :         elog(ERROR, "unrecognized token: \"%.*s\"", length, token); \
     671              :     vals = (datatype *) palloc(numCols * sizeof(datatype)); \
     672              :     for (int i = 0; i < numCols; i++) \
     673              :     { \
     674              :         token = pg_strtok(&length); \
     675              :         if (token == NULL || token[0] == ')') \
     676              :             elog(ERROR, "incomplete scalar array"); \
     677              :         vals[i] = convfunc(token); \
     678              :     } \
     679              :     token = pg_strtok(&length); \
     680              :     if (token == NULL || length != 1 || token[0] != ')') \
     681              :         elog(ERROR, "incomplete scalar array"); \
     682              :     return vals; \
     683              : }
     684              : 
     685              : /*
     686              :  * Note: these functions are exported in nodes.h for possible use by
     687              :  * extensions, so don't mess too much with their names or API.
     688              :  */
     689       275244 : READ_SCALAR_ARRAY(readAttrNumberCols, int16, atoi)
     690       336285 : READ_SCALAR_ARRAY(readOidCols, Oid, atooid)
     691              : /* outfuncs.c has writeIndexCols, but we don't yet need that here */
     692              : /* READ_SCALAR_ARRAY(readIndexCols, Index, atoui) */
     693         8205 : READ_SCALAR_ARRAY(readIntCols, int, atoi)
     694       121613 : READ_SCALAR_ARRAY(readBoolCols, bool, strtobool)
        

Generated by: LCOV version 2.0-1