LCOV - differential code coverage report
Current view: top level - src/backend/nodes - readfuncs.c (source / functions) Coverage Total Hit UNC UBC GBC GNC CBC DUB DCB
Current: f76c13edadc2b319036e0d238703ed56bb23f934 vs 9e17d25e79d4756be08b4a5521b4b58450217137 Lines: 59.5 % 257 153 8 96 6 24 123 12 20
Current Date: 2026-09-20 14:13:17 +0900 Functions: 80.0 % 15 12 3 7 5 4 6
Baseline: lcov-20260920-baseline Branches: 33.9 % 307 104 203 1 103
Baseline Date: 2026-09-20 14:13:13 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 75.0 % 32 24 8 24
(30,360] days: 100.0 % 2 2 2
(360..) days: 57.0 % 223 127 96 6 121
Function coverage date bins:
(7,30] days: 70.0 % 10 7 3 7
(360..) days: 100.0 % 5 5 5
Branch coverage date bins:
(30,360] days: 100.0 % 4 4 4
(360..) days: 33.0 % 303 100 203 1 99

 Age         Owner                    Branch data    TLA  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(ctx, &length);        /* skip :fldname */ \
                                 60                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                 66                 :                :     token = pg_strtok(ctx, &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(ctx, &length); /* skip :fldname */ \
                                 72                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                 78                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                 84                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                 90                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                 96                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                103                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                109                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                115                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                121                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                128                 :                :     token = pg_strtok(ctx, &length);        /* get field value */ \
                                129                 :                :     local_node->fldname = ctx->restore_location_fields ? atoi(token) : -1
                                130                 :                : #else
                                131                 :                : #define READ_LOCATION_FIELD(fldname) \
                                132                 :                :     token = pg_strtok(ctx, &length);        /* skip :fldname */ \
                                133                 :                :     token = pg_strtok(ctx, &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(ctx, &length);        /* skip :fldname */ \
                                141                 :                :     (void) token;               /* in case not used elsewhere */ \
                                142                 :                :     local_node->fldname = nodeRead(ctx, NULL, 0)
                                143                 :                : 
                                144                 :                : /* Read a bitmapset field */
                                145                 :                : #define READ_BITMAPSET_FIELD(fldname) \
                                146                 :                :     token = pg_strtok(ctx, &length);        /* skip :fldname */ \
                                147                 :                :     (void) token;               /* in case not used elsewhere */ \
                                148                 :                :     local_node->fldname = _readBitmapset(ctx)
                                149                 :                : 
                                150                 :                : /* Read an attribute number array */
                                151                 :                : #define READ_ATTRNUMBER_ARRAY(fldname, len) \
                                152                 :                :     token = pg_strtok(ctx, &length);        /* skip :fldname */ \
                                153                 :                :     local_node->fldname = readAttrNumberCols(ctx, len)
                                154                 :                : 
                                155                 :                : /* Read an oid array */
                                156                 :                : #define READ_OID_ARRAY(fldname, len) \
                                157                 :                :     token = pg_strtok(ctx, &length);        /* skip :fldname */ \
                                158                 :                :     local_node->fldname = readOidCols(ctx, len)
                                159                 :                : 
                                160                 :                : /* Read an int array */
                                161                 :                : #define READ_INT_ARRAY(fldname, len) \
                                162                 :                :     token = pg_strtok(ctx, &length);        /* skip :fldname */ \
                                163                 :                :     local_node->fldname = readIntCols(ctx, len)
                                164                 :                : 
                                165                 :                : /* Read a bool array */
                                166                 :                : #define READ_BOOL_ARRAY(fldname, len) \
                                167                 :                :     token = pg_strtok(ctx, &length);        /* skip :fldname */ \
                                168                 :                :     local_node->fldname = readBoolCols(ctx, 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 *
 1455 peter@eisentraut.org      186                 :CBC      601793 : nullable_string(const char *token, int length)
                                187                 :                : {
                                188                 :                :     /* outToken emits <> for NULL, and pg_strtok makes that an empty string */
                                189         [ +  + ]:         601793 :     if (length == 0)
                                190                 :         123501 :         return NULL;
                                191                 :                :     /* outToken emits "" for empty string */
                                192   [ +  +  -  +  :         478292 :     if (length == 2 && token[0] == '"' && token[1] == '"')
                                              -  - ]
 1455 peter@eisentraut.org      193                 :UBC           0 :         return pstrdup("");
                                194                 :                :     /* otherwise, we must remove protective backslashes added by outToken */
 1455 peter@eisentraut.org      195                 :CBC      478292 :     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 *
   27 michael@paquier.xyz       207                 :GNC     1697685 : _readBitmapset(ReadNodeContext *ctx)
                                208                 :                : {
 6310 bruce@momjian.us          209                 :CBC     1697685 :     Bitmapset  *result = NULL;
                                210                 :                : 
                                211                 :                :     READ_TEMP_LOCALS();
                                212                 :                : 
   27 michael@paquier.xyz       213                 :GNC     1697685 :     token = pg_strtok(ctx, &length);
 6450 tgl@sss.pgh.pa.us         214         [ -  + ]:CBC     1697685 :     if (token == NULL)
 6450 tgl@sss.pgh.pa.us         215         [ #  # ]:UBC           0 :         elog(ERROR, "incomplete Bitmapset structure");
 6450 tgl@sss.pgh.pa.us         216   [ +  -  -  + ]:CBC     1697685 :     if (length != 1 || token[0] != '(')
 6450 tgl@sss.pgh.pa.us         217         [ #  # ]:UBC           0 :         elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
                                218                 :                : 
   27 michael@paquier.xyz       219                 :GNC     1697685 :     token = pg_strtok(ctx, &length);
 6450 tgl@sss.pgh.pa.us         220         [ -  + ]:CBC     1697685 :     if (token == NULL)
 6450 tgl@sss.pgh.pa.us         221         [ #  # ]:UBC           0 :         elog(ERROR, "incomplete Bitmapset structure");
 6450 tgl@sss.pgh.pa.us         222   [ +  -  +  - ]:CBC     1697685 :     if (length != 1 || token[0] != 'b')
 6450 tgl@sss.pgh.pa.us         223         [ #  # ]:UBC           0 :         elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
                                224                 :                : 
                                225                 :                :     for (;;)
 6450 tgl@sss.pgh.pa.us         226                 :CBC      427334 :     {
                                227                 :                :         int         val;
                                228                 :                :         char       *endptr;
                                229                 :                : 
   27 michael@paquier.xyz       230                 :GNC     2125019 :         token = pg_strtok(ctx, &length);
 6450 tgl@sss.pgh.pa.us         231         [ -  + ]:CBC     2125019 :         if (token == NULL)
 6450 tgl@sss.pgh.pa.us         232         [ #  # ]:UBC           0 :             elog(ERROR, "unterminated Bitmapset structure");
 6450 tgl@sss.pgh.pa.us         233   [ +  +  +  + ]:CBC     2125019 :         if (length == 1 && token[0] == ')')
                                234                 :        1697685 :             break;
                                235                 :         427334 :         val = (int) strtol(token, &endptr, 10);
                                236         [ -  + ]:         427334 :         if (endptr != token + length)
 6450 tgl@sss.pgh.pa.us         237         [ #  # ]:UBC           0 :             elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
 6450 tgl@sss.pgh.pa.us         238                 :CBC      427334 :         result = bms_add_member(result, val);
                                239                 :                :     }
                                240                 :                : 
                                241                 :        1697685 :     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 *
   27 michael@paquier.xyz       249                 :UNC           0 : readBitmapset(ReadNodeContext *ctx)
                                250                 :                : {
                                251                 :              0 :     return _readBitmapset(ctx);
                                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 *
   27 michael@paquier.xyz       263                 :GNC      423098 : _readConst(ReadNodeContext *ctx)
                                264                 :                : {
 1534 peter@eisentraut.org      265                 :CBC      423098 :     READ_LOCALS(Const);
                                266                 :                : 
                                267                 :         423098 :     READ_OID_FIELD(consttype);
                                268                 :         423098 :     READ_INT_FIELD(consttypmod);
                                269                 :         423098 :     READ_OID_FIELD(constcollid);
                                270                 :         423098 :     READ_INT_FIELD(constlen);
                                271                 :         423098 :     READ_BOOL_FIELD(constbyval);
                                272                 :         423098 :     READ_BOOL_FIELD(constisnull);
 4145 andres@anarazel.de        273         [ -  + ]:         423098 :     READ_LOCATION_FIELD(location);
                                274                 :                : 
   27 michael@paquier.xyz       275                 :GNC      423098 :     token = pg_strtok(ctx, &length);    /* skip :constvalue */
 1534 peter@eisentraut.org      276         [ +  + ]:CBC      423098 :     if (local_node->constisnull)
   27 michael@paquier.xyz       277                 :GNC       45364 :         token = pg_strtok(ctx, &length);    /* skip "<>" */
                                278                 :                :     else
                                279                 :         377734 :         local_node->constvalue = readDatum(ctx, local_node->constbyval);
                                280                 :                : 
 2057 peter@eisentraut.org      281                 :CBC      423098 :     READ_DONE();
                                282                 :                : }
                                283                 :                : 
                                284                 :                : static BoolExpr *
   27 michael@paquier.xyz       285                 :GNC       28791 : _readBoolExpr(ReadNodeContext *ctx)
                                286                 :                : {
 1534 peter@eisentraut.org      287                 :CBC       28791 :     READ_LOCALS(BoolExpr);
                                288                 :                : 
                                289                 :                :     /* do-it-yourself enum representation */
   27 michael@paquier.xyz       290                 :GNC       28791 :     token = pg_strtok(ctx, &length);    /* skip :boolop */
                                291                 :          28791 :     token = pg_strtok(ctx, &length);    /* get field value */
 1457 peter@eisentraut.org      292   [ +  +  +  + ]:CBC       28791 :     if (length == 3 && strncmp(token, "and", 3) == 0)
 1534                           293                 :          20118 :         local_node->boolop = AND_EXPR;
 1457                           294   [ +  +  +  - ]:           8673 :     else if (length == 2 && strncmp(token, "or", 2) == 0)
 1534                           295                 :           6091 :         local_node->boolop = OR_EXPR;
 1457                           296   [ +  -  +  - ]:           2582 :     else if (length == 3 && strncmp(token, "not", 3) == 0)
 1534                           297                 :           2582 :         local_node->boolop = NOT_EXPR;
                                298                 :                :     else
 1534 peter@eisentraut.org      299         [ #  # ]:UBC           0 :         elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
                                300                 :                : 
 1534 peter@eisentraut.org      301                 :CBC       28791 :     READ_NODE_FIELD(args);
 6560 tgl@sss.pgh.pa.us         302         [ -  + ]:          28791 :     READ_LOCATION_FIELD(location);
                                303                 :                : 
 8700                           304                 :          28791 :     READ_DONE();
                                305                 :                : }
                                306                 :                : 
                                307                 :                : static A_Const *
   27 michael@paquier.xyz       308                 :UNC           0 : _readA_Const(ReadNodeContext *ctx)
                                309                 :                : {
 1457 peter@eisentraut.org      310                 :UBC           0 :     READ_LOCALS(A_Const);
                                311                 :                : 
                                312                 :                :     /* We expect either NULL or :val here */
   27 michael@paquier.xyz       313                 :UNC           0 :     token = pg_strtok(ctx, &length);
 1457 peter@eisentraut.org      314   [ #  #  #  # ]:UBC           0 :     if (length == 4 && strncmp(token, "NULL", 4) == 0)
                                315                 :              0 :         local_node->isnull = true;
                                316                 :                :     else
                                317                 :                :     {
   27 michael@paquier.xyz       318                 :UNC           0 :         union ValUnion *tmp = nodeRead(ctx, NULL, 0);
                                319                 :                : 
                                320                 :                :         /* To forestall valgrind complaints, copy only the valid data */
 1281 tgl@sss.pgh.pa.us         321   [ #  #  #  #  :UBC           0 :         switch (nodeTag(tmp))
                                              #  # ]
                                322                 :                :         {
                                323                 :              0 :             case T_Integer:
                                324                 :              0 :                 memcpy(&local_node->val, tmp, sizeof(Integer));
                                325                 :              0 :                 break;
                                326                 :              0 :             case T_Float:
                                327                 :              0 :                 memcpy(&local_node->val, tmp, sizeof(Float));
                                328                 :              0 :                 break;
                                329                 :              0 :             case T_Boolean:
                                330                 :              0 :                 memcpy(&local_node->val, tmp, sizeof(Boolean));
                                331                 :              0 :                 break;
                                332                 :              0 :             case T_String:
                                333                 :              0 :                 memcpy(&local_node->val, tmp, sizeof(String));
                                334                 :              0 :                 break;
                                335                 :              0 :             case T_BitString:
                                336                 :              0 :                 memcpy(&local_node->val, tmp, sizeof(BitString));
                                337                 :              0 :                 break;
                                338                 :              0 :             default:
                                339         [ #  # ]:              0 :                 elog(ERROR, "unrecognized node type: %d",
                                340                 :                :                      (int) nodeTag(tmp));
                                341                 :                :                 break;
                                342                 :                :         }
                                343                 :                :     }
                                344                 :                : 
 1457 peter@eisentraut.org      345         [ #  # ]:              0 :     READ_LOCATION_FIELD(location);
                                346                 :                : 
                                347                 :              0 :     READ_DONE();
                                348                 :                : }
                                349                 :                : 
                                350                 :                : static RangeTblEntry *
   27 michael@paquier.xyz       351                 :GNC      119115 : _readRangeTblEntry(ReadNodeContext *ctx)
                                352                 :                : {
 1534 peter@eisentraut.org      353                 :CBC      119115 :     READ_LOCALS(RangeTblEntry);
                                354                 :                : 
                                355                 :         119115 :     READ_NODE_FIELD(alias);
                                356                 :         119115 :     READ_NODE_FIELD(eref);
                                357                 :         119115 :     READ_ENUM_FIELD(rtekind, RTEKind);
                                358                 :                : 
                                359   [ +  +  +  +  :         119115 :     switch (local_node->rtekind)
                                     +  +  +  -  +  
                                              +  - ]
                                360                 :                :     {
                                361                 :          72265 :         case RTE_RELATION:
                                362                 :          72265 :             READ_OID_FIELD(relid);
  927                           363                 :          72265 :             READ_BOOL_FIELD(inh);
 1534                           364   [ +  -  -  + ]:          72265 :             READ_CHAR_FIELD(relkind);
                                365                 :          72265 :             READ_INT_FIELD(rellockmode);
 1384 alvherre@alvh.no-ip.      366                 :          72265 :             READ_UINT_FIELD(perminfoindex);
  929 peter@eisentraut.org      367                 :          72265 :             READ_NODE_FIELD(tablesample);
 1534                           368                 :          72265 :             break;
                                369                 :          13549 :         case RTE_SUBQUERY:
                                370                 :          13549 :             READ_NODE_FIELD(subquery);
                                371                 :          13549 :             READ_BOOL_FIELD(security_barrier);
                                372                 :                :             /* we re-use these RELATION fields, too: */
 1341 tgl@sss.pgh.pa.us         373                 :          13549 :             READ_OID_FIELD(relid);
  927 peter@eisentraut.org      374                 :          13549 :             READ_BOOL_FIELD(inh);
 1195 amitlan@postgresql.o      375   [ +  +  -  + ]:          13549 :             READ_CHAR_FIELD(relkind);
 1341 tgl@sss.pgh.pa.us         376                 :          13549 :             READ_INT_FIELD(rellockmode);
                                377                 :          13549 :             READ_UINT_FIELD(perminfoindex);
 1534 peter@eisentraut.org      378                 :          13549 :             break;
                                379                 :          22162 :         case RTE_JOIN:
                                380                 :          22162 :             READ_ENUM_FIELD(jointype, JoinType);
                                381                 :          22162 :             READ_INT_FIELD(joinmergedcols);
                                382                 :          22162 :             READ_NODE_FIELD(joinaliasvars);
                                383                 :          22162 :             READ_NODE_FIELD(joinleftcols);
                                384                 :          22162 :             READ_NODE_FIELD(joinrightcols);
                                385                 :          22162 :             READ_NODE_FIELD(join_using_alias);
                                386                 :          22162 :             break;
                                387                 :           8325 :         case RTE_FUNCTION:
                                388                 :           8325 :             READ_NODE_FIELD(functions);
                                389                 :           8325 :             READ_BOOL_FIELD(funcordinality);
                                390                 :           8325 :             break;
                                391                 :            210 :         case RTE_TABLEFUNC:
                                392                 :            210 :             READ_NODE_FIELD(tablefunc);
                                393                 :                :             /* The RTE must have a copy of the column type info, if any */
                                394         [ +  - ]:            210 :             if (local_node->tablefunc)
                                395                 :                :             {
                                396                 :            210 :                 TableFunc  *tf = local_node->tablefunc;
                                397                 :                : 
                                398                 :            210 :                 local_node->coltypes = tf->coltypes;
                                399                 :            210 :                 local_node->coltypmods = tf->coltypmods;
                                400                 :            210 :                 local_node->colcollations = tf->colcollations;
                                401                 :                :             }
                                402                 :            210 :             break;
                                403                 :            975 :         case RTE_VALUES:
                                404                 :            975 :             READ_NODE_FIELD(values_lists);
                                405                 :            975 :             READ_NODE_FIELD(coltypes);
                                406                 :            975 :             READ_NODE_FIELD(coltypmods);
                                407                 :            975 :             READ_NODE_FIELD(colcollations);
                                408                 :            975 :             break;
                                409                 :            435 :         case RTE_CTE:
                                410                 :            435 :             READ_STRING_FIELD(ctename);
                                411                 :            435 :             READ_UINT_FIELD(ctelevelsup);
                                412                 :            435 :             READ_BOOL_FIELD(self_reference);
                                413                 :            435 :             READ_NODE_FIELD(coltypes);
                                414                 :            435 :             READ_NODE_FIELD(coltypmods);
                                415                 :            435 :             READ_NODE_FIELD(colcollations);
                                416                 :            435 :             break;
 1534 peter@eisentraut.org      417                 :UBC           0 :         case RTE_NAMEDTUPLESTORE:
                                418                 :              0 :             READ_STRING_FIELD(enrname);
                                419                 :              0 :             READ_FLOAT_FIELD(enrtuples);
                                420                 :              0 :             READ_NODE_FIELD(coltypes);
                                421                 :              0 :             READ_NODE_FIELD(coltypmods);
                                422                 :              0 :             READ_NODE_FIELD(colcollations);
                                423                 :                :             /* we re-use these RELATION fields, too: */
 1341 tgl@sss.pgh.pa.us         424                 :              0 :             READ_OID_FIELD(relid);
 1534 peter@eisentraut.org      425                 :              0 :             break;
 1534 peter@eisentraut.org      426                 :CBC          76 :         case RTE_RESULT:
                                427                 :                :             /* no extra fields */
                                428                 :             76 :             break;
  740 rguo@postgresql.org       429                 :           1118 :         case RTE_GROUP:
                                430                 :           1118 :             READ_NODE_FIELD(groupexprs);
                                431                 :           1118 :             break;
 1534 peter@eisentraut.org      432                 :UBC           0 :         default:
                                433         [ #  # ]:              0 :             elog(ERROR, "unrecognized RTE kind: %d",
                                434                 :                :                  (int) local_node->rtekind);
                                435                 :                :             break;
                                436                 :                :     }
                                437                 :                : 
 1534 peter@eisentraut.org      438                 :CBC      119115 :     READ_BOOL_FIELD(lateral);
                                439                 :         119115 :     READ_BOOL_FIELD(inFromCl);
                                440                 :         119115 :     READ_NODE_FIELD(securityQuals);
                                441                 :                : 
 8700 tgl@sss.pgh.pa.us         442                 :         119115 :     READ_DONE();
                                443                 :                : }
                                444                 :                : 
                                445                 :                : static A_Expr *
   27 michael@paquier.xyz       446                 :UNC           0 : _readA_Expr(ReadNodeContext *ctx)
                                447                 :                : {
 1457 peter@eisentraut.org      448                 :UBC           0 :     READ_LOCALS(A_Expr);
                                449                 :                : 
   27 michael@paquier.xyz       450                 :UNC           0 :     token = pg_strtok(ctx, &length);
                                451                 :                : 
 1457 peter@eisentraut.org      452   [ #  #  #  # ]:UBC           0 :     if (length == 3 && strncmp(token, "ANY", 3) == 0)
                                453                 :                :     {
                                454                 :              0 :         local_node->kind = AEXPR_OP_ANY;
                                455                 :              0 :         READ_NODE_FIELD(name);
                                456                 :                :     }
                                457   [ #  #  #  # ]:              0 :     else if (length == 3 && strncmp(token, "ALL", 3) == 0)
                                458                 :                :     {
                                459                 :              0 :         local_node->kind = AEXPR_OP_ALL;
                                460                 :              0 :         READ_NODE_FIELD(name);
                                461                 :                :     }
                                462   [ #  #  #  # ]:              0 :     else if (length == 8 && strncmp(token, "DISTINCT", 8) == 0)
                                463                 :                :     {
                                464                 :              0 :         local_node->kind = AEXPR_DISTINCT;
                                465                 :              0 :         READ_NODE_FIELD(name);
                                466                 :                :     }
                                467   [ #  #  #  # ]:              0 :     else if (length == 12 && strncmp(token, "NOT_DISTINCT", 12) == 0)
                                468                 :                :     {
                                469                 :              0 :         local_node->kind = AEXPR_NOT_DISTINCT;
                                470                 :              0 :         READ_NODE_FIELD(name);
                                471                 :                :     }
                                472   [ #  #  #  # ]:              0 :     else if (length == 6 && strncmp(token, "NULLIF", 6) == 0)
                                473                 :                :     {
                                474                 :              0 :         local_node->kind = AEXPR_NULLIF;
                                475                 :              0 :         READ_NODE_FIELD(name);
                                476                 :                :     }
                                477   [ #  #  #  # ]:              0 :     else if (length == 2 && strncmp(token, "IN", 2) == 0)
                                478                 :                :     {
                                479                 :              0 :         local_node->kind = AEXPR_IN;
                                480                 :              0 :         READ_NODE_FIELD(name);
                                481                 :                :     }
                                482   [ #  #  #  # ]:              0 :     else if (length == 4 && strncmp(token, "LIKE", 4) == 0)
                                483                 :                :     {
                                484                 :              0 :         local_node->kind = AEXPR_LIKE;
                                485                 :              0 :         READ_NODE_FIELD(name);
                                486                 :                :     }
                                487   [ #  #  #  # ]:              0 :     else if (length == 5 && strncmp(token, "ILIKE", 5) == 0)
                                488                 :                :     {
                                489                 :              0 :         local_node->kind = AEXPR_ILIKE;
                                490                 :              0 :         READ_NODE_FIELD(name);
                                491                 :                :     }
                                492   [ #  #  #  # ]:              0 :     else if (length == 7 && strncmp(token, "SIMILAR", 7) == 0)
                                493                 :                :     {
                                494                 :              0 :         local_node->kind = AEXPR_SIMILAR;
                                495                 :              0 :         READ_NODE_FIELD(name);
                                496                 :                :     }
                                497   [ #  #  #  # ]:              0 :     else if (length == 7 && strncmp(token, "BETWEEN", 7) == 0)
                                498                 :                :     {
                                499                 :              0 :         local_node->kind = AEXPR_BETWEEN;
                                500                 :              0 :         READ_NODE_FIELD(name);
                                501                 :                :     }
                                502   [ #  #  #  # ]:              0 :     else if (length == 11 && strncmp(token, "NOT_BETWEEN", 11) == 0)
                                503                 :                :     {
                                504                 :              0 :         local_node->kind = AEXPR_NOT_BETWEEN;
                                505                 :              0 :         READ_NODE_FIELD(name);
                                506                 :                :     }
                                507   [ #  #  #  # ]:              0 :     else if (length == 11 && strncmp(token, "BETWEEN_SYM", 11) == 0)
                                508                 :                :     {
                                509                 :              0 :         local_node->kind = AEXPR_BETWEEN_SYM;
                                510                 :              0 :         READ_NODE_FIELD(name);
                                511                 :                :     }
                                512   [ #  #  #  # ]:              0 :     else if (length == 15 && strncmp(token, "NOT_BETWEEN_SYM", 15) == 0)
                                513                 :                :     {
                                514                 :              0 :         local_node->kind = AEXPR_NOT_BETWEEN_SYM;
                                515                 :              0 :         READ_NODE_FIELD(name);
                                516                 :                :     }
                                517   [ #  #  #  # ]:              0 :     else if (length == 5 && strncmp(token, ":name", 5) == 0)
                                518                 :                :     {
                                519                 :              0 :         local_node->kind = AEXPR_OP;
   27 michael@paquier.xyz       520                 :UNC           0 :         local_node->name = nodeRead(ctx, NULL, 0);
                                521                 :                :     }
                                522                 :                :     else
 1457 peter@eisentraut.org      523         [ #  # ]:UBC           0 :         elog(ERROR, "unrecognized A_Expr kind: \"%.*s\"", length, token);
                                524                 :                : 
                                525                 :              0 :     READ_NODE_FIELD(lexpr);
                                526                 :              0 :     READ_NODE_FIELD(rexpr);
  465 alvherre@kurilemu.de      527         [ #  # ]:              0 :     READ_LOCATION_FIELD(rexpr_list_start);
                                528         [ #  # ]:              0 :     READ_LOCATION_FIELD(rexpr_list_end);
 1457 peter@eisentraut.org      529         [ #  # ]:              0 :     READ_LOCATION_FIELD(location);
                                530                 :                : 
                                531                 :              0 :     READ_DONE();
                                532                 :                : }
                                533                 :                : 
                                534                 :                : static ExtensibleNode *
   27 michael@paquier.xyz       535                 :GNC          12 : _readExtensibleNode(ReadNodeContext *ctx)
                                536                 :                : {
                                537                 :                :     const ExtensibleNodeMethods *methods;
                                538                 :                :     ExtensibleNode *local_node;
                                539                 :                :     const char *extnodename;
                                540                 :                : 
                                541                 :                :     READ_TEMP_LOCALS();
                                542                 :                : 
                                543                 :             12 :     token = pg_strtok(ctx, &length);    /* skip :extnodename */
                                544                 :             12 :     token = pg_strtok(ctx, &length);    /* get extnodename */
                                545                 :                : 
 1534 peter@eisentraut.org      546                 :GBC          12 :     extnodename = nullable_string(token, length);
                                547         [ -  + ]:             12 :     if (!extnodename)
 1534 peter@eisentraut.org      548         [ #  # ]:UBC           0 :         elog(ERROR, "extnodename has to be supplied");
 1534 peter@eisentraut.org      549                 :GBC          12 :     methods = GetExtensibleNodeMethods(extnodename, false);
                                550                 :                : 
                                551                 :             12 :     local_node = (ExtensibleNode *) newNode(methods->node_size,
                                552                 :                :                                             T_ExtensibleNode);
                                553                 :             12 :     local_node->extnodename = extnodename;
                                554                 :                : 
                                555                 :                :     /* deserialize the private fields */
   27 michael@paquier.xyz       556                 :GNC          12 :     methods->nodeRead(ctx, local_node);
                                557                 :                : 
 8700 tgl@sss.pgh.pa.us         558                 :GBC          11 :     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                 :                : Node *
   27 michael@paquier.xyz       569                 :GNC     3535826 : parseNodeString(ReadNodeContext *ctx)
                                570                 :                : {
                                571                 :                :     READ_TEMP_LOCALS();
                                572                 :                : 
                                573                 :                :     /* Guard against stack overflow due to overly complex expressions */
 2841 tgl@sss.pgh.pa.us         574                 :CBC     3535826 :     check_stack_depth();
                                575                 :                : 
   27 michael@paquier.xyz       576                 :GNC     3535826 :     token = pg_strtok(ctx, &length);
                                577                 :                : 
                                578                 :                : #define MATCH(tokname, namelen) \
                                579                 :                :     (length == namelen && memcmp(token, tokname, namelen) == 0)
                                580                 :                : 
                                581                 :                : #include "readfuncs.switch.c"
                                582                 :                : 
 1194 noah@leadboat.com         583         [ #  # ]:UBC           0 :     elog(ERROR, "badly formatted node string \"%.32s\"...", token);
                                584                 :                :     return NULL;                /* keep compiler quiet */
                                585                 :                : }
                                586                 :                : 
                                587                 :                : 
                                588                 :                : /*
                                589                 :                :  * readDatum
                                590                 :                :  *
                                591                 :                :  * Given a string representation of a constant, recreate the appropriate
                                592                 :                :  * Datum.  The string representation embeds length info, but not byValue,
                                593                 :                :  * so we must be told that.
                                594                 :                :  */
                                595                 :                : Datum
   27 michael@paquier.xyz       596                 :GNC      377734 : readDatum(ReadNodeContext *ctx, bool typbyval)
                                597                 :                : {
                                598                 :                :     Size        length;
                                599                 :                :     int         tokenLength;
                                600                 :                :     const char *token;
                                601                 :                :     Datum       res;
                                602                 :                :     char       *s;
                                603                 :                : 
                                604                 :                :     /*
                                605                 :                :      * read the actual length of the value
                                606                 :                :      */
                                607                 :         377734 :     token = pg_strtok(ctx, &tokenLength);
 9386 tgl@sss.pgh.pa.us         608                 :CBC      377734 :     length = atoui(token);
                                609                 :                : 
   27 michael@paquier.xyz       610                 :GNC      377734 :     token = pg_strtok(ctx, &tokenLength);   /* read the '[' */
 9210 tgl@sss.pgh.pa.us         611   [ +  -  -  + ]:CBC      377734 :     if (token == NULL || token[0] != '[')
 4623 tgl@sss.pgh.pa.us         612   [ #  #  #  # ]:UBC           0 :         elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
                                613                 :                :              token ? token : "[NULL]", length);
                                614                 :                : 
 9387 tgl@sss.pgh.pa.us         615         [ +  + ]:CBC      377734 :     if (typbyval)
                                616                 :                :     {
 9386                           617         [ -  + ]:         293819 :         if (length > (Size) sizeof(Datum))
 4623 tgl@sss.pgh.pa.us         618         [ #  # ]:UBC           0 :             elog(ERROR, "byval datum but length = %zu", length);
 9746 tgl@sss.pgh.pa.us         619                 :CBC      293819 :         res = (Datum) 0;
10605 bruce@momjian.us          620                 :         293819 :         s = (char *) (&res);
  299 peter@eisentraut.org      621         [ +  + ]:        2644371 :         for (Size i = 0; i < (Size) sizeof(Datum); i++)
                                622                 :                :         {
   27 michael@paquier.xyz       623                 :GNC     2350552 :             token = pg_strtok(ctx, &tokenLength);
10605 bruce@momjian.us          624                 :CBC     2350552 :             s[i] = (char) atoi(token);
                                625                 :                :         }
                                626                 :                :     }
                                627         [ -  + ]:          83915 :     else if (length <= 0)
  408 tgl@sss.pgh.pa.us         628                 :UBC           0 :         res = (Datum) 0;
                                629                 :                :     else
                                630                 :                :     {
10605 bruce@momjian.us          631                 :CBC       83915 :         s = (char *) palloc(length);
  299 peter@eisentraut.org      632         [ +  + ]:        2744033 :         for (Size i = 0; i < length; i++)
                                633                 :                :         {
   27 michael@paquier.xyz       634                 :GNC     2660118 :             token = pg_strtok(ctx, &tokenLength);
10605 bruce@momjian.us          635                 :CBC     2660118 :             s[i] = (char) atoi(token);
                                636                 :                :         }
                                637                 :          83915 :         res = PointerGetDatum(s);
                                638                 :                :     }
                                639                 :                : 
   27 michael@paquier.xyz       640                 :GNC      377734 :     token = pg_strtok(ctx, &tokenLength);   /* read the ']' */
 9387 tgl@sss.pgh.pa.us         641   [ +  -  -  + ]:CBC      377734 :     if (token == NULL || token[0] != ']')
 4623 tgl@sss.pgh.pa.us         642   [ #  #  #  # ]:UBC           0 :         elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
                                643                 :                :              token ? token : "[NULL]", length);
                                644                 :                : 
10246 bruce@momjian.us          645                 :CBC      377734 :     return res;
                                646                 :                : }
                                647                 :                : 
                                648                 :                : /*
                                649                 :                :  * common implementation for scalar-array-reading functions
                                650                 :                :  *
                                651                 :                :  * The data format is either "<>" for a NULL pointer (in which case numCols
                                652                 :                :  * is ignored) or "(item item item)" where the number of items must equal
                                653                 :                :  * numCols.  The convfunc must be okay with stopping at whitespace or a
                                654                 :                :  * right parenthesis, since pg_strtok won't null-terminate the token.
                                655                 :                :  */
                                656                 :                : #define READ_SCALAR_ARRAY(fnname, datatype, convfunc) \
                                657                 :                : datatype * \
                                658                 :                : fnname(ReadNodeContext *ctx, int numCols) \
                                659                 :                : { \
                                660                 :                :     datatype   *vals; \
                                661                 :                :     READ_TEMP_LOCALS(); \
                                662                 :                :     token = pg_strtok(ctx, &length); \
                                663                 :                :     if (token == NULL) \
                                664                 :                :         elog(ERROR, "incomplete scalar array"); \
                                665                 :                :     if (length == 0) \
                                666                 :                :         return NULL;            /* it was "<>", so return NULL pointer */ \
                                667                 :                :     if (length != 1 || token[0] != '(') \
                                668                 :                :         elog(ERROR, "unrecognized token: \"%.*s\"", length, token); \
                                669                 :                :     vals = palloc_array(datatype, numCols); \
                                670                 :                :     for (int i = 0; i < numCols; i++) \
                                671                 :                :     { \
                                672                 :                :         token = pg_strtok(ctx, &length); \
                                673                 :                :         if (token == NULL || token[0] == ')') \
                                674                 :                :             elog(ERROR, "incomplete scalar array"); \
                                675                 :                :         vals[i] = convfunc(token); \
                                676                 :                :     } \
                                677                 :                :     token = pg_strtok(ctx, &length); \
                                678                 :                :     if (token == NULL || length != 1 || token[0] != ')') \
                                679                 :                :         elog(ERROR, "incomplete scalar array"); \
                                680                 :                :     return vals; \
                                681                 :                : }
                                682                 :                : 
                                683                 :                : /*
                                684                 :                :  * Note: these functions are exported in nodes.h for possible use by
                                685                 :                :  * extensions, so don't mess too much with their names or API.
                                686                 :                :  */
 1523 tgl@sss.pgh.pa.us         687   [ -  +  -  -  :           2351 : READ_SCALAR_ARRAY(readAttrNumberCols, int16, atoi)
                                     +  +  +  -  -  
                                     +  -  -  +  -  
                                     -  +  -  -  +  
                                     +  +  -  +  -  
                                        -  +  -  - ]
                                688   [ -  +  -  -  :           5830 : READ_SCALAR_ARRAY(readOidCols, Oid, atooid)
                                     +  +  +  -  -  
                                     +  -  -  +  -  
                                     -  +  -  -  +  
                                     +  +  -  +  -  
                                        -  +  -  - ]
                                689                 :                : /* outfuncs.c has writeIndexCols, but we don't yet need that here */
                                690                 :                : /* READ_SCALAR_ARRAY(readIndexCols, Index, atoui) */
                                691   [ -  +  -  -  :           3096 : READ_SCALAR_ARRAY(readIntCols, int, atoi)
                                     -  +  +  -  -  
                                     +  -  -  +  -  
                                     -  +  -  -  +  
                                     +  +  -  +  -  
                                        -  +  -  - ]
                                692   [ -  +  -  -  :            740 : READ_SCALAR_ARRAY(readBoolCols, bool, strtobool)
                                     -  +  +  -  -  
                                     +  -  -  +  -  
                                     -  +  -  -  +  
                                     +  +  -  +  -  
                                        -  +  -  - ]
        

Generated by: LCOV version 2.0-1