LCOV - code coverage report
Current view: top level - src/backend/nodes - nodeFuncs.c (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 78.7 % 2686 2115
Test Date: 2026-10-05 05:15:52 Functions: 100.0 % 32 32
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 70.4 % 1520 1070

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * nodeFuncs.c
       4                 :             :  *      Various general-purpose manipulations of Node trees
       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/nodeFuncs.c
      12                 :             :  *
      13                 :             :  *-------------------------------------------------------------------------
      14                 :             :  */
      15                 :             : #include "postgres.h"
      16                 :             : 
      17                 :             : #include "catalog/pg_collation.h"
      18                 :             : #include "catalog/pg_type.h"
      19                 :             : #include "miscadmin.h"
      20                 :             : #include "nodes/execnodes.h"
      21                 :             : #include "nodes/nodeFuncs.h"
      22                 :             : #include "nodes/pathnodes.h"
      23                 :             : #include "utils/builtins.h"
      24                 :             : #include "utils/lsyscache.h"
      25                 :             : 
      26                 :             : static bool expression_returns_set_walker(Node *node, void *context);
      27                 :             : static int  leftmostLoc(int loc1, int loc2);
      28                 :             : static bool fix_opfuncids_walker(Node *node, void *context);
      29                 :             : static bool planstate_walk_subplans(List *plans,
      30                 :             :                                     planstate_tree_walker_callback walker,
      31                 :             :                                     void *context);
      32                 :             : static bool planstate_walk_members(PlanState **planstates, int nplans,
      33                 :             :                                    planstate_tree_walker_callback walker,
      34                 :             :                                    void *context);
      35                 :             : 
      36                 :             : 
      37                 :             : /*
      38                 :             :  *  exprType -
      39                 :             :  *    returns the Oid of the type of the expression's result.
      40                 :             :  */
      41                 :             : Oid
      42                 :    22107284 : exprType(const Node *expr)
      43                 :             : {
      44                 :             :     Oid         type;
      45                 :             : 
      46         [ +  + ]:    22107284 :     if (!expr)
      47                 :         312 :         return InvalidOid;
      48                 :             : 
      49   [ +  +  +  +  :    22106972 :     switch (nodeTag(expr))
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  -  +  +  
                      - ]
      50                 :             :     {
      51                 :    12382569 :         case T_Var:
      52                 :    12382569 :             type = ((const Var *) expr)->vartype;
      53                 :    12382569 :             break;
      54                 :     3199881 :         case T_Const:
      55                 :     3199881 :             type = ((const Const *) expr)->consttype;
      56                 :     3199881 :             break;
      57                 :     1984813 :         case T_Param:
      58                 :     1984813 :             type = ((const Param *) expr)->paramtype;
      59                 :     1984813 :             break;
      60                 :      223326 :         case T_Aggref:
      61                 :      223326 :             type = ((const Aggref *) expr)->aggtype;
      62                 :      223326 :             break;
      63                 :        1759 :         case T_GroupingFunc:
      64                 :        1759 :             type = INT4OID;
      65                 :        1759 :             break;
      66                 :       16071 :         case T_WindowFunc:
      67                 :       16071 :             type = ((const WindowFunc *) expr)->wintype;
      68                 :       16071 :             break;
      69                 :         748 :         case T_MergeSupportFunc:
      70                 :         748 :             type = ((const MergeSupportFunc *) expr)->msftype;
      71                 :         748 :             break;
      72                 :      101315 :         case T_SubscriptingRef:
      73                 :      101315 :             type = ((const SubscriptingRef *) expr)->refrestype;
      74                 :      101315 :             break;
      75                 :     1363765 :         case T_FuncExpr:
      76                 :     1363765 :             type = ((const FuncExpr *) expr)->funcresulttype;
      77                 :     1363765 :             break;
      78                 :       51169 :         case T_NamedArgExpr:
      79                 :       51169 :             type = exprType((Node *) ((const NamedArgExpr *) expr)->arg);
      80                 :       51169 :             break;
      81                 :      996397 :         case T_OpExpr:
      82                 :      996397 :             type = ((const OpExpr *) expr)->opresulttype;
      83                 :      996397 :             break;
      84                 :        1463 :         case T_DistinctExpr:
      85                 :        1463 :             type = ((const DistinctExpr *) expr)->opresulttype;
      86                 :        1463 :             break;
      87                 :        1812 :         case T_NullIfExpr:
      88                 :        1812 :             type = ((const NullIfExpr *) expr)->opresulttype;
      89                 :        1812 :             break;
      90                 :       74983 :         case T_ScalarArrayOpExpr:
      91                 :       74983 :             type = BOOLOID;
      92                 :       74983 :             break;
      93                 :      238893 :         case T_BoolExpr:
      94                 :      238893 :             type = BOOLOID;
      95                 :      238893 :             break;
      96                 :       78232 :         case T_SubLink:
      97                 :             :             {
      98                 :       78232 :                 const SubLink *sublink = (const SubLink *) expr;
      99                 :             : 
     100         [ +  + ]:       78232 :                 if (sublink->subLinkType == EXPR_SUBLINK ||
     101         [ +  + ]:       35899 :                     sublink->subLinkType == ARRAY_SUBLINK)
     102                 :       53554 :                 {
     103                 :             :                     /* get the type of the subselect's first target column */
     104                 :       53554 :                     Query      *qtree = (Query *) sublink->subselect;
     105                 :             :                     TargetEntry *tent;
     106                 :             : 
     107   [ +  -  -  + ]:       53554 :                     if (!qtree || !IsA(qtree, Query))
     108         [ #  # ]:           0 :                         elog(ERROR, "cannot get type for untransformed sublink");
     109                 :       53554 :                     tent = linitial_node(TargetEntry, qtree->targetList);
     110                 :             :                     Assert(!tent->resjunk);
     111                 :       53554 :                     type = exprType((Node *) tent->expr);
     112         [ +  + ]:       53554 :                     if (sublink->subLinkType == ARRAY_SUBLINK)
     113                 :             :                     {
     114                 :       11221 :                         type = get_promoted_array_type(type);
     115         [ -  + ]:       11221 :                         if (!OidIsValid(type))
     116         [ #  # ]:           0 :                             ereport(ERROR,
     117                 :             :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
     118                 :             :                                      errmsg("could not find array type for data type %s",
     119                 :             :                                             format_type_be(exprType((Node *) tent->expr)))));
     120                 :             :                     }
     121                 :             :                 }
     122         [ +  + ]:       24678 :                 else if (sublink->subLinkType == MULTIEXPR_SUBLINK)
     123                 :             :                 {
     124                 :             :                     /* MULTIEXPR is always considered to return RECORD */
     125                 :          91 :                     type = RECORDOID;
     126                 :             :                 }
     127                 :             :                 else
     128                 :             :                 {
     129                 :             :                     /* for all other sublink types, result is boolean */
     130                 :       24587 :                     type = BOOLOID;
     131                 :             :                 }
     132                 :             :             }
     133                 :       78232 :             break;
     134                 :       36655 :         case T_SubPlan:
     135                 :             :             {
     136                 :       36655 :                 const SubPlan *subplan = (const SubPlan *) expr;
     137                 :             : 
     138         [ +  + ]:       36655 :                 if (subplan->subLinkType == EXPR_SUBLINK ||
     139         [ +  + ]:        3007 :                     subplan->subLinkType == ARRAY_SUBLINK)
     140                 :             :                 {
     141                 :             :                     /* get the type of the subselect's first target column */
     142                 :       33896 :                     type = subplan->firstColType;
     143         [ +  + ]:       33896 :                     if (subplan->subLinkType == ARRAY_SUBLINK)
     144                 :             :                     {
     145                 :         248 :                         type = get_promoted_array_type(type);
     146         [ -  + ]:         248 :                         if (!OidIsValid(type))
     147         [ #  # ]:           0 :                             ereport(ERROR,
     148                 :             :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
     149                 :             :                                      errmsg("could not find array type for data type %s",
     150                 :             :                                             format_type_be(subplan->firstColType))));
     151                 :             :                     }
     152                 :             :                 }
     153         [ +  + ]:        2759 :                 else if (subplan->subLinkType == MULTIEXPR_SUBLINK)
     154                 :             :                 {
     155                 :             :                     /* MULTIEXPR is always considered to return RECORD */
     156                 :         126 :                     type = RECORDOID;
     157                 :             :                 }
     158                 :             :                 else
     159                 :             :                 {
     160                 :             :                     /* for all other subplan types, result is boolean */
     161                 :        2633 :                     type = BOOLOID;
     162                 :             :                 }
     163                 :             :             }
     164                 :       36655 :             break;
     165                 :         970 :         case T_AlternativeSubPlan:
     166                 :             :             {
     167                 :         970 :                 const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
     168                 :             : 
     169                 :             :                 /* subplans should all return the same thing */
     170                 :         970 :                 type = exprType((Node *) linitial(asplan->subplans));
     171                 :             :             }
     172                 :         970 :             break;
     173                 :       33256 :         case T_FieldSelect:
     174                 :       33256 :             type = ((const FieldSelect *) expr)->resulttype;
     175                 :       33256 :             break;
     176                 :         760 :         case T_FieldStore:
     177                 :         760 :             type = ((const FieldStore *) expr)->resulttype;
     178                 :         760 :             break;
     179                 :      441435 :         case T_RelabelType:
     180                 :      441435 :             type = ((const RelabelType *) expr)->resulttype;
     181                 :      441435 :             break;
     182                 :      102486 :         case T_CoerceViaIO:
     183                 :      102486 :             type = ((const CoerceViaIO *) expr)->resulttype;
     184                 :      102486 :             break;
     185                 :       11117 :         case T_ArrayCoerceExpr:
     186                 :       11117 :             type = ((const ArrayCoerceExpr *) expr)->resulttype;
     187                 :       11117 :             break;
     188                 :        1703 :         case T_ConvertRowtypeExpr:
     189                 :        1703 :             type = ((const ConvertRowtypeExpr *) expr)->resulttype;
     190                 :        1703 :             break;
     191                 :        7462 :         case T_CollateExpr:
     192                 :        7462 :             type = exprType((Node *) ((const CollateExpr *) expr)->arg);
     193                 :        7462 :             break;
     194                 :      270557 :         case T_CaseExpr:
     195                 :      270557 :             type = ((const CaseExpr *) expr)->casetype;
     196                 :      270557 :             break;
     197                 :       29666 :         case T_CaseTestExpr:
     198                 :       29666 :             type = ((const CaseTestExpr *) expr)->typeId;
     199                 :       29666 :             break;
     200                 :       68179 :         case T_ArrayExpr:
     201                 :       68179 :             type = ((const ArrayExpr *) expr)->array_typeid;
     202                 :       68179 :             break;
     203                 :       12231 :         case T_RowExpr:
     204                 :       12231 :             type = ((const RowExpr *) expr)->row_typeid;
     205                 :       12231 :             break;
     206                 :         346 :         case T_RowCompareExpr:
     207                 :         346 :             type = BOOLOID;
     208                 :         346 :             break;
     209                 :       20133 :         case T_CoalesceExpr:
     210                 :       20133 :             type = ((const CoalesceExpr *) expr)->coalescetype;
     211                 :       20133 :             break;
     212                 :        3670 :         case T_MinMaxExpr:
     213                 :        3670 :             type = ((const MinMaxExpr *) expr)->minmaxtype;
     214                 :        3670 :             break;
     215                 :        7825 :         case T_SQLValueFunction:
     216                 :        7825 :             type = ((const SQLValueFunction *) expr)->type;
     217                 :        7825 :             break;
     218                 :       16907 :         case T_XmlExpr:
     219         [ +  + ]:       16907 :             if (((const XmlExpr *) expr)->op == IS_DOCUMENT)
     220                 :          77 :                 type = BOOLOID;
     221         [ +  + ]:       16830 :             else if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
     222                 :         450 :                 type = TEXTOID;
     223                 :             :             else
     224                 :       16380 :                 type = XMLOID;
     225                 :       16907 :             break;
     226                 :         809 :         case T_JsonValueExpr:
     227                 :             :             {
     228                 :         809 :                 const JsonValueExpr *jve = (const JsonValueExpr *) expr;
     229                 :             : 
     230                 :         809 :                 type = exprType((Node *) jve->formatted_expr);
     231                 :             :             }
     232                 :         809 :             break;
     233                 :        5966 :         case T_JsonConstructorExpr:
     234                 :        5966 :             type = ((const JsonConstructorExpr *) expr)->returning->typid;
     235                 :        5966 :             break;
     236                 :        1283 :         case T_JsonIsPredicate:
     237                 :        1283 :             type = BOOLOID;
     238                 :        1283 :             break;
     239                 :        7882 :         case T_JsonExpr:
     240                 :             :             {
     241                 :        7882 :                 const JsonExpr *jexpr = (const JsonExpr *) expr;
     242                 :             : 
     243                 :        7882 :                 type = jexpr->returning->typid;
     244                 :        7882 :                 break;
     245                 :             :             }
     246                 :        3840 :         case T_JsonBehavior:
     247                 :             :             {
     248                 :        3840 :                 const JsonBehavior *behavior = (const JsonBehavior *) expr;
     249                 :             : 
     250                 :        3840 :                 type = exprType(behavior->expr);
     251                 :        3840 :                 break;
     252                 :             :             }
     253                 :       30376 :         case T_NullTest:
     254                 :       30376 :             type = BOOLOID;
     255                 :       30376 :             break;
     256                 :        2092 :         case T_BooleanTest:
     257                 :        2092 :             type = BOOLOID;
     258                 :        2092 :             break;
     259                 :      175255 :         case T_CoerceToDomain:
     260                 :      175255 :             type = ((const CoerceToDomain *) expr)->resulttype;
     261                 :      175255 :             break;
     262                 :        1546 :         case T_CoerceToDomainValue:
     263                 :        1546 :             type = ((const CoerceToDomainValue *) expr)->typeId;
     264                 :        1546 :             break;
     265                 :       73629 :         case T_SetToDefault:
     266                 :       73629 :             type = ((const SetToDefault *) expr)->typeId;
     267                 :       73629 :             break;
     268                 :         172 :         case T_CurrentOfExpr:
     269                 :         172 :             type = BOOLOID;
     270                 :         172 :             break;
     271                 :        1522 :         case T_NextValueExpr:
     272                 :        1522 :             type = ((const NextValueExpr *) expr)->typeId;
     273                 :        1522 :             break;
     274                 :           0 :         case T_InferenceElem:
     275                 :             :             {
     276                 :           0 :                 const InferenceElem *n = (const InferenceElem *) expr;
     277                 :             : 
     278                 :           0 :                 type = exprType((Node *) n->expr);
     279                 :             :             }
     280                 :           0 :             break;
     281                 :         640 :         case T_ReturningExpr:
     282                 :         640 :             type = exprType((Node *) ((const ReturningExpr *) expr)->retexpr);
     283                 :         640 :             break;
     284                 :       19406 :         case T_PlaceHolderVar:
     285                 :       19406 :             type = exprType((Node *) ((const PlaceHolderVar *) expr)->phexpr);
     286                 :       19406 :             break;
     287                 :           0 :         default:
     288         [ #  # ]:           0 :             elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
     289                 :             :             type = InvalidOid;  /* keep compiler quiet */
     290                 :             :             break;
     291                 :             :     }
     292                 :    22106972 :     return type;
     293                 :             : }
     294                 :             : 
     295                 :             : /*
     296                 :             :  *  exprTypmod -
     297                 :             :  *    returns the type-specific modifier of the expression's result type,
     298                 :             :  *    if it can be determined.  In many cases, it can't and we return -1.
     299                 :             :  */
     300                 :             : int32
     301                 :     7516698 : exprTypmod(const Node *expr)
     302                 :             : {
     303         [ -  + ]:     7516698 :     if (!expr)
     304                 :           0 :         return -1;
     305                 :             : 
     306   [ +  +  +  +  :     7516698 :     switch (nodeTag(expr))
          +  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  -  
          +  +  +  +  +  
                      + ]
     307                 :             :     {
     308                 :     4458895 :         case T_Var:
     309                 :     4458895 :             return ((const Var *) expr)->vartypmod;
     310                 :     1185951 :         case T_Const:
     311                 :     1185951 :             return ((const Const *) expr)->consttypmod;
     312                 :      111481 :         case T_Param:
     313                 :      111481 :             return ((const Param *) expr)->paramtypmod;
     314                 :       30387 :         case T_SubscriptingRef:
     315                 :       30387 :             return ((const SubscriptingRef *) expr)->reftypmod;
     316                 :      858065 :         case T_FuncExpr:
     317                 :             :             {
     318                 :             :                 int32       coercedTypmod;
     319                 :             : 
     320                 :             :                 /* Be smart about length-coercion functions... */
     321         [ +  + ]:      858065 :                 if (exprIsLengthCoercion(expr, &coercedTypmod))
     322                 :       17359 :                     return coercedTypmod;
     323                 :             :             }
     324                 :      840706 :             break;
     325                 :           0 :         case T_NamedArgExpr:
     326                 :           0 :             return exprTypmod((Node *) ((const NamedArgExpr *) expr)->arg);
     327                 :         321 :         case T_NullIfExpr:
     328                 :             :             {
     329                 :             :                 /*
     330                 :             :                  * Result is either first argument or NULL, so we can report
     331                 :             :                  * first argument's typmod if known.
     332                 :             :                  */
     333                 :         321 :                 const NullIfExpr *nexpr = (const NullIfExpr *) expr;
     334                 :             : 
     335                 :         321 :                 return exprTypmod((Node *) linitial(nexpr->args));
     336                 :             :             }
     337                 :             :             break;
     338                 :        4667 :         case T_SubLink:
     339                 :             :             {
     340                 :        4667 :                 const SubLink *sublink = (const SubLink *) expr;
     341                 :             : 
     342         [ +  + ]:        4667 :                 if (sublink->subLinkType == EXPR_SUBLINK ||
     343         [ +  + ]:         447 :                     sublink->subLinkType == ARRAY_SUBLINK)
     344                 :             :                 {
     345                 :             :                     /* get the typmod of the subselect's first target column */
     346                 :        4596 :                     Query      *qtree = (Query *) sublink->subselect;
     347                 :             :                     TargetEntry *tent;
     348                 :             : 
     349   [ +  -  -  + ]:        4596 :                     if (!qtree || !IsA(qtree, Query))
     350         [ #  # ]:           0 :                         elog(ERROR, "cannot get type for untransformed sublink");
     351                 :        4596 :                     tent = linitial_node(TargetEntry, qtree->targetList);
     352                 :             :                     Assert(!tent->resjunk);
     353                 :        4596 :                     return exprTypmod((Node *) tent->expr);
     354                 :             :                     /* note we don't need to care if it's an array */
     355                 :             :                 }
     356                 :             :                 /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
     357                 :             :             }
     358                 :          71 :             break;
     359                 :       25897 :         case T_SubPlan:
     360                 :             :             {
     361                 :       25897 :                 const SubPlan *subplan = (const SubPlan *) expr;
     362                 :             : 
     363         [ +  + ]:       25897 :                 if (subplan->subLinkType == EXPR_SUBLINK ||
     364         [ +  + ]:        1630 :                     subplan->subLinkType == ARRAY_SUBLINK)
     365                 :             :                 {
     366                 :             :                     /* get the typmod of the subselect's first target column */
     367                 :             :                     /* note we don't need to care if it's an array */
     368                 :       24444 :                     return subplan->firstColTypmod;
     369                 :             :                 }
     370                 :             :                 /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
     371                 :             :             }
     372                 :        1453 :             break;
     373                 :         490 :         case T_AlternativeSubPlan:
     374                 :             :             {
     375                 :         490 :                 const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
     376                 :             : 
     377                 :             :                 /* subplans should all return the same thing */
     378                 :         490 :                 return exprTypmod((Node *) linitial(asplan->subplans));
     379                 :             :             }
     380                 :             :             break;
     381                 :       14747 :         case T_FieldSelect:
     382                 :       14747 :             return ((const FieldSelect *) expr)->resulttypmod;
     383                 :      147019 :         case T_RelabelType:
     384                 :      147019 :             return ((const RelabelType *) expr)->resulttypmod;
     385                 :        5321 :         case T_ArrayCoerceExpr:
     386                 :        5321 :             return ((const ArrayCoerceExpr *) expr)->resulttypmod;
     387                 :         128 :         case T_CollateExpr:
     388                 :         128 :             return exprTypmod((Node *) ((const CollateExpr *) expr)->arg);
     389                 :      127070 :         case T_CaseExpr:
     390                 :             :             {
     391                 :             :                 /*
     392                 :             :                  * If all the alternatives agree on type/typmod, return that
     393                 :             :                  * typmod, else use -1
     394                 :             :                  */
     395                 :      127070 :                 const CaseExpr *cexpr = (const CaseExpr *) expr;
     396                 :      127070 :                 Oid         casetype = cexpr->casetype;
     397                 :             :                 int32       typmod;
     398                 :             :                 ListCell   *arg;
     399                 :             : 
     400         [ -  + ]:      127070 :                 if (!cexpr->defresult)
     401                 :           0 :                     return -1;
     402         [ -  + ]:      127070 :                 if (exprType((Node *) cexpr->defresult) != casetype)
     403                 :           0 :                     return -1;
     404                 :      127070 :                 typmod = exprTypmod((Node *) cexpr->defresult);
     405         [ +  - ]:      127070 :                 if (typmod < 0)
     406                 :      127070 :                     return -1;  /* no point in trying harder */
     407   [ #  #  #  #  :           0 :                 foreach(arg, cexpr->args)
                   #  # ]
     408                 :             :                 {
     409                 :           0 :                     CaseWhen   *w = lfirst_node(CaseWhen, arg);
     410                 :             : 
     411         [ #  # ]:           0 :                     if (exprType((Node *) w->result) != casetype)
     412                 :           0 :                         return -1;
     413         [ #  # ]:           0 :                     if (exprTypmod((Node *) w->result) != typmod)
     414                 :           0 :                         return -1;
     415                 :             :                 }
     416                 :           0 :                 return typmod;
     417                 :             :             }
     418                 :             :             break;
     419                 :        9328 :         case T_CaseTestExpr:
     420                 :        9328 :             return ((const CaseTestExpr *) expr)->typeMod;
     421                 :       27287 :         case T_ArrayExpr:
     422                 :             :             {
     423                 :             :                 /*
     424                 :             :                  * If all the elements agree on type/typmod, return that
     425                 :             :                  * typmod, else use -1
     426                 :             :                  */
     427                 :       27287 :                 const ArrayExpr *arrayexpr = (const ArrayExpr *) expr;
     428                 :             :                 Oid         commontype;
     429                 :             :                 int32       typmod;
     430                 :             :                 ListCell   *elem;
     431                 :             : 
     432         [ +  + ]:       27287 :                 if (arrayexpr->elements == NIL)
     433                 :         164 :                     return -1;
     434                 :       27123 :                 typmod = exprTypmod((Node *) linitial(arrayexpr->elements));
     435         [ +  + ]:       27123 :                 if (typmod < 0)
     436                 :       27111 :                     return -1;  /* no point in trying harder */
     437         [ -  + ]:          12 :                 if (arrayexpr->multidims)
     438                 :           0 :                     commontype = arrayexpr->array_typeid;
     439                 :             :                 else
     440                 :          12 :                     commontype = arrayexpr->element_typeid;
     441   [ +  -  +  +  :          36 :                 foreach(elem, arrayexpr->elements)
                   +  + ]
     442                 :             :                 {
     443                 :          24 :                     Node       *e = (Node *) lfirst(elem);
     444                 :             : 
     445         [ -  + ]:          24 :                     if (exprType(e) != commontype)
     446                 :           0 :                         return -1;
     447         [ -  + ]:          24 :                     if (exprTypmod(e) != typmod)
     448                 :           0 :                         return -1;
     449                 :             :                 }
     450                 :          12 :                 return typmod;
     451                 :             :             }
     452                 :             :             break;
     453                 :        6791 :         case T_CoalesceExpr:
     454                 :             :             {
     455                 :             :                 /*
     456                 :             :                  * If all the alternatives agree on type/typmod, return that
     457                 :             :                  * typmod, else use -1
     458                 :             :                  */
     459                 :        6791 :                 const CoalesceExpr *cexpr = (const CoalesceExpr *) expr;
     460                 :        6791 :                 Oid         coalescetype = cexpr->coalescetype;
     461                 :             :                 int32       typmod;
     462                 :             :                 ListCell   *arg;
     463                 :             : 
     464         [ -  + ]:        6791 :                 if (exprType((Node *) linitial(cexpr->args)) != coalescetype)
     465                 :           0 :                     return -1;
     466                 :        6791 :                 typmod = exprTypmod((Node *) linitial(cexpr->args));
     467         [ +  + ]:        6791 :                 if (typmod < 0)
     468                 :        6765 :                     return -1;  /* no point in trying harder */
     469   [ +  -  +  +  :          52 :                 for_each_from(arg, cexpr->args, 1)
                   +  + ]
     470                 :             :                 {
     471                 :          26 :                     Node       *e = (Node *) lfirst(arg);
     472                 :             : 
     473         [ -  + ]:          26 :                     if (exprType(e) != coalescetype)
     474                 :           0 :                         return -1;
     475         [ -  + ]:          26 :                     if (exprTypmod(e) != typmod)
     476                 :           0 :                         return -1;
     477                 :             :                 }
     478                 :          26 :                 return typmod;
     479                 :             :             }
     480                 :             :             break;
     481                 :        1895 :         case T_MinMaxExpr:
     482                 :             :             {
     483                 :             :                 /*
     484                 :             :                  * If all the alternatives agree on type/typmod, return that
     485                 :             :                  * typmod, else use -1
     486                 :             :                  */
     487                 :        1895 :                 const MinMaxExpr *mexpr = (const MinMaxExpr *) expr;
     488                 :        1895 :                 Oid         minmaxtype = mexpr->minmaxtype;
     489                 :             :                 int32       typmod;
     490                 :             :                 ListCell   *arg;
     491                 :             : 
     492         [ -  + ]:        1895 :                 if (exprType((Node *) linitial(mexpr->args)) != minmaxtype)
     493                 :           0 :                     return -1;
     494                 :        1895 :                 typmod = exprTypmod((Node *) linitial(mexpr->args));
     495         [ +  - ]:        1895 :                 if (typmod < 0)
     496                 :        1895 :                     return -1;  /* no point in trying harder */
     497   [ #  #  #  #  :           0 :                 for_each_from(arg, mexpr->args, 1)
                   #  # ]
     498                 :             :                 {
     499                 :           0 :                     Node       *e = (Node *) lfirst(arg);
     500                 :             : 
     501         [ #  # ]:           0 :                     if (exprType(e) != minmaxtype)
     502                 :           0 :                         return -1;
     503         [ #  # ]:           0 :                     if (exprTypmod(e) != typmod)
     504                 :           0 :                         return -1;
     505                 :             :                 }
     506                 :           0 :                 return typmod;
     507                 :             :             }
     508                 :             :             break;
     509                 :        1623 :         case T_SQLValueFunction:
     510                 :        1623 :             return ((const SQLValueFunction *) expr)->typmod;
     511                 :          44 :         case T_JsonValueExpr:
     512                 :          44 :             return exprTypmod((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
     513                 :        2304 :         case T_JsonConstructorExpr:
     514                 :        2304 :             return ((const JsonConstructorExpr *) expr)->returning->typmod;
     515                 :        3001 :         case T_JsonExpr:
     516                 :             :             {
     517                 :        3001 :                 const JsonExpr *jexpr = (const JsonExpr *) expr;
     518                 :             : 
     519                 :        3001 :                 return jexpr->returning->typmod;
     520                 :             :             }
     521                 :             :             break;
     522                 :           0 :         case T_JsonBehavior:
     523                 :             :             {
     524                 :           0 :                 const JsonBehavior *behavior = (const JsonBehavior *) expr;
     525                 :             : 
     526                 :           0 :                 return exprTypmod(behavior->expr);
     527                 :             :             }
     528                 :             :             break;
     529                 :      133974 :         case T_CoerceToDomain:
     530                 :      133974 :             return ((const CoerceToDomain *) expr)->resulttypmod;
     531                 :          52 :         case T_CoerceToDomainValue:
     532                 :          52 :             return ((const CoerceToDomainValue *) expr)->typeMod;
     533                 :       19331 :         case T_SetToDefault:
     534                 :       19331 :             return ((const SetToDefault *) expr)->typeMod;
     535                 :         352 :         case T_ReturningExpr:
     536                 :         352 :             return exprTypmod((Node *) ((const ReturningExpr *) expr)->retexpr);
     537                 :       10885 :         case T_PlaceHolderVar:
     538                 :       10885 :             return exprTypmod((Node *) ((const PlaceHolderVar *) expr)->phexpr);
     539                 :      329392 :         default:
     540                 :      329392 :             break;
     541                 :             :     }
     542                 :     1171622 :     return -1;
     543                 :             : }
     544                 :             : 
     545                 :             : /*
     546                 :             :  * exprIsLengthCoercion
     547                 :             :  *      Detect whether an expression tree is an application of a datatype's
     548                 :             :  *      typmod-coercion function.  Optionally extract the result's typmod.
     549                 :             :  *
     550                 :             :  * If coercedTypmod is not NULL, the typmod is stored there if the expression
     551                 :             :  * is a length-coercion function, else -1 is stored there.
     552                 :             :  *
     553                 :             :  * Note that a combined type-and-length coercion will be treated as a
     554                 :             :  * length coercion by this routine.
     555                 :             :  */
     556                 :             : bool
     557                 :      859180 : exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
     558                 :             : {
     559         [ +  - ]:      859180 :     if (coercedTypmod != NULL)
     560                 :      859180 :         *coercedTypmod = -1;    /* default result on failure */
     561                 :             : 
     562                 :             :     /*
     563                 :             :      * Scalar-type length coercions are FuncExprs, array-type length coercions
     564                 :             :      * are ArrayCoerceExprs
     565                 :             :      */
     566   [ +  -  +  - ]:      859180 :     if (expr && IsA(expr, FuncExpr))
     567                 :             :     {
     568                 :      859180 :         const FuncExpr *func = (const FuncExpr *) expr;
     569                 :             :         int         nargs;
     570                 :             :         Const      *second_arg;
     571                 :             : 
     572                 :             :         /*
     573                 :             :          * If it didn't come from a coercion context, reject.
     574                 :             :          */
     575         [ +  + ]:      859180 :         if (func->funcformat != COERCE_EXPLICIT_CAST &&
     576         [ +  + ]:      833699 :             func->funcformat != COERCE_IMPLICIT_CAST)
     577                 :      689824 :             return false;
     578                 :             : 
     579                 :             :         /*
     580                 :             :          * If it's not a two-argument or three-argument function with the
     581                 :             :          * second argument being an int4 constant, it can't have been created
     582                 :             :          * from a length coercion (it must be a type coercion, instead).
     583                 :             :          */
     584                 :      169356 :         nargs = list_length(func->args);
     585   [ +  +  -  + ]:      169356 :         if (nargs < 2 || nargs > 3)
     586                 :      151940 :             return false;
     587                 :             : 
     588                 :       17416 :         second_arg = (Const *) lsecond(func->args);
     589         [ +  - ]:       17416 :         if (!IsA(second_arg, Const) ||
     590         [ +  - ]:       17416 :             second_arg->consttype != INT4OID ||
     591         [ -  + ]:       17416 :             second_arg->constisnull)
     592                 :           0 :             return false;
     593                 :             : 
     594                 :             :         /*
     595                 :             :          * OK, it is indeed a length-coercion function.
     596                 :             :          */
     597         [ +  - ]:       17416 :         if (coercedTypmod != NULL)
     598                 :       17416 :             *coercedTypmod = DatumGetInt32(second_arg->constvalue);
     599                 :             : 
     600                 :       17416 :         return true;
     601                 :             :     }
     602                 :             : 
     603   [ #  #  #  # ]:           0 :     if (expr && IsA(expr, ArrayCoerceExpr))
     604                 :             :     {
     605                 :           0 :         const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
     606                 :             : 
     607                 :             :         /* It's not a length coercion unless there's a nondefault typmod */
     608         [ #  # ]:           0 :         if (acoerce->resulttypmod < 0)
     609                 :           0 :             return false;
     610                 :             : 
     611                 :             :         /*
     612                 :             :          * OK, it is indeed a length-coercion expression.
     613                 :             :          */
     614         [ #  # ]:           0 :         if (coercedTypmod != NULL)
     615                 :           0 :             *coercedTypmod = acoerce->resulttypmod;
     616                 :             : 
     617                 :           0 :         return true;
     618                 :             :     }
     619                 :             : 
     620                 :           0 :     return false;
     621                 :             : }
     622                 :             : 
     623                 :             : /*
     624                 :             :  * applyRelabelType
     625                 :             :  *      Add a RelabelType node if needed to make the expression expose
     626                 :             :  *      the specified type, typmod, and collation.
     627                 :             :  *
     628                 :             :  * This is primarily intended to be used during planning.  Therefore, it must
     629                 :             :  * maintain the post-eval_const_expressions invariants that there are not
     630                 :             :  * adjacent RelabelTypes, and that the tree is fully const-folded (hence,
     631                 :             :  * we mustn't return a RelabelType atop a Const).  If we do find a Const,
     632                 :             :  * we'll modify it in-place if "overwrite_ok" is true; that should only be
     633                 :             :  * passed as true if caller knows the Const is newly generated.
     634                 :             :  */
     635                 :             : Node *
     636                 :      237239 : applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid,
     637                 :             :                  CoercionForm rformat, int rlocation, bool overwrite_ok)
     638                 :             : {
     639                 :             :     /*
     640                 :             :      * If we find stacked RelabelTypes (eg, from foo::int::oid) we can discard
     641                 :             :      * all but the top one, and must do so to ensure that semantically
     642                 :             :      * equivalent expressions are equal().
     643                 :             :      */
     644   [ +  -  +  + ]:      239784 :     while (arg && IsA(arg, RelabelType))
     645                 :        2545 :         arg = (Node *) ((RelabelType *) arg)->arg;
     646                 :             : 
     647   [ +  -  +  + ]:      237239 :     if (arg && IsA(arg, Const))
     648                 :             :     {
     649                 :             :         /* Modify the Const directly to preserve const-flatness. */
     650                 :       85079 :         Const      *con = (Const *) arg;
     651                 :             : 
     652         [ +  + ]:       85079 :         if (!overwrite_ok)
     653                 :       11596 :             con = copyObject(con);
     654                 :       85079 :         con->consttype = rtype;
     655                 :       85079 :         con->consttypmod = rtypmod;
     656                 :       85079 :         con->constcollid = rcollid;
     657                 :             :         /* We keep the Const's original location. */
     658                 :       85079 :         return (Node *) con;
     659                 :             :     }
     660   [ +  +  +  + ]:      158210 :     else if (exprType(arg) == rtype &&
     661         [ +  + ]:       12040 :              exprTypmod(arg) == rtypmod &&
     662                 :        5990 :              exprCollation(arg) == rcollid)
     663                 :             :     {
     664                 :             :         /* Sometimes we find a nest of relabels that net out to nothing. */
     665                 :        2541 :         return arg;
     666                 :             :     }
     667                 :             :     else
     668                 :             :     {
     669                 :             :         /* Nope, gotta have a RelabelType. */
     670                 :      149619 :         RelabelType *newrelabel = makeNode(RelabelType);
     671                 :             : 
     672                 :      149619 :         newrelabel->arg = (Expr *) arg;
     673                 :      149619 :         newrelabel->resulttype = rtype;
     674                 :      149619 :         newrelabel->resulttypmod = rtypmod;
     675                 :      149619 :         newrelabel->resultcollid = rcollid;
     676                 :      149619 :         newrelabel->relabelformat = rformat;
     677                 :      149619 :         newrelabel->location = rlocation;
     678                 :      149619 :         return (Node *) newrelabel;
     679                 :             :     }
     680                 :             : }
     681                 :             : 
     682                 :             : /*
     683                 :             :  * relabel_to_typmod
     684                 :             :  *      Add a RelabelType node that changes just the typmod of the expression.
     685                 :             :  *
     686                 :             :  * Convenience function for a common usage of applyRelabelType.
     687                 :             :  */
     688                 :             : Node *
     689                 :          24 : relabel_to_typmod(Node *expr, int32 typmod)
     690                 :             : {
     691                 :          24 :     return applyRelabelType(expr, exprType(expr), typmod, exprCollation(expr),
     692                 :             :                             COERCE_EXPLICIT_CAST, -1, false);
     693                 :             : }
     694                 :             : 
     695                 :             : /*
     696                 :             :  * strip_implicit_coercions: remove implicit coercions at top level of tree
     697                 :             :  *
     698                 :             :  * This doesn't modify or copy the input expression tree, just return a
     699                 :             :  * pointer to a suitable place within it.
     700                 :             :  *
     701                 :             :  * Note: there isn't any useful thing we can do with a RowExpr here, so
     702                 :             :  * just return it unchanged, even if it's marked as an implicit coercion.
     703                 :             :  */
     704                 :             : Node *
     705                 :      687457 : strip_implicit_coercions(Node *node)
     706                 :             : {
     707         [ -  + ]:      687457 :     if (node == NULL)
     708                 :           0 :         return NULL;
     709         [ +  + ]:      687457 :     if (IsA(node, FuncExpr))
     710                 :             :     {
     711                 :        9487 :         FuncExpr   *f = (FuncExpr *) node;
     712                 :             : 
     713         [ +  + ]:        9487 :         if (f->funcformat == COERCE_IMPLICIT_CAST)
     714                 :          36 :             return strip_implicit_coercions(linitial(f->args));
     715                 :             :     }
     716         [ +  + ]:      677970 :     else if (IsA(node, RelabelType))
     717                 :             :     {
     718                 :        7844 :         RelabelType *r = (RelabelType *) node;
     719                 :             : 
     720         [ +  + ]:        7844 :         if (r->relabelformat == COERCE_IMPLICIT_CAST)
     721                 :           9 :             return strip_implicit_coercions((Node *) r->arg);
     722                 :             :     }
     723         [ +  + ]:      670126 :     else if (IsA(node, CoerceViaIO))
     724                 :             :     {
     725                 :         419 :         CoerceViaIO *c = (CoerceViaIO *) node;
     726                 :             : 
     727         [ -  + ]:         419 :         if (c->coerceformat == COERCE_IMPLICIT_CAST)
     728                 :           0 :             return strip_implicit_coercions((Node *) c->arg);
     729                 :             :     }
     730         [ -  + ]:      669707 :     else if (IsA(node, ArrayCoerceExpr))
     731                 :             :     {
     732                 :           0 :         ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
     733                 :             : 
     734         [ #  # ]:           0 :         if (c->coerceformat == COERCE_IMPLICIT_CAST)
     735                 :           0 :             return strip_implicit_coercions((Node *) c->arg);
     736                 :             :     }
     737         [ -  + ]:      669707 :     else if (IsA(node, ConvertRowtypeExpr))
     738                 :             :     {
     739                 :           0 :         ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node;
     740                 :             : 
     741         [ #  # ]:           0 :         if (c->convertformat == COERCE_IMPLICIT_CAST)
     742                 :           0 :             return strip_implicit_coercions((Node *) c->arg);
     743                 :             :     }
     744         [ +  + ]:      669707 :     else if (IsA(node, CoerceToDomain))
     745                 :             :     {
     746                 :        5301 :         CoerceToDomain *c = (CoerceToDomain *) node;
     747                 :             : 
     748         [ -  + ]:        5301 :         if (c->coercionformat == COERCE_IMPLICIT_CAST)
     749                 :           0 :             return strip_implicit_coercions((Node *) c->arg);
     750                 :             :     }
     751                 :      687412 :     return node;
     752                 :             : }
     753                 :             : 
     754                 :             : /*
     755                 :             :  * expression_returns_set
     756                 :             :  *    Test whether an expression returns a set result.
     757                 :             :  *
     758                 :             :  * Because we use expression_tree_walker(), this can also be applied to
     759                 :             :  * whole targetlists; it'll produce true if any one of the tlist items
     760                 :             :  * returns a set.
     761                 :             :  */
     762                 :             : bool
     763                 :      587062 : expression_returns_set(Node *clause)
     764                 :             : {
     765                 :      587062 :     return expression_returns_set_walker(clause, NULL);
     766                 :             : }
     767                 :             : 
     768                 :             : static bool
     769                 :     2534325 : expression_returns_set_walker(Node *node, void *context)
     770                 :             : {
     771         [ +  + ]:     2534325 :     if (node == NULL)
     772                 :       36046 :         return false;
     773         [ +  + ]:     2498279 :     if (IsA(node, FuncExpr))
     774                 :             :     {
     775                 :       79450 :         FuncExpr   *expr = (FuncExpr *) node;
     776                 :             : 
     777         [ +  + ]:       79450 :         if (expr->funcretset)
     778                 :       11904 :             return true;
     779                 :             :         /* else fall through to check args */
     780                 :             :     }
     781         [ +  + ]:     2486375 :     if (IsA(node, OpExpr))
     782                 :             :     {
     783                 :      561800 :         OpExpr     *expr = (OpExpr *) node;
     784                 :             : 
     785         [ +  + ]:      561800 :         if (expr->opretset)
     786                 :           5 :             return true;
     787                 :             :         /* else fall through to check args */
     788                 :             :     }
     789                 :             : 
     790                 :             :     /*
     791                 :             :      * If you add any more cases that return sets, also fix
     792                 :             :      * expression_returns_set_rows() in clauses.c and IS_SRF_CALL() in
     793                 :             :      * tlist.c.
     794                 :             :      */
     795                 :             : 
     796                 :             :     /* Avoid recursion for some cases that parser checks not to return a set */
     797         [ +  + ]:     2486370 :     if (IsA(node, Aggref))
     798                 :         804 :         return false;
     799         [ +  + ]:     2485566 :     if (IsA(node, GroupingFunc))
     800                 :          40 :         return false;
     801         [ +  + ]:     2485526 :     if (IsA(node, WindowFunc))
     802                 :          19 :         return false;
     803                 :             : 
     804                 :     2485507 :     return expression_tree_walker(node, expression_returns_set_walker,
     805                 :             :                                   context);
     806                 :             : }
     807                 :             : 
     808                 :             : 
     809                 :             : /*
     810                 :             :  *  exprCollation -
     811                 :             :  *    returns the Oid of the collation of the expression's result.
     812                 :             :  *
     813                 :             :  * Note: expression nodes that can invoke functions generally have an
     814                 :             :  * "inputcollid" field, which is what the function should use as collation.
     815                 :             :  * That is the resolved common collation of the node's inputs.  It is often
     816                 :             :  * but not always the same as the result collation; in particular, if the
     817                 :             :  * function produces a non-collatable result type from collatable inputs
     818                 :             :  * or vice versa, the two are different.
     819                 :             :  */
     820                 :             : Oid
     821                 :     9807691 : exprCollation(const Node *expr)
     822                 :             : {
     823                 :             :     Oid         coll;
     824                 :             : 
     825         [ -  + ]:     9807691 :     if (!expr)
     826                 :           0 :         return InvalidOid;
     827                 :             : 
     828   [ +  +  +  +  :     9807691 :     switch (nodeTag(expr))
          +  +  +  +  +  
          -  +  +  +  +  
          +  +  +  -  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  -  
          +  +  +  +  +  
          +  +  -  +  +  
                      - ]
     829                 :             :     {
     830                 :     7571146 :         case T_Var:
     831                 :     7571146 :             coll = ((const Var *) expr)->varcollid;
     832                 :     7571146 :             break;
     833                 :     1284383 :         case T_Const:
     834                 :     1284383 :             coll = ((const Const *) expr)->constcollid;
     835                 :     1284383 :             break;
     836                 :      131301 :         case T_Param:
     837                 :      131301 :             coll = ((const Param *) expr)->paramcollid;
     838                 :      131301 :             break;
     839                 :       65704 :         case T_Aggref:
     840                 :       65704 :             coll = ((const Aggref *) expr)->aggcollid;
     841                 :       65704 :             break;
     842                 :         555 :         case T_GroupingFunc:
     843                 :         555 :             coll = InvalidOid;
     844                 :         555 :             break;
     845                 :        4272 :         case T_WindowFunc:
     846                 :        4272 :             coll = ((const WindowFunc *) expr)->wincollid;
     847                 :        4272 :             break;
     848                 :         261 :         case T_MergeSupportFunc:
     849                 :         261 :             coll = ((const MergeSupportFunc *) expr)->msfcollid;
     850                 :         261 :             break;
     851                 :        6596 :         case T_SubscriptingRef:
     852                 :        6596 :             coll = ((const SubscriptingRef *) expr)->refcollid;
     853                 :        6596 :             break;
     854                 :      272492 :         case T_FuncExpr:
     855                 :      272492 :             coll = ((const FuncExpr *) expr)->funccollid;
     856                 :      272492 :             break;
     857                 :           0 :         case T_NamedArgExpr:
     858                 :           0 :             coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
     859                 :           0 :             break;
     860                 :       79014 :         case T_OpExpr:
     861                 :       79014 :             coll = ((const OpExpr *) expr)->opcollid;
     862                 :       79014 :             break;
     863                 :          52 :         case T_DistinctExpr:
     864                 :          52 :             coll = ((const DistinctExpr *) expr)->opcollid;
     865                 :          52 :             break;
     866                 :         173 :         case T_NullIfExpr:
     867                 :         173 :             coll = ((const NullIfExpr *) expr)->opcollid;
     868                 :         173 :             break;
     869                 :       14950 :         case T_ScalarArrayOpExpr:
     870                 :             :             /* ScalarArrayOpExpr's result is boolean ... */
     871                 :       14950 :             coll = InvalidOid;  /* ... so it has no collation */
     872                 :       14950 :             break;
     873                 :        2634 :         case T_BoolExpr:
     874                 :             :             /* BoolExpr's result is boolean ... */
     875                 :        2634 :             coll = InvalidOid;  /* ... so it has no collation */
     876                 :        2634 :             break;
     877                 :        2621 :         case T_SubLink:
     878                 :             :             {
     879                 :        2621 :                 const SubLink *sublink = (const SubLink *) expr;
     880                 :             : 
     881         [ +  + ]:        2621 :                 if (sublink->subLinkType == EXPR_SUBLINK ||
     882         [ +  + ]:         196 :                     sublink->subLinkType == ARRAY_SUBLINK)
     883                 :        2558 :                 {
     884                 :             :                     /* get the collation of subselect's first target column */
     885                 :        2558 :                     Query      *qtree = (Query *) sublink->subselect;
     886                 :             :                     TargetEntry *tent;
     887                 :             : 
     888   [ +  -  -  + ]:        2558 :                     if (!qtree || !IsA(qtree, Query))
     889         [ #  # ]:           0 :                         elog(ERROR, "cannot get collation for untransformed sublink");
     890                 :        2558 :                     tent = linitial_node(TargetEntry, qtree->targetList);
     891                 :             :                     Assert(!tent->resjunk);
     892                 :        2558 :                     coll = exprCollation((Node *) tent->expr);
     893                 :             :                     /* collation doesn't change if it's converted to array */
     894                 :             :                 }
     895                 :             :                 else
     896                 :             :                 {
     897                 :             :                     /* otherwise, SubLink's result is RECORD or BOOLEAN */
     898                 :          63 :                     coll = InvalidOid;  /* ... so it has no collation */
     899                 :             :                 }
     900                 :             :             }
     901                 :        2621 :             break;
     902                 :       14491 :         case T_SubPlan:
     903                 :             :             {
     904                 :       14491 :                 const SubPlan *subplan = (const SubPlan *) expr;
     905                 :             : 
     906         [ +  + ]:       14491 :                 if (subplan->subLinkType == EXPR_SUBLINK ||
     907         [ +  + ]:         207 :                     subplan->subLinkType == ARRAY_SUBLINK)
     908                 :             :                 {
     909                 :             :                     /* get the collation of subselect's first target column */
     910                 :       14348 :                     coll = subplan->firstColCollation;
     911                 :             :                     /* collation doesn't change if it's converted to array */
     912                 :             :                 }
     913                 :             :                 else
     914                 :             :                 {
     915                 :             :                     /* otherwise, SubPlan's result is RECORD or BOOLEAN */
     916                 :         143 :                     coll = InvalidOid;  /* ... so it has no collation */
     917                 :             :                 }
     918                 :             :             }
     919                 :       14491 :             break;
     920                 :           0 :         case T_AlternativeSubPlan:
     921                 :             :             {
     922                 :           0 :                 const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
     923                 :             : 
     924                 :             :                 /* subplans should all return the same thing */
     925                 :           0 :                 coll = exprCollation((Node *) linitial(asplan->subplans));
     926                 :             :             }
     927                 :           0 :             break;
     928                 :        8694 :         case T_FieldSelect:
     929                 :        8694 :             coll = ((const FieldSelect *) expr)->resultcollid;
     930                 :        8694 :             break;
     931                 :          42 :         case T_FieldStore:
     932                 :             :             /* FieldStore's result is composite ... */
     933                 :          42 :             coll = InvalidOid;  /* ... so it has no collation */
     934                 :          42 :             break;
     935                 :       85442 :         case T_RelabelType:
     936                 :       85442 :             coll = ((const RelabelType *) expr)->resultcollid;
     937                 :       85442 :             break;
     938                 :       30756 :         case T_CoerceViaIO:
     939                 :       30756 :             coll = ((const CoerceViaIO *) expr)->resultcollid;
     940                 :       30756 :             break;
     941                 :        1132 :         case T_ArrayCoerceExpr:
     942                 :        1132 :             coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
     943                 :        1132 :             break;
     944                 :         348 :         case T_ConvertRowtypeExpr:
     945                 :             :             /* ConvertRowtypeExpr's result is composite ... */
     946                 :         348 :             coll = InvalidOid;  /* ... so it has no collation */
     947                 :         348 :             break;
     948                 :         138 :         case T_CollateExpr:
     949                 :         138 :             coll = ((const CollateExpr *) expr)->collOid;
     950                 :         138 :             break;
     951                 :       96519 :         case T_CaseExpr:
     952                 :       96519 :             coll = ((const CaseExpr *) expr)->casecollid;
     953                 :       96519 :             break;
     954                 :       23841 :         case T_CaseTestExpr:
     955                 :       23841 :             coll = ((const CaseTestExpr *) expr)->collation;
     956                 :       23841 :             break;
     957                 :       21301 :         case T_ArrayExpr:
     958                 :       21301 :             coll = ((const ArrayExpr *) expr)->array_collid;
     959                 :       21301 :             break;
     960                 :        4162 :         case T_RowExpr:
     961                 :             :             /* RowExpr's result is composite ... */
     962                 :        4162 :             coll = InvalidOid;  /* ... so it has no collation */
     963                 :        4162 :             break;
     964                 :          44 :         case T_RowCompareExpr:
     965                 :             :             /* RowCompareExpr's result is boolean ... */
     966                 :          44 :             coll = InvalidOid;  /* ... so it has no collation */
     967                 :          44 :             break;
     968                 :        3418 :         case T_CoalesceExpr:
     969                 :        3418 :             coll = ((const CoalesceExpr *) expr)->coalescecollid;
     970                 :        3418 :             break;
     971                 :        1706 :         case T_MinMaxExpr:
     972                 :        1706 :             coll = ((const MinMaxExpr *) expr)->minmaxcollid;
     973                 :        1706 :             break;
     974                 :        1169 :         case T_SQLValueFunction:
     975                 :             :             /* Returns either NAME or a non-collatable type */
     976         [ +  + ]:        1169 :             if (((const SQLValueFunction *) expr)->type == NAMEOID)
     977                 :        1066 :                 coll = C_COLLATION_OID;
     978                 :             :             else
     979                 :         103 :                 coll = InvalidOid;
     980                 :        1169 :             break;
     981                 :         555 :         case T_XmlExpr:
     982                 :             : 
     983                 :             :             /*
     984                 :             :              * XMLSERIALIZE returns text from non-collatable inputs, so its
     985                 :             :              * collation is always default.  The other cases return boolean or
     986                 :             :              * XML, which are non-collatable.
     987                 :             :              */
     988         [ +  + ]:         555 :             if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
     989                 :         155 :                 coll = DEFAULT_COLLATION_OID;
     990                 :             :             else
     991                 :         400 :                 coll = InvalidOid;
     992                 :         555 :             break;
     993                 :           8 :         case T_JsonValueExpr:
     994                 :           8 :             coll = exprCollation((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
     995                 :           8 :             break;
     996                 :        1368 :         case T_JsonConstructorExpr:
     997                 :             :             {
     998                 :        1368 :                 const JsonConstructorExpr *ctor = (const JsonConstructorExpr *) expr;
     999                 :             : 
    1000                 :             :                 /*
    1001                 :             :                  * Collation comes from coercion if present, otherwise from
    1002                 :             :                  * func.  The func fallback is needed in cases where func
    1003                 :             :                  * already produces the final output type and no coercion is
    1004                 :             :                  * needed (cf. the JSCTOR_JSON_ARRAY_QUERY case).
    1005                 :             :                  */
    1006         [ +  + ]:        1368 :                 if (ctor->coercion)
    1007                 :         250 :                     coll = exprCollation((Node *) ctor->coercion);
    1008         [ +  + ]:        1118 :                 else if (ctor->func)
    1009                 :         580 :                     coll = exprCollation((Node *) ctor->func);
    1010                 :             :                 else
    1011                 :         538 :                     coll = InvalidOid;
    1012                 :             :             }
    1013                 :        1368 :             break;
    1014                 :         226 :         case T_JsonIsPredicate:
    1015                 :             :             /* IS JSON's result is boolean ... */
    1016                 :         226 :             coll = InvalidOid;  /* ... so it has no collation */
    1017                 :         226 :             break;
    1018                 :        1960 :         case T_JsonExpr:
    1019                 :             :             {
    1020                 :        1960 :                 const JsonExpr *jsexpr = (const JsonExpr *) expr;
    1021                 :             : 
    1022                 :        1960 :                 coll = jsexpr->collation;
    1023                 :             :             }
    1024                 :        1960 :             break;
    1025                 :           0 :         case T_JsonBehavior:
    1026                 :             :             {
    1027                 :           0 :                 const JsonBehavior *behavior = (const JsonBehavior *) expr;
    1028                 :             : 
    1029         [ #  # ]:           0 :                 if (behavior->expr)
    1030                 :           0 :                     coll = exprCollation(behavior->expr);
    1031                 :             :                 else
    1032                 :           0 :                     coll = InvalidOid;
    1033                 :             :             }
    1034                 :           0 :             break;
    1035                 :        1479 :         case T_NullTest:
    1036                 :             :             /* NullTest's result is boolean ... */
    1037                 :        1479 :             coll = InvalidOid;  /* ... so it has no collation */
    1038                 :        1479 :             break;
    1039                 :         270 :         case T_BooleanTest:
    1040                 :             :             /* BooleanTest's result is boolean ... */
    1041                 :         270 :             coll = InvalidOid;  /* ... so it has no collation */
    1042                 :         270 :             break;
    1043                 :       42669 :         case T_CoerceToDomain:
    1044                 :       42669 :             coll = ((const CoerceToDomain *) expr)->resultcollid;
    1045                 :       42669 :             break;
    1046                 :         566 :         case T_CoerceToDomainValue:
    1047                 :         566 :             coll = ((const CoerceToDomainValue *) expr)->collation;
    1048                 :         566 :             break;
    1049                 :       19089 :         case T_SetToDefault:
    1050                 :       19089 :             coll = ((const SetToDefault *) expr)->collation;
    1051                 :       19089 :             break;
    1052                 :         172 :         case T_CurrentOfExpr:
    1053                 :             :             /* CurrentOfExpr's result is boolean ... */
    1054                 :         172 :             coll = InvalidOid;  /* ... so it has no collation */
    1055                 :         172 :             break;
    1056                 :         405 :         case T_NextValueExpr:
    1057                 :             :             /* NextValueExpr's result is an integer type ... */
    1058                 :         405 :             coll = InvalidOid;  /* ... so it has no collation */
    1059                 :         405 :             break;
    1060                 :           0 :         case T_InferenceElem:
    1061                 :           0 :             coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
    1062                 :           0 :             break;
    1063                 :         352 :         case T_ReturningExpr:
    1064                 :         352 :             coll = exprCollation((Node *) ((const ReturningExpr *) expr)->retexpr);
    1065                 :         352 :             break;
    1066                 :        9215 :         case T_PlaceHolderVar:
    1067                 :        9215 :             coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
    1068                 :        9215 :             break;
    1069                 :           0 :         default:
    1070         [ #  # ]:           0 :             elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
    1071                 :             :             coll = InvalidOid;  /* keep compiler quiet */
    1072                 :             :             break;
    1073                 :             :     }
    1074                 :     9807691 :     return coll;
    1075                 :             : }
    1076                 :             : 
    1077                 :             : /*
    1078                 :             :  *  exprInputCollation -
    1079                 :             :  *    returns the Oid of the collation a function should use, if available.
    1080                 :             :  *
    1081                 :             :  * Result is InvalidOid if the node type doesn't store this information.
    1082                 :             :  */
    1083                 :             : Oid
    1084                 :      345674 : exprInputCollation(const Node *expr)
    1085                 :             : {
    1086                 :             :     Oid         coll;
    1087                 :             : 
    1088         [ -  + ]:      345674 :     if (!expr)
    1089                 :           0 :         return InvalidOid;
    1090                 :             : 
    1091   [ -  -  +  +  :      345674 :     switch (nodeTag(expr))
             +  +  +  +  
                      + ]
    1092                 :             :     {
    1093                 :           0 :         case T_Aggref:
    1094                 :           0 :             coll = ((const Aggref *) expr)->inputcollid;
    1095                 :           0 :             break;
    1096                 :           0 :         case T_WindowFunc:
    1097                 :           0 :             coll = ((const WindowFunc *) expr)->inputcollid;
    1098                 :           0 :             break;
    1099                 :          65 :         case T_FuncExpr:
    1100                 :          65 :             coll = ((const FuncExpr *) expr)->inputcollid;
    1101                 :          65 :             break;
    1102                 :      344977 :         case T_OpExpr:
    1103                 :      344977 :             coll = ((const OpExpr *) expr)->inputcollid;
    1104                 :      344977 :             break;
    1105                 :           4 :         case T_DistinctExpr:
    1106                 :           4 :             coll = ((const DistinctExpr *) expr)->inputcollid;
    1107                 :           4 :             break;
    1108                 :           8 :         case T_NullIfExpr:
    1109                 :           8 :             coll = ((const NullIfExpr *) expr)->inputcollid;
    1110                 :           8 :             break;
    1111                 :           4 :         case T_ScalarArrayOpExpr:
    1112                 :           4 :             coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
    1113                 :           4 :             break;
    1114                 :           4 :         case T_MinMaxExpr:
    1115                 :           4 :             coll = ((const MinMaxExpr *) expr)->inputcollid;
    1116                 :           4 :             break;
    1117                 :         612 :         default:
    1118                 :         612 :             coll = InvalidOid;
    1119                 :         612 :             break;
    1120                 :             :     }
    1121                 :      345674 :     return coll;
    1122                 :             : }
    1123                 :             : 
    1124                 :             : /*
    1125                 :             :  *  exprSetCollation -
    1126                 :             :  *    Assign collation information to an expression tree node.
    1127                 :             :  *
    1128                 :             :  * Note: since this is only used during parse analysis, we don't need to
    1129                 :             :  * worry about subplans, PlaceHolderVars, or ReturningExprs.
    1130                 :             :  */
    1131                 :             : void
    1132                 :     1183471 : exprSetCollation(Node *expr, Oid collation)
    1133                 :             : {
    1134   [ -  -  -  +  :     1183471 :     switch (nodeTag(expr))
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  -  +  +  
          +  +  +  +  +  
          -  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  -  
             -  -  -  - ]
    1135                 :             :     {
    1136                 :           0 :         case T_Var:
    1137                 :           0 :             ((Var *) expr)->varcollid = collation;
    1138                 :           0 :             break;
    1139                 :           0 :         case T_Const:
    1140                 :           0 :             ((Const *) expr)->constcollid = collation;
    1141                 :           0 :             break;
    1142                 :           0 :         case T_Param:
    1143                 :           0 :             ((Param *) expr)->paramcollid = collation;
    1144                 :           0 :             break;
    1145                 :       31754 :         case T_Aggref:
    1146                 :       31754 :             ((Aggref *) expr)->aggcollid = collation;
    1147                 :       31754 :             break;
    1148                 :         252 :         case T_GroupingFunc:
    1149                 :             :             Assert(!OidIsValid(collation));
    1150                 :         252 :             break;
    1151                 :        2748 :         case T_WindowFunc:
    1152                 :        2748 :             ((WindowFunc *) expr)->wincollid = collation;
    1153                 :        2748 :             break;
    1154                 :         156 :         case T_MergeSupportFunc:
    1155                 :         156 :             ((MergeSupportFunc *) expr)->msfcollid = collation;
    1156                 :         156 :             break;
    1157                 :        8630 :         case T_SubscriptingRef:
    1158                 :        8630 :             ((SubscriptingRef *) expr)->refcollid = collation;
    1159                 :        8630 :             break;
    1160                 :      279197 :         case T_FuncExpr:
    1161                 :      279197 :             ((FuncExpr *) expr)->funccollid = collation;
    1162                 :      279197 :             break;
    1163                 :       25545 :         case T_NamedArgExpr:
    1164                 :             :             Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
    1165                 :       25545 :             break;
    1166                 :      403656 :         case T_OpExpr:
    1167                 :      403656 :             ((OpExpr *) expr)->opcollid = collation;
    1168                 :      403656 :             break;
    1169                 :         733 :         case T_DistinctExpr:
    1170                 :         733 :             ((DistinctExpr *) expr)->opcollid = collation;
    1171                 :         733 :             break;
    1172                 :         472 :         case T_NullIfExpr:
    1173                 :         472 :             ((NullIfExpr *) expr)->opcollid = collation;
    1174                 :         472 :             break;
    1175                 :       22561 :         case T_ScalarArrayOpExpr:
    1176                 :             :             /* ScalarArrayOpExpr's result is boolean ... */
    1177                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1178                 :       22561 :             break;
    1179                 :      115778 :         case T_BoolExpr:
    1180                 :             :             /* BoolExpr's result is boolean ... */
    1181                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1182                 :      115778 :             break;
    1183                 :       36707 :         case T_SubLink:
    1184                 :             : #ifdef USE_ASSERT_CHECKING
    1185                 :             :             {
    1186                 :             :                 SubLink    *sublink = (SubLink *) expr;
    1187                 :             : 
    1188                 :             :                 if (sublink->subLinkType == EXPR_SUBLINK ||
    1189                 :             :                     sublink->subLinkType == ARRAY_SUBLINK)
    1190                 :             :                 {
    1191                 :             :                     /* get the collation of subselect's first target column */
    1192                 :             :                     Query      *qtree = (Query *) sublink->subselect;
    1193                 :             :                     TargetEntry *tent;
    1194                 :             : 
    1195                 :             :                     if (!qtree || !IsA(qtree, Query))
    1196                 :             :                         elog(ERROR, "cannot set collation for untransformed sublink");
    1197                 :             :                     tent = linitial_node(TargetEntry, qtree->targetList);
    1198                 :             :                     Assert(!tent->resjunk);
    1199                 :             :                     Assert(collation == exprCollation((Node *) tent->expr));
    1200                 :             :                 }
    1201                 :             :                 else
    1202                 :             :                 {
    1203                 :             :                     /* otherwise, result is RECORD or BOOLEAN */
    1204                 :             :                     Assert(!OidIsValid(collation));
    1205                 :             :                 }
    1206                 :             :             }
    1207                 :             : #endif                          /* USE_ASSERT_CHECKING */
    1208                 :       36707 :             break;
    1209                 :           0 :         case T_FieldSelect:
    1210                 :           0 :             ((FieldSelect *) expr)->resultcollid = collation;
    1211                 :           0 :             break;
    1212                 :         401 :         case T_FieldStore:
    1213                 :             :             /* FieldStore's result is composite ... */
    1214                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1215                 :         401 :             break;
    1216                 :      102208 :         case T_RelabelType:
    1217                 :      102208 :             ((RelabelType *) expr)->resultcollid = collation;
    1218                 :      102208 :             break;
    1219                 :       18066 :         case T_CoerceViaIO:
    1220                 :       18066 :             ((CoerceViaIO *) expr)->resultcollid = collation;
    1221                 :       18066 :             break;
    1222                 :        3617 :         case T_ArrayCoerceExpr:
    1223                 :        3617 :             ((ArrayCoerceExpr *) expr)->resultcollid = collation;
    1224                 :        3617 :             break;
    1225                 :          40 :         case T_ConvertRowtypeExpr:
    1226                 :             :             /* ConvertRowtypeExpr's result is composite ... */
    1227                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1228                 :          40 :             break;
    1229                 :       29535 :         case T_CaseExpr:
    1230                 :       29535 :             ((CaseExpr *) expr)->casecollid = collation;
    1231                 :       29535 :             break;
    1232                 :       18212 :         case T_ArrayExpr:
    1233                 :       18212 :             ((ArrayExpr *) expr)->array_collid = collation;
    1234                 :       18212 :             break;
    1235                 :           0 :         case T_RowExpr:
    1236                 :             :             /* RowExpr's result is composite ... */
    1237                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1238                 :           0 :             break;
    1239                 :           0 :         case T_RowCompareExpr:
    1240                 :             :             /* RowCompareExpr's result is boolean ... */
    1241                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1242                 :           0 :             break;
    1243                 :        4195 :         case T_CoalesceExpr:
    1244                 :        4195 :             ((CoalesceExpr *) expr)->coalescecollid = collation;
    1245                 :        4195 :             break;
    1246                 :         225 :         case T_MinMaxExpr:
    1247                 :         225 :             ((MinMaxExpr *) expr)->minmaxcollid = collation;
    1248                 :         225 :             break;
    1249                 :        1743 :         case T_SQLValueFunction:
    1250                 :             :             Assert((((SQLValueFunction *) expr)->type == NAMEOID) ?
    1251                 :             :                    (collation == C_COLLATION_OID) :
    1252                 :             :                    (collation == InvalidOid));
    1253                 :        1743 :             break;
    1254                 :         523 :         case T_XmlExpr:
    1255                 :             :             Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
    1256                 :             :                    (collation == DEFAULT_COLLATION_OID) :
    1257                 :             :                    (collation == InvalidOid));
    1258                 :         523 :             break;
    1259                 :         586 :         case T_JsonValueExpr:
    1260                 :         586 :             exprSetCollation((Node *) ((JsonValueExpr *) expr)->formatted_expr,
    1261                 :             :                              collation);
    1262                 :         586 :             break;
    1263                 :        1222 :         case T_JsonConstructorExpr:
    1264                 :             :             {
    1265                 :        1222 :                 JsonConstructorExpr *ctor = (JsonConstructorExpr *) expr;
    1266                 :             : 
    1267                 :             :                 /* See comment in exprCollation() */
    1268         [ +  + ]:        1222 :                 if (ctor->coercion)
    1269                 :         308 :                     exprSetCollation((Node *) ctor->coercion, collation);
    1270         [ +  + ]:         914 :                 else if (ctor->func)
    1271                 :         360 :                     exprSetCollation((Node *) ctor->func, collation);
    1272                 :             :                 else
    1273                 :             :                     Assert(!OidIsValid(collation)); /* result is always a
    1274                 :             :                                                      * json[b] type */
    1275                 :             :             }
    1276                 :        1222 :             break;
    1277                 :         264 :         case T_JsonIsPredicate:
    1278                 :             :             Assert(!OidIsValid(collation)); /* result is always boolean */
    1279                 :         264 :             break;
    1280                 :        2024 :         case T_JsonExpr:
    1281                 :             :             {
    1282                 :        2024 :                 JsonExpr   *jexpr = (JsonExpr *) expr;
    1283                 :             : 
    1284                 :        2024 :                 jexpr->collation = collation;
    1285                 :             :             }
    1286                 :        2024 :             break;
    1287                 :        3840 :         case T_JsonBehavior:
    1288                 :             :             Assert(((JsonBehavior *) expr)->expr == NULL ||
    1289                 :             :                    exprCollation(((JsonBehavior *) expr)->expr) == collation);
    1290                 :        3840 :             break;
    1291                 :       14294 :         case T_NullTest:
    1292                 :             :             /* NullTest's result is boolean ... */
    1293                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1294                 :       14294 :             break;
    1295                 :         683 :         case T_BooleanTest:
    1296                 :             :             /* BooleanTest's result is boolean ... */
    1297                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1298                 :         683 :             break;
    1299                 :       53604 :         case T_CoerceToDomain:
    1300                 :       53604 :             ((CoerceToDomain *) expr)->resultcollid = collation;
    1301                 :       53604 :             break;
    1302                 :           0 :         case T_CoerceToDomainValue:
    1303                 :           0 :             ((CoerceToDomainValue *) expr)->collation = collation;
    1304                 :           0 :             break;
    1305                 :           0 :         case T_SetToDefault:
    1306                 :           0 :             ((SetToDefault *) expr)->collation = collation;
    1307                 :           0 :             break;
    1308                 :           0 :         case T_CurrentOfExpr:
    1309                 :             :             /* CurrentOfExpr's result is boolean ... */
    1310                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1311                 :           0 :             break;
    1312                 :           0 :         case T_NextValueExpr:
    1313                 :             :             /* NextValueExpr's result is an integer type ... */
    1314                 :             :             Assert(!OidIsValid(collation)); /* ... so never set a collation */
    1315                 :           0 :             break;
    1316                 :           0 :         default:
    1317         [ #  # ]:           0 :             elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
    1318                 :             :             break;
    1319                 :             :     }
    1320                 :     1183471 : }
    1321                 :             : 
    1322                 :             : /*
    1323                 :             :  *  exprSetInputCollation -
    1324                 :             :  *    Assign input-collation information to an expression tree node.
    1325                 :             :  *
    1326                 :             :  * This is a no-op for node types that don't store their input collation.
    1327                 :             :  * Note we omit RowCompareExpr, which needs special treatment since it
    1328                 :             :  * contains multiple input collation OIDs.
    1329                 :             :  */
    1330                 :             : void
    1331                 :     1128621 : exprSetInputCollation(Node *expr, Oid inputcollation)
    1332                 :             : {
    1333   [ +  +  +  +  :     1128621 :     switch (nodeTag(expr))
             +  +  +  +  
                      + ]
    1334                 :             :     {
    1335                 :       31502 :         case T_Aggref:
    1336                 :       31502 :             ((Aggref *) expr)->inputcollid = inputcollation;
    1337                 :       31502 :             break;
    1338                 :        2716 :         case T_WindowFunc:
    1339                 :        2716 :             ((WindowFunc *) expr)->inputcollid = inputcollation;
    1340                 :        2716 :             break;
    1341                 :      279053 :         case T_FuncExpr:
    1342                 :      279053 :             ((FuncExpr *) expr)->inputcollid = inputcollation;
    1343                 :      279053 :             break;
    1344                 :      403656 :         case T_OpExpr:
    1345                 :      403656 :             ((OpExpr *) expr)->inputcollid = inputcollation;
    1346                 :      403656 :             break;
    1347                 :         733 :         case T_DistinctExpr:
    1348                 :         733 :             ((DistinctExpr *) expr)->inputcollid = inputcollation;
    1349                 :         733 :             break;
    1350                 :         472 :         case T_NullIfExpr:
    1351                 :         472 :             ((NullIfExpr *) expr)->inputcollid = inputcollation;
    1352                 :         472 :             break;
    1353                 :       22561 :         case T_ScalarArrayOpExpr:
    1354                 :       22561 :             ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
    1355                 :       22561 :             break;
    1356                 :         225 :         case T_MinMaxExpr:
    1357                 :         225 :             ((MinMaxExpr *) expr)->inputcollid = inputcollation;
    1358                 :         225 :             break;
    1359                 :      387703 :         default:
    1360                 :      387703 :             break;
    1361                 :             :     }
    1362                 :     1128621 : }
    1363                 :             : 
    1364                 :             : 
    1365                 :             : /*
    1366                 :             :  *  exprLocation -
    1367                 :             :  *    returns the parse location of an expression tree, for error reports
    1368                 :             :  *
    1369                 :             :  * -1 is returned if the location can't be determined.
    1370                 :             :  *
    1371                 :             :  * For expressions larger than a single token, the intent here is to
    1372                 :             :  * return the location of the expression's leftmost token, not necessarily
    1373                 :             :  * the topmost Node's location field.  For example, an OpExpr's location
    1374                 :             :  * field will point at the operator name, but if it is not a prefix operator
    1375                 :             :  * then we should return the location of the left-hand operand instead.
    1376                 :             :  * The reason is that we want to reference the entire expression not just
    1377                 :             :  * that operator, and pointing to its start seems to be the most natural way.
    1378                 :             :  *
    1379                 :             :  * The location is not perfect --- for example, since the grammar doesn't
    1380                 :             :  * explicitly represent parentheses in the parsetree, given something that
    1381                 :             :  * had been written "(a + b) * c" we are going to point at "a" not "(".
    1382                 :             :  * But it should be plenty good enough for error reporting purposes.
    1383                 :             :  *
    1384                 :             :  * You might think that this code is overly general, for instance why check
    1385                 :             :  * the operands of a FuncExpr node, when the function name can be expected
    1386                 :             :  * to be to the left of them?  There are a couple of reasons.  The grammar
    1387                 :             :  * sometimes builds expressions that aren't quite what the user wrote;
    1388                 :             :  * for instance x IS NOT BETWEEN ... becomes a NOT-expression whose keyword
    1389                 :             :  * pointer is to the right of its leftmost argument.  Also, nodes that were
    1390                 :             :  * inserted implicitly by parse analysis (such as FuncExprs for implicit
    1391                 :             :  * coercions) will have location -1, and so we can have odd combinations of
    1392                 :             :  * known and unknown locations in a tree.
    1393                 :             :  */
    1394                 :             : int
    1395                 :     2852030 : exprLocation(const Node *expr)
    1396                 :             : {
    1397                 :             :     int         loc;
    1398                 :             : 
    1399         [ +  + ]:     2852030 :     if (expr == NULL)
    1400                 :       16444 :         return -1;
    1401   [ +  -  +  +  :     2835586 :     switch (nodeTag(expr))
          +  +  +  +  +  
          +  +  +  +  -  
          +  +  +  -  +  
          +  +  +  +  +  
          -  +  +  -  +  
          +  +  +  -  -  
          +  -  +  +  +  
          -  +  +  +  -  
          -  +  +  +  +  
          -  +  +  -  +  
          -  +  +  +  -  
          -  -  +  -  -  
          -  -  +  -  -  
          +  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
                +  +  + ]
    1402                 :             :     {
    1403                 :          20 :         case T_RangeVar:
    1404                 :          20 :             loc = ((const RangeVar *) expr)->location;
    1405                 :          20 :             break;
    1406                 :           0 :         case T_TableFunc:
    1407                 :           0 :             loc = ((const TableFunc *) expr)->location;
    1408                 :           0 :             break;
    1409                 :     1473075 :         case T_Var:
    1410                 :     1473075 :             loc = ((const Var *) expr)->location;
    1411                 :     1473075 :             break;
    1412                 :      886792 :         case T_Const:
    1413                 :      886792 :             loc = ((const Const *) expr)->location;
    1414                 :      886792 :             break;
    1415                 :       68096 :         case T_Param:
    1416                 :       68096 :             loc = ((const Param *) expr)->location;
    1417                 :       68096 :             break;
    1418                 :        6444 :         case T_Aggref:
    1419                 :             :             /* function name should always be the first thing */
    1420                 :        6444 :             loc = ((const Aggref *) expr)->location;
    1421                 :        6444 :             break;
    1422                 :          50 :         case T_GroupingFunc:
    1423                 :          50 :             loc = ((const GroupingFunc *) expr)->location;
    1424                 :          50 :             break;
    1425                 :          36 :         case T_WindowFunc:
    1426                 :             :             /* function name should always be the first thing */
    1427                 :          36 :             loc = ((const WindowFunc *) expr)->location;
    1428                 :          36 :             break;
    1429                 :         156 :         case T_MergeSupportFunc:
    1430                 :         156 :             loc = ((const MergeSupportFunc *) expr)->location;
    1431                 :         156 :             break;
    1432                 :         198 :         case T_SubscriptingRef:
    1433                 :             :             /* just use container argument's location */
    1434                 :         198 :             loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
    1435                 :         198 :             break;
    1436                 :       65629 :         case T_FuncExpr:
    1437                 :             :             {
    1438                 :       65629 :                 const FuncExpr *fexpr = (const FuncExpr *) expr;
    1439                 :             : 
    1440                 :             :                 /* consider both function name and leftmost arg */
    1441                 :       65629 :                 loc = leftmostLoc(fexpr->location,
    1442                 :       65629 :                                   exprLocation((Node *) fexpr->args));
    1443                 :             :             }
    1444                 :       65629 :             break;
    1445                 :           4 :         case T_NamedArgExpr:
    1446                 :             :             {
    1447                 :           4 :                 const NamedArgExpr *na = (const NamedArgExpr *) expr;
    1448                 :             : 
    1449                 :             :                 /* consider both argument name and value */
    1450                 :           4 :                 loc = leftmostLoc(na->location,
    1451                 :           4 :                                   exprLocation((Node *) na->arg));
    1452                 :             :             }
    1453                 :           4 :             break;
    1454                 :        8450 :         case T_OpExpr:
    1455                 :             :         case T_DistinctExpr:    /* struct-equivalent to OpExpr */
    1456                 :             :         case T_NullIfExpr:      /* struct-equivalent to OpExpr */
    1457                 :             :             {
    1458                 :        8450 :                 const OpExpr *opexpr = (const OpExpr *) expr;
    1459                 :             : 
    1460                 :             :                 /* consider both operator name and leftmost arg */
    1461                 :        8450 :                 loc = leftmostLoc(opexpr->location,
    1462                 :        8450 :                                   exprLocation((Node *) opexpr->args));
    1463                 :             :             }
    1464                 :        8450 :             break;
    1465                 :           0 :         case T_ScalarArrayOpExpr:
    1466                 :             :             {
    1467                 :           0 :                 const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
    1468                 :             : 
    1469                 :             :                 /* consider both operator name and leftmost arg */
    1470                 :           0 :                 loc = leftmostLoc(saopexpr->location,
    1471                 :           0 :                                   exprLocation((Node *) saopexpr->args));
    1472                 :             :             }
    1473                 :           0 :             break;
    1474                 :          91 :         case T_BoolExpr:
    1475                 :             :             {
    1476                 :          91 :                 const BoolExpr *bexpr = (const BoolExpr *) expr;
    1477                 :             : 
    1478                 :             :                 /*
    1479                 :             :                  * Same as above, to handle either NOT or AND/OR.  We can't
    1480                 :             :                  * special-case NOT because of the way that it's used for
    1481                 :             :                  * things like IS NOT BETWEEN.
    1482                 :             :                  */
    1483                 :          91 :                 loc = leftmostLoc(bexpr->location,
    1484                 :          91 :                                   exprLocation((Node *) bexpr->args));
    1485                 :             :             }
    1486                 :          91 :             break;
    1487                 :         787 :         case T_SubLink:
    1488                 :             :             {
    1489                 :         787 :                 const SubLink *sublink = (const SubLink *) expr;
    1490                 :             : 
    1491                 :             :                 /* check the testexpr, if any, and the operator/keyword */
    1492                 :         787 :                 loc = leftmostLoc(exprLocation(sublink->testexpr),
    1493                 :         787 :                                   sublink->location);
    1494                 :             :             }
    1495                 :         787 :             break;
    1496                 :        2705 :         case T_FieldSelect:
    1497                 :             :             /* just use argument's location */
    1498                 :        2705 :             loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
    1499                 :        2705 :             break;
    1500                 :           0 :         case T_FieldStore:
    1501                 :             :             /* just use argument's location */
    1502                 :           0 :             loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
    1503                 :           0 :             break;
    1504                 :        9328 :         case T_RelabelType:
    1505                 :             :             {
    1506                 :        9328 :                 const RelabelType *rexpr = (const RelabelType *) expr;
    1507                 :             : 
    1508                 :             :                 /* Much as above */
    1509                 :        9328 :                 loc = leftmostLoc(rexpr->location,
    1510                 :        9328 :                                   exprLocation((Node *) rexpr->arg));
    1511                 :             :             }
    1512                 :        9328 :             break;
    1513                 :       16282 :         case T_CoerceViaIO:
    1514                 :             :             {
    1515                 :       16282 :                 const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
    1516                 :             : 
    1517                 :             :                 /* Much as above */
    1518                 :       16282 :                 loc = leftmostLoc(cexpr->location,
    1519                 :       16282 :                                   exprLocation((Node *) cexpr->arg));
    1520                 :             :             }
    1521                 :       16282 :             break;
    1522                 :          14 :         case T_ArrayCoerceExpr:
    1523                 :             :             {
    1524                 :          14 :                 const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
    1525                 :             : 
    1526                 :             :                 /* Much as above */
    1527                 :          14 :                 loc = leftmostLoc(cexpr->location,
    1528                 :          14 :                                   exprLocation((Node *) cexpr->arg));
    1529                 :             :             }
    1530                 :          14 :             break;
    1531                 :           8 :         case T_ConvertRowtypeExpr:
    1532                 :             :             {
    1533                 :           8 :                 const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
    1534                 :             : 
    1535                 :             :                 /* Much as above */
    1536                 :           8 :                 loc = leftmostLoc(cexpr->location,
    1537                 :           8 :                                   exprLocation((Node *) cexpr->arg));
    1538                 :             :             }
    1539                 :           8 :             break;
    1540                 :          32 :         case T_CollateExpr:
    1541                 :             :             /* just use argument's location */
    1542                 :          32 :             loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
    1543                 :          32 :             break;
    1544                 :        7112 :         case T_CaseExpr:
    1545                 :             :             /* CASE keyword should always be the first thing */
    1546                 :        7112 :             loc = ((const CaseExpr *) expr)->location;
    1547                 :        7112 :             break;
    1548                 :           0 :         case T_CaseWhen:
    1549                 :             :             /* WHEN keyword should always be the first thing */
    1550                 :           0 :             loc = ((const CaseWhen *) expr)->location;
    1551                 :           0 :             break;
    1552                 :         278 :         case T_ArrayExpr:
    1553                 :             :             /* the location points at ARRAY or [, which must be leftmost */
    1554                 :         278 :             loc = ((const ArrayExpr *) expr)->location;
    1555                 :         278 :             break;
    1556                 :         237 :         case T_RowExpr:
    1557                 :             :             /* the location points at ROW or (, which must be leftmost */
    1558                 :         237 :             loc = ((const RowExpr *) expr)->location;
    1559                 :         237 :             break;
    1560                 :           0 :         case T_RowCompareExpr:
    1561                 :             :             /* just use leftmost argument's location */
    1562                 :           0 :             loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
    1563                 :           0 :             break;
    1564                 :        1339 :         case T_CoalesceExpr:
    1565                 :             :             /* COALESCE keyword should always be the first thing */
    1566                 :        1339 :             loc = ((const CoalesceExpr *) expr)->location;
    1567                 :        1339 :             break;
    1568                 :          19 :         case T_MinMaxExpr:
    1569                 :             :             /* GREATEST/LEAST keyword should always be the first thing */
    1570                 :          19 :             loc = ((const MinMaxExpr *) expr)->location;
    1571                 :          19 :             break;
    1572                 :        1104 :         case T_SQLValueFunction:
    1573                 :             :             /* function keyword should always be the first thing */
    1574                 :        1104 :             loc = ((const SQLValueFunction *) expr)->location;
    1575                 :        1104 :             break;
    1576                 :         144 :         case T_XmlExpr:
    1577                 :             :             {
    1578                 :         144 :                 const XmlExpr *xexpr = (const XmlExpr *) expr;
    1579                 :             : 
    1580                 :             :                 /* consider both function name and leftmost arg */
    1581                 :         144 :                 loc = leftmostLoc(xexpr->location,
    1582                 :         144 :                                   exprLocation((Node *) xexpr->args));
    1583                 :             :             }
    1584                 :         144 :             break;
    1585                 :           0 :         case T_JsonFormat:
    1586                 :           0 :             loc = ((const JsonFormat *) expr)->location;
    1587                 :           0 :             break;
    1588                 :           0 :         case T_JsonValueExpr:
    1589                 :           0 :             loc = exprLocation((Node *) ((const JsonValueExpr *) expr)->raw_expr);
    1590                 :           0 :             break;
    1591                 :         162 :         case T_JsonConstructorExpr:
    1592                 :         162 :             loc = ((const JsonConstructorExpr *) expr)->location;
    1593                 :         162 :             break;
    1594                 :           0 :         case T_JsonIsPredicate:
    1595                 :           0 :             loc = ((const JsonIsPredicate *) expr)->location;
    1596                 :           0 :             break;
    1597                 :         396 :         case T_JsonExpr:
    1598                 :             :             {
    1599                 :         396 :                 const JsonExpr *jsexpr = (const JsonExpr *) expr;
    1600                 :             : 
    1601                 :             :                 /* consider both function name and leftmost arg */
    1602                 :         396 :                 loc = leftmostLoc(jsexpr->location,
    1603                 :         396 :                                   exprLocation(jsexpr->formatted_expr));
    1604                 :             :             }
    1605                 :         396 :             break;
    1606                 :         176 :         case T_JsonBehavior:
    1607                 :         176 :             loc = exprLocation(((const JsonBehavior *) expr)->expr);
    1608                 :         176 :             break;
    1609                 :         118 :         case T_NullTest:
    1610                 :             :             {
    1611                 :         118 :                 const NullTest *nexpr = (const NullTest *) expr;
    1612                 :             : 
    1613                 :             :                 /* Much as above */
    1614                 :         118 :                 loc = leftmostLoc(nexpr->location,
    1615                 :         118 :                                   exprLocation((Node *) nexpr->arg));
    1616                 :             :             }
    1617                 :         118 :             break;
    1618                 :           0 :         case T_BooleanTest:
    1619                 :             :             {
    1620                 :           0 :                 const BooleanTest *bexpr = (const BooleanTest *) expr;
    1621                 :             : 
    1622                 :             :                 /* Much as above */
    1623                 :           0 :                 loc = leftmostLoc(bexpr->location,
    1624                 :           0 :                                   exprLocation((Node *) bexpr->arg));
    1625                 :             :             }
    1626                 :           0 :             break;
    1627                 :       50277 :         case T_CoerceToDomain:
    1628                 :             :             {
    1629                 :       50277 :                 const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
    1630                 :             : 
    1631                 :             :                 /* Much as above */
    1632                 :       50277 :                 loc = leftmostLoc(cexpr->location,
    1633                 :       50277 :                                   exprLocation((Node *) cexpr->arg));
    1634                 :             :             }
    1635                 :       50277 :             break;
    1636                 :         719 :         case T_CoerceToDomainValue:
    1637                 :         719 :             loc = ((const CoerceToDomainValue *) expr)->location;
    1638                 :         719 :             break;
    1639                 :       37055 :         case T_SetToDefault:
    1640                 :       37055 :             loc = ((const SetToDefault *) expr)->location;
    1641                 :       37055 :             break;
    1642                 :           0 :         case T_ReturningExpr:
    1643                 :           0 :             loc = exprLocation((Node *) ((const ReturningExpr *) expr)->retexpr);
    1644                 :           0 :             break;
    1645                 :           0 :         case T_TargetEntry:
    1646                 :             :             /* just use argument's location */
    1647                 :           0 :             loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
    1648                 :           0 :             break;
    1649                 :          12 :         case T_IntoClause:
    1650                 :             :             /* use the contained RangeVar's location --- close enough */
    1651                 :          12 :             loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
    1652                 :          12 :             break;
    1653                 :       62449 :         case T_List:
    1654                 :             :             {
    1655                 :             :                 /* report location of first list member that has a location */
    1656                 :             :                 ListCell   *lc;
    1657                 :             : 
    1658                 :       62449 :                 loc = -1;       /* just to suppress compiler warning */
    1659   [ +  -  +  +  :       62952 :                 foreach(lc, (const List *) expr)
                   +  + ]
    1660                 :             :                 {
    1661                 :       62691 :                     loc = exprLocation((Node *) lfirst(lc));
    1662         [ +  + ]:       62691 :                     if (loc >= 0)
    1663                 :       62188 :                         break;
    1664                 :             :                 }
    1665                 :             :             }
    1666                 :       62449 :             break;
    1667                 :        3511 :         case T_A_Expr:
    1668                 :             :             {
    1669                 :        3511 :                 const A_Expr *aexpr = (const A_Expr *) expr;
    1670                 :             : 
    1671                 :             :                 /* use leftmost of operator or left operand (if any) */
    1672                 :             :                 /* we assume right operand can't be to left of operator */
    1673                 :        3511 :                 loc = leftmostLoc(aexpr->location,
    1674                 :        3511 :                                   exprLocation(aexpr->lexpr));
    1675                 :             :             }
    1676                 :        3511 :             break;
    1677                 :       52917 :         case T_ColumnRef:
    1678                 :       52917 :             loc = ((const ColumnRef *) expr)->location;
    1679                 :       52917 :             break;
    1680                 :           0 :         case T_ParamRef:
    1681                 :           0 :             loc = ((const ParamRef *) expr)->location;
    1682                 :           0 :             break;
    1683                 :       44984 :         case T_A_Const:
    1684                 :       44984 :             loc = ((const A_Const *) expr)->location;
    1685                 :       44984 :             break;
    1686                 :        2527 :         case T_FuncCall:
    1687                 :             :             {
    1688                 :        2527 :                 const FuncCall *fc = (const FuncCall *) expr;
    1689                 :             : 
    1690                 :             :                 /* consider both function name and leftmost arg */
    1691                 :             :                 /* (we assume any ORDER BY nodes must be to right of name) */
    1692                 :        2527 :                 loc = leftmostLoc(fc->location,
    1693                 :        2527 :                                   exprLocation((Node *) fc->args));
    1694                 :             :             }
    1695                 :        2527 :             break;
    1696                 :           0 :         case T_A_ArrayExpr:
    1697                 :             :             /* the location points at ARRAY or [, which must be leftmost */
    1698                 :           0 :             loc = ((const A_ArrayExpr *) expr)->location;
    1699                 :           0 :             break;
    1700                 :          12 :         case T_ResTarget:
    1701                 :             :             /* we need not examine the contained expression (if any) */
    1702                 :          12 :             loc = ((const ResTarget *) expr)->location;
    1703                 :          12 :             break;
    1704                 :           0 :         case T_MultiAssignRef:
    1705                 :           0 :             loc = exprLocation(((const MultiAssignRef *) expr)->source);
    1706                 :           0 :             break;
    1707                 :        5210 :         case T_TypeCast:
    1708                 :             :             {
    1709                 :        5210 :                 const TypeCast *tc = (const TypeCast *) expr;
    1710                 :             : 
    1711                 :             :                 /*
    1712                 :             :                  * This could represent CAST(), ::, or TypeName 'literal', so
    1713                 :             :                  * any of the components might be leftmost.
    1714                 :             :                  */
    1715                 :        5210 :                 loc = exprLocation(tc->arg);
    1716                 :        5210 :                 loc = leftmostLoc(loc, tc->typeName->location);
    1717                 :        5210 :                 loc = leftmostLoc(loc, tc->location);
    1718                 :             :             }
    1719                 :        5210 :             break;
    1720                 :         527 :         case T_CollateClause:
    1721                 :             :             /* just use argument's location */
    1722                 :         527 :             loc = exprLocation(((const CollateClause *) expr)->arg);
    1723                 :         527 :             break;
    1724                 :           8 :         case T_SortBy:
    1725                 :             :             /* just use argument's location (ignore operator, if any) */
    1726                 :           8 :             loc = exprLocation(((const SortBy *) expr)->node);
    1727                 :           8 :             break;
    1728                 :           0 :         case T_WindowDef:
    1729                 :           0 :             loc = ((const WindowDef *) expr)->location;
    1730                 :           0 :             break;
    1731                 :           0 :         case T_RangeTableSample:
    1732                 :           0 :             loc = ((const RangeTableSample *) expr)->location;
    1733                 :           0 :             break;
    1734                 :           0 :         case T_TypeName:
    1735                 :           0 :             loc = ((const TypeName *) expr)->location;
    1736                 :           0 :             break;
    1737                 :          12 :         case T_ColumnDef:
    1738                 :          12 :             loc = ((const ColumnDef *) expr)->location;
    1739                 :          12 :             break;
    1740                 :           0 :         case T_IndexElem:
    1741                 :           0 :             loc = ((const IndexElem *) expr)->location;
    1742                 :           0 :             break;
    1743                 :           0 :         case T_Constraint:
    1744                 :           0 :             loc = ((const Constraint *) expr)->location;
    1745                 :           0 :             break;
    1746                 :           0 :         case T_FunctionParameter:
    1747                 :           0 :             loc = ((const FunctionParameter *) expr)->location;
    1748                 :           0 :             break;
    1749                 :           0 :         case T_XmlSerialize:
    1750                 :             :             /* XMLSERIALIZE keyword should always be the first thing */
    1751                 :           0 :             loc = ((const XmlSerialize *) expr)->location;
    1752                 :           0 :             break;
    1753                 :          28 :         case T_GroupingSet:
    1754                 :          28 :             loc = ((const GroupingSet *) expr)->location;
    1755                 :          28 :             break;
    1756                 :           0 :         case T_WithClause:
    1757                 :           0 :             loc = ((const WithClause *) expr)->location;
    1758                 :           0 :             break;
    1759                 :           0 :         case T_InferClause:
    1760                 :           0 :             loc = ((const InferClause *) expr)->location;
    1761                 :           0 :             break;
    1762                 :           4 :         case T_OnConflictClause:
    1763                 :           4 :             loc = ((const OnConflictClause *) expr)->location;
    1764                 :           4 :             break;
    1765                 :           0 :         case T_CTESearchClause:
    1766                 :           0 :             loc = ((const CTESearchClause *) expr)->location;
    1767                 :           0 :             break;
    1768                 :           0 :         case T_CTECycleClause:
    1769                 :           0 :             loc = ((const CTECycleClause *) expr)->location;
    1770                 :           0 :             break;
    1771                 :           0 :         case T_CommonTableExpr:
    1772                 :           0 :             loc = ((const CommonTableExpr *) expr)->location;
    1773                 :           0 :             break;
    1774                 :           0 :         case T_JsonKeyValue:
    1775                 :             :             /* just use the key's location */
    1776                 :           0 :             loc = exprLocation((Node *) ((const JsonKeyValue *) expr)->key);
    1777                 :           0 :             break;
    1778                 :           0 :         case T_JsonObjectConstructor:
    1779                 :           0 :             loc = ((const JsonObjectConstructor *) expr)->location;
    1780                 :           0 :             break;
    1781                 :           0 :         case T_JsonArrayConstructor:
    1782                 :           0 :             loc = ((const JsonArrayConstructor *) expr)->location;
    1783                 :           0 :             break;
    1784                 :           0 :         case T_JsonArrayQueryConstructor:
    1785                 :           0 :             loc = ((const JsonArrayQueryConstructor *) expr)->location;
    1786                 :           0 :             break;
    1787                 :           0 :         case T_JsonAggConstructor:
    1788                 :           0 :             loc = ((const JsonAggConstructor *) expr)->location;
    1789                 :           0 :             break;
    1790                 :           0 :         case T_JsonObjectAgg:
    1791                 :           0 :             loc = exprLocation((Node *) ((const JsonObjectAgg *) expr)->constructor);
    1792                 :           0 :             break;
    1793                 :           0 :         case T_JsonArrayAgg:
    1794                 :           0 :             loc = exprLocation((Node *) ((const JsonArrayAgg *) expr)->constructor);
    1795                 :           0 :             break;
    1796                 :           0 :         case T_PlaceHolderVar:
    1797                 :             :             /* just use argument's location */
    1798                 :           0 :             loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
    1799                 :           0 :             break;
    1800                 :           0 :         case T_InferenceElem:
    1801                 :             :             /* just use nested expr's location */
    1802                 :           0 :             loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
    1803                 :           0 :             break;
    1804                 :           0 :         case T_PartitionElem:
    1805                 :           0 :             loc = ((const PartitionElem *) expr)->location;
    1806                 :           0 :             break;
    1807                 :           0 :         case T_PartitionSpec:
    1808                 :           0 :             loc = ((const PartitionSpec *) expr)->location;
    1809                 :           0 :             break;
    1810                 :          32 :         case T_PartitionBoundSpec:
    1811                 :          32 :             loc = ((const PartitionBoundSpec *) expr)->location;
    1812                 :          32 :             break;
    1813                 :          12 :         case T_PartitionRangeDatum:
    1814                 :          12 :             loc = ((const PartitionRangeDatum *) expr)->location;
    1815                 :          12 :             break;
    1816                 :       26008 :         default:
    1817                 :             :             /* for any other node type it's just unknown... */
    1818                 :       26008 :             loc = -1;
    1819                 :       26008 :             break;
    1820                 :             :     }
    1821                 :     2835586 :     return loc;
    1822                 :             : }
    1823                 :             : 
    1824                 :             : /*
    1825                 :             :  * leftmostLoc - support for exprLocation
    1826                 :             :  *
    1827                 :             :  * Take the minimum of two parse location values, but ignore unknowns
    1828                 :             :  */
    1829                 :             : static int
    1830                 :      167986 : leftmostLoc(int loc1, int loc2)
    1831                 :             : {
    1832         [ +  + ]:      167986 :     if (loc1 < 0)
    1833                 :       13743 :         return loc2;
    1834         [ +  + ]:      154243 :     else if (loc2 < 0)
    1835                 :       15849 :         return loc1;
    1836                 :             :     else
    1837                 :      138394 :         return Min(loc1, loc2);
    1838                 :             : }
    1839                 :             : 
    1840                 :             : 
    1841                 :             : /*
    1842                 :             :  * fix_opfuncids
    1843                 :             :  *    Calculate opfuncid field from opno for each OpExpr node in given tree.
    1844                 :             :  *    The given tree can be anything expression_tree_walker handles.
    1845                 :             :  *
    1846                 :             :  * The argument is modified in-place.  (This is OK since we'd want the
    1847                 :             :  * same change for any node, even if it gets visited more than once due to
    1848                 :             :  * shared structure.)
    1849                 :             :  */
    1850                 :             : void
    1851                 :      309732 : fix_opfuncids(Node *node)
    1852                 :             : {
    1853                 :             :     /* This tree walk requires no special setup, so away we go... */
    1854                 :      309732 :     fix_opfuncids_walker(node, NULL);
    1855                 :      309732 : }
    1856                 :             : 
    1857                 :             : static bool
    1858                 :      741515 : fix_opfuncids_walker(Node *node, void *context)
    1859                 :             : {
    1860         [ +  + ]:      741515 :     if (node == NULL)
    1861                 :       37679 :         return false;
    1862         [ +  + ]:      703836 :     if (IsA(node, OpExpr))
    1863                 :       45093 :         set_opfuncid((OpExpr *) node);
    1864         [ +  + ]:      658743 :     else if (IsA(node, DistinctExpr))
    1865                 :           4 :         set_opfuncid((OpExpr *) node);  /* rely on struct equivalence */
    1866         [ +  + ]:      658739 :     else if (IsA(node, NullIfExpr))
    1867                 :         671 :         set_opfuncid((OpExpr *) node);  /* rely on struct equivalence */
    1868         [ +  + ]:      658068 :     else if (IsA(node, ScalarArrayOpExpr))
    1869                 :        1644 :         set_sa_opfuncid((ScalarArrayOpExpr *) node);
    1870                 :      703836 :     return expression_tree_walker(node, fix_opfuncids_walker, context);
    1871                 :             : }
    1872                 :             : 
    1873                 :             : /*
    1874                 :             :  * set_opfuncid
    1875                 :             :  *      Set the opfuncid (procedure OID) in an OpExpr node,
    1876                 :             :  *      if it hasn't been set already.
    1877                 :             :  *
    1878                 :             :  * Because of struct equivalence, this can also be used for
    1879                 :             :  * DistinctExpr and NullIfExpr nodes.
    1880                 :             :  */
    1881                 :             : void
    1882                 :     3126464 : set_opfuncid(OpExpr *opexpr)
    1883                 :             : {
    1884         [ +  + ]:     3126464 :     if (opexpr->opfuncid == InvalidOid)
    1885                 :      186066 :         opexpr->opfuncid = get_opcode(opexpr->opno);
    1886                 :     3126464 : }
    1887                 :             : 
    1888                 :             : /*
    1889                 :             :  * set_sa_opfuncid
    1890                 :             :  *      As above, for ScalarArrayOpExpr nodes.
    1891                 :             :  */
    1892                 :             : void
    1893                 :      149481 : set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
    1894                 :             : {
    1895         [ +  + ]:      149481 :     if (opexpr->opfuncid == InvalidOid)
    1896                 :         380 :         opexpr->opfuncid = get_opcode(opexpr->opno);
    1897                 :      149481 : }
    1898                 :             : 
    1899                 :             : 
    1900                 :             : /*
    1901                 :             :  *  check_functions_in_node -
    1902                 :             :  *    apply checker() to each function OID contained in given expression node
    1903                 :             :  *
    1904                 :             :  * Returns true if the checker() function does; for nodes representing more
    1905                 :             :  * than one function call, returns true if the checker() function does so
    1906                 :             :  * for any of those functions.  Returns false if node does not invoke any
    1907                 :             :  * SQL-visible function.  Caller must not pass node == NULL.
    1908                 :             :  *
    1909                 :             :  * This function examines only the given node; it does not recurse into any
    1910                 :             :  * sub-expressions.  Callers typically prefer to keep control of the recursion
    1911                 :             :  * for themselves, in case additional checks should be made, or because they
    1912                 :             :  * have special rules about which parts of the tree need to be visited.
    1913                 :             :  *
    1914                 :             :  * Note: we ignore MinMaxExpr, SQLValueFunction, XmlExpr, CoerceToDomain,
    1915                 :             :  * and NextValueExpr nodes, because they do not contain SQL function OIDs.
    1916                 :             :  * However, they can invoke SQL-visible functions, so callers should take
    1917                 :             :  * thought about how to treat them.
    1918                 :             :  */
    1919                 :             : bool
    1920                 :    18000157 : check_functions_in_node(Node *node, check_function_callback checker,
    1921                 :             :                         void *context)
    1922                 :             : {
    1923   [ +  +  +  +  :    18000157 :     switch (nodeTag(node))
             +  +  +  + ]
    1924                 :             :     {
    1925                 :       95609 :         case T_Aggref:
    1926                 :             :             {
    1927                 :       95609 :                 Aggref     *expr = (Aggref *) node;
    1928                 :             : 
    1929         [ +  + ]:       95609 :                 if (checker(expr->aggfnoid, context))
    1930                 :         860 :                     return true;
    1931                 :             :             }
    1932                 :       94749 :             break;
    1933                 :        6850 :         case T_WindowFunc:
    1934                 :             :             {
    1935                 :        6850 :                 WindowFunc *expr = (WindowFunc *) node;
    1936                 :             : 
    1937         [ +  + ]:        6850 :                 if (checker(expr->winfnoid, context))
    1938                 :         135 :                     return true;
    1939                 :             :             }
    1940                 :        6715 :             break;
    1941                 :      535472 :         case T_FuncExpr:
    1942                 :             :             {
    1943                 :      535472 :                 FuncExpr   *expr = (FuncExpr *) node;
    1944                 :             : 
    1945         [ +  + ]:      535472 :                 if (checker(expr->funcid, context))
    1946                 :       77916 :                     return true;
    1947                 :             :             }
    1948                 :      457556 :             break;
    1949                 :     1244109 :         case T_OpExpr:
    1950                 :             :         case T_DistinctExpr:    /* struct-equivalent to OpExpr */
    1951                 :             :         case T_NullIfExpr:      /* struct-equivalent to OpExpr */
    1952                 :             :             {
    1953                 :     1244109 :                 OpExpr     *expr = (OpExpr *) node;
    1954                 :             : 
    1955                 :             :                 /* Set opfuncid if it wasn't set already */
    1956                 :     1244109 :                 set_opfuncid(expr);
    1957         [ +  + ]:     1244109 :                 if (checker(expr->opfuncid, context))
    1958                 :        1388 :                     return true;
    1959                 :             :             }
    1960                 :     1242721 :             break;
    1961                 :       50773 :         case T_ScalarArrayOpExpr:
    1962                 :             :             {
    1963                 :       50773 :                 ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
    1964                 :             : 
    1965                 :       50773 :                 set_sa_opfuncid(expr);
    1966         [ +  + ]:       50773 :                 if (checker(expr->opfuncid, context))
    1967                 :         167 :                     return true;
    1968                 :             :             }
    1969                 :       50606 :             break;
    1970                 :       40461 :         case T_CoerceViaIO:
    1971                 :             :             {
    1972                 :       40461 :                 CoerceViaIO *expr = (CoerceViaIO *) node;
    1973                 :             :                 Oid         iofunc;
    1974                 :             :                 Oid         typioparam;
    1975                 :             :                 bool        typisvarlena;
    1976                 :             : 
    1977                 :             :                 /* check the result type's input function */
    1978                 :       40461 :                 getTypeInputInfo(expr->resulttype,
    1979                 :             :                                  &iofunc, &typioparam);
    1980         [ +  + ]:       40461 :                 if (checker(iofunc, context))
    1981                 :         372 :                     return true;
    1982                 :             :                 /* check the input type's output function */
    1983                 :       40430 :                 getTypeOutputInfo(exprType((Node *) expr->arg),
    1984                 :             :                                   &iofunc, &typisvarlena);
    1985         [ +  + ]:       40430 :                 if (checker(iofunc, context))
    1986                 :         341 :                     return true;
    1987                 :             :             }
    1988                 :       40089 :             break;
    1989                 :         344 :         case T_RowCompareExpr:
    1990                 :             :             {
    1991                 :         344 :                 RowCompareExpr *rcexpr = (RowCompareExpr *) node;
    1992                 :             :                 ListCell   *opid;
    1993                 :             : 
    1994   [ +  -  +  +  :        1117 :                 foreach(opid, rcexpr->opnos)
                   +  + ]
    1995                 :             :                 {
    1996                 :         773 :                     Oid         opfuncid = get_opcode(lfirst_oid(opid));
    1997                 :             : 
    1998         [ -  + ]:         773 :                     if (checker(opfuncid, context))
    1999                 :           0 :                         return true;
    2000                 :             :                 }
    2001                 :             :             }
    2002                 :         344 :             break;
    2003                 :    16026539 :         default:
    2004                 :    16026539 :             break;
    2005                 :             :     }
    2006                 :    17919319 :     return false;
    2007                 :             : }
    2008                 :             : 
    2009                 :             : 
    2010                 :             : /*
    2011                 :             :  * Standard expression-tree walking support
    2012                 :             :  *
    2013                 :             :  * We used to have near-duplicate code in many different routines that
    2014                 :             :  * understood how to recurse through an expression node tree.  That was
    2015                 :             :  * a pain to maintain, and we frequently had bugs due to some particular
    2016                 :             :  * routine neglecting to support a particular node type.  In most cases,
    2017                 :             :  * these routines only actually care about certain node types, and don't
    2018                 :             :  * care about other types except insofar as they have to recurse through
    2019                 :             :  * non-primitive node types.  Therefore, we now provide generic tree-walking
    2020                 :             :  * logic to consolidate the redundant "boilerplate" code.  There are
    2021                 :             :  * two versions: expression_tree_walker() and expression_tree_mutator().
    2022                 :             :  */
    2023                 :             : 
    2024                 :             : /*
    2025                 :             :  * expression_tree_walker() is designed to support routines that traverse
    2026                 :             :  * a tree in a read-only fashion (although it will also work for routines
    2027                 :             :  * that modify nodes in-place but never add/delete/replace nodes).
    2028                 :             :  * A walker routine should look like this:
    2029                 :             :  *
    2030                 :             :  * bool my_walker (Node *node, my_struct *context)
    2031                 :             :  * {
    2032                 :             :  *      if (node == NULL)
    2033                 :             :  *          return false;
    2034                 :             :  *      // check for nodes that special work is required for, eg:
    2035                 :             :  *      if (IsA(node, Var))
    2036                 :             :  *      {
    2037                 :             :  *          ... do special actions for Var nodes
    2038                 :             :  *      }
    2039                 :             :  *      else if (IsA(node, ...))
    2040                 :             :  *      {
    2041                 :             :  *          ... do special actions for other node types
    2042                 :             :  *      }
    2043                 :             :  *      // for any node type not specially processed, do:
    2044                 :             :  *      return expression_tree_walker(node, my_walker, context);
    2045                 :             :  * }
    2046                 :             :  *
    2047                 :             :  * The "context" argument points to a struct that holds whatever context
    2048                 :             :  * information the walker routine needs --- it can be used to return data
    2049                 :             :  * gathered by the walker, too.  This argument is not touched by
    2050                 :             :  * expression_tree_walker, but it is passed down to recursive sub-invocations
    2051                 :             :  * of my_walker.  The tree walk is started from a setup routine that
    2052                 :             :  * fills in the appropriate context struct, calls my_walker with the top-level
    2053                 :             :  * node of the tree, and then examines the results.
    2054                 :             :  *
    2055                 :             :  * The walker routine should return "false" to continue the tree walk, or
    2056                 :             :  * "true" to abort the walk and immediately return "true" to the top-level
    2057                 :             :  * caller.  This can be used to short-circuit the traversal if the walker
    2058                 :             :  * has found what it came for.  "false" is returned to the top-level caller
    2059                 :             :  * iff no invocation of the walker returned "true".
    2060                 :             :  *
    2061                 :             :  * The node types handled by expression_tree_walker include all those
    2062                 :             :  * normally found in target lists and qualifier clauses during the planning
    2063                 :             :  * stage.  In particular, it handles List nodes since a cnf-ified qual clause
    2064                 :             :  * will have List structure at the top level, and it handles TargetEntry nodes
    2065                 :             :  * so that a scan of a target list can be handled without additional code.
    2066                 :             :  * Also, RangeTblRef, FromExpr, JoinExpr, and SetOperationStmt nodes are
    2067                 :             :  * handled, so that query jointrees and setOperation trees can be processed
    2068                 :             :  * without additional code.
    2069                 :             :  *
    2070                 :             :  * expression_tree_walker will handle SubLink nodes by recursing normally
    2071                 :             :  * into the "testexpr" subtree (which is an expression belonging to the outer
    2072                 :             :  * plan).  It will also call the walker on the sub-Query node; however, when
    2073                 :             :  * expression_tree_walker itself is called on a Query node, it does nothing
    2074                 :             :  * and returns "false".  The net effect is that unless the walker does
    2075                 :             :  * something special at a Query node, sub-selects will not be visited during
    2076                 :             :  * an expression tree walk. This is exactly the behavior wanted in many cases
    2077                 :             :  * --- and for those walkers that do want to recurse into sub-selects, special
    2078                 :             :  * behavior is typically needed anyway at the entry to a sub-select (such as
    2079                 :             :  * incrementing a depth counter). A walker that wants to examine sub-selects
    2080                 :             :  * should include code along the lines of:
    2081                 :             :  *
    2082                 :             :  *      if (IsA(node, Query))
    2083                 :             :  *      {
    2084                 :             :  *          adjust context for subquery;
    2085                 :             :  *          result = query_tree_walker((Query *) node, my_walker, context,
    2086                 :             :  *                                     0); // adjust flags as needed
    2087                 :             :  *          restore context if needed;
    2088                 :             :  *          return result;
    2089                 :             :  *      }
    2090                 :             :  *
    2091                 :             :  * query_tree_walker is a convenience routine (see below) that calls the
    2092                 :             :  * walker on all the expression subtrees of the given Query node.
    2093                 :             :  *
    2094                 :             :  * expression_tree_walker will handle SubPlan nodes by recursing normally
    2095                 :             :  * into the "testexpr" and the "args" list (which are expressions belonging to
    2096                 :             :  * the outer plan).  It will not touch the completed subplan, however.  Since
    2097                 :             :  * there is no link to the original Query, it is not possible to recurse into
    2098                 :             :  * subselects of an already-planned expression tree.  This is OK for current
    2099                 :             :  * uses, but may need to be revisited in future.
    2100                 :             :  */
    2101                 :             : 
    2102                 :             : pg_attribute_no_sanitize_function()
    2103                 :             : bool
    2104                 :    82521378 : expression_tree_walker_impl(Node *node,
    2105                 :             :                             tree_walker_callback walker,
    2106                 :             :                             void *context)
    2107                 :             : {
    2108                 :             :     ListCell   *temp;
    2109                 :             : 
    2110                 :             :     /*
    2111                 :             :      * The walker has already visited the current node, and so we need only
    2112                 :             :      * recurse into any sub-nodes it has.
    2113                 :             :      *
    2114                 :             :      * We assume that the walker is not interested in List nodes per se, so
    2115                 :             :      * when we expect a List we just recurse directly to self without
    2116                 :             :      * bothering to call the walker.
    2117                 :             :      */
    2118                 :             : #define WALK(n) walker((Node *) (n), context)
    2119                 :             : 
    2120                 :             : #define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)
    2121                 :             : 
    2122         [ +  + ]:    82521378 :     if (node == NULL)
    2123                 :     1658327 :         return false;
    2124                 :             : 
    2125                 :             :     /* Guard against stack overflow due to overly complex expressions */
    2126                 :    80863051 :     check_stack_depth();
    2127                 :             : 
    2128   [ +  +  +  +  :    80863047 :     switch (nodeTag(node))
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  -  -  
          -  -  -  -  -  
          +  +  +  +  +  
          +  +  +  +  +  
          -  +  +  +  +  
             -  +  +  +  
                      - ]
    2129                 :             :     {
    2130                 :    34108457 :         case T_Var:
    2131                 :             :         case T_Const:
    2132                 :             :         case T_Param:
    2133                 :             :         case T_CaseTestExpr:
    2134                 :             :         case T_SQLValueFunction:
    2135                 :             :         case T_CoerceToDomainValue:
    2136                 :             :         case T_SetToDefault:
    2137                 :             :         case T_CurrentOfExpr:
    2138                 :             :         case T_NextValueExpr:
    2139                 :             :         case T_RangeTblRef:
    2140                 :             :         case T_SortGroupClause:
    2141                 :             :         case T_CTESearchClause:
    2142                 :             :         case T_MergeSupportFunc:
    2143                 :             :             /* primitive node types with no expression subnodes */
    2144                 :    34108457 :             break;
    2145                 :        6691 :         case T_WithCheckOption:
    2146                 :        6691 :             return WALK(((WithCheckOption *) node)->qual);
    2147                 :      286503 :         case T_Aggref:
    2148                 :             :             {
    2149                 :      286503 :                 Aggref     *expr = (Aggref *) node;
    2150                 :             : 
    2151                 :             :                 /* recurse directly on Lists */
    2152         [ -  + ]:      286503 :                 if (LIST_WALK(expr->aggdirectargs))
    2153                 :           0 :                     return true;
    2154         [ +  + ]:      286503 :                 if (LIST_WALK(expr->args))
    2155                 :       14493 :                     return true;
    2156         [ -  + ]:      272010 :                 if (LIST_WALK(expr->aggorder))
    2157                 :           0 :                     return true;
    2158         [ -  + ]:      272010 :                 if (LIST_WALK(expr->aggdistinct))
    2159                 :           0 :                     return true;
    2160         [ +  + ]:      272010 :                 if (WALK(expr->aggfilter))
    2161                 :          71 :                     return true;
    2162                 :             :             }
    2163                 :      271939 :             break;
    2164                 :        3219 :         case T_GroupingFunc:
    2165                 :             :             {
    2166                 :        3219 :                 GroupingFunc *grouping = (GroupingFunc *) node;
    2167                 :             : 
    2168         [ +  + ]:        3219 :                 if (LIST_WALK(grouping->args))
    2169                 :         190 :                     return true;
    2170                 :             :             }
    2171                 :        3029 :             break;
    2172                 :       16921 :         case T_WindowFunc:
    2173                 :             :             {
    2174                 :       16921 :                 WindowFunc *expr = (WindowFunc *) node;
    2175                 :             : 
    2176                 :             :                 /* recurse directly on List */
    2177         [ +  + ]:       16921 :                 if (LIST_WALK(expr->args))
    2178                 :         490 :                     return true;
    2179         [ +  + ]:       16431 :                 if (WALK(expr->aggfilter))
    2180                 :           9 :                     return true;
    2181         [ -  + ]:       16422 :                 if (WALK(expr->runCondition))
    2182                 :           0 :                     return true;
    2183                 :             :             }
    2184                 :       16422 :             break;
    2185                 :         549 :         case T_WindowFuncRunCondition:
    2186                 :             :             {
    2187                 :         549 :                 WindowFuncRunCondition *expr = (WindowFuncRunCondition *) node;
    2188                 :             : 
    2189         [ -  + ]:         549 :                 if (WALK(expr->arg))
    2190                 :           0 :                     return true;
    2191                 :             :             }
    2192                 :         549 :             break;
    2193                 :      221955 :         case T_SubscriptingRef:
    2194                 :             :             {
    2195                 :      221955 :                 SubscriptingRef *sbsref = (SubscriptingRef *) node;
    2196                 :             : 
    2197                 :             :                 /* recurse directly for upper/lower container index lists */
    2198         [ +  + ]:      221955 :                 if (LIST_WALK(sbsref->refupperindexpr))
    2199                 :        9655 :                     return true;
    2200         [ -  + ]:      212300 :                 if (LIST_WALK(sbsref->reflowerindexpr))
    2201                 :           0 :                     return true;
    2202                 :             :                 /* walker must see the refexpr and refassgnexpr, however */
    2203         [ +  + ]:      212300 :                 if (WALK(sbsref->refexpr))
    2204                 :       11856 :                     return true;
    2205                 :             : 
    2206         [ +  + ]:      200444 :                 if (WALK(sbsref->refassgnexpr))
    2207                 :         126 :                     return true;
    2208                 :             :             }
    2209                 :      200318 :             break;
    2210                 :     2713690 :         case T_FuncExpr:
    2211                 :             :             {
    2212                 :     2713690 :                 FuncExpr   *expr = (FuncExpr *) node;
    2213                 :             : 
    2214         [ +  + ]:     2713690 :                 if (LIST_WALK(expr->args))
    2215                 :       57726 :                     return true;
    2216                 :             :             }
    2217                 :     2655956 :             break;
    2218                 :       53314 :         case T_NamedArgExpr:
    2219                 :       53314 :             return WALK(((NamedArgExpr *) node)->arg);
    2220                 :     6524786 :         case T_OpExpr:
    2221                 :             :         case T_DistinctExpr:    /* struct-equivalent to OpExpr */
    2222                 :             :         case T_NullIfExpr:      /* struct-equivalent to OpExpr */
    2223                 :             :             {
    2224                 :     6524786 :                 OpExpr     *expr = (OpExpr *) node;
    2225                 :             : 
    2226         [ +  + ]:     6524786 :                 if (LIST_WALK(expr->args))
    2227                 :       64237 :                     return true;
    2228                 :             :             }
    2229                 :     6460465 :             break;
    2230                 :      356479 :         case T_ScalarArrayOpExpr:
    2231                 :             :             {
    2232                 :      356479 :                 ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
    2233                 :             : 
    2234         [ +  + ]:      356479 :                 if (LIST_WALK(expr->args))
    2235                 :       32650 :                     return true;
    2236                 :             :             }
    2237                 :      323829 :             break;
    2238                 :      964698 :         case T_BoolExpr:
    2239                 :             :             {
    2240                 :      964698 :                 BoolExpr   *expr = (BoolExpr *) node;
    2241                 :             : 
    2242         [ +  + ]:      964698 :                 if (LIST_WALK(expr->args))
    2243                 :       13176 :                     return true;
    2244                 :             :             }
    2245                 :      951518 :             break;
    2246                 :      208735 :         case T_SubLink:
    2247                 :             :             {
    2248                 :      208735 :                 SubLink    *sublink = (SubLink *) node;
    2249                 :             : 
    2250         [ +  + ]:      208735 :                 if (WALK(sublink->testexpr))
    2251                 :          56 :                     return true;
    2252                 :             : 
    2253                 :             :                 /*
    2254                 :             :                  * Also invoke the walker on the sublink's Query node, so it
    2255                 :             :                  * can recurse into the sub-query if it wants to.
    2256                 :             :                  */
    2257                 :      208679 :                 return WALK(sublink->subselect);
    2258                 :             :             }
    2259                 :             :             break;
    2260                 :       88188 :         case T_SubPlan:
    2261                 :             :             {
    2262                 :       88188 :                 SubPlan    *subplan = (SubPlan *) node;
    2263                 :             : 
    2264                 :             :                 /* recurse into the testexpr, but not into the Plan */
    2265         [ +  + ]:       88188 :                 if (WALK(subplan->testexpr))
    2266                 :          58 :                     return true;
    2267                 :             :                 /* also examine args list */
    2268         [ +  + ]:       88130 :                 if (LIST_WALK(subplan->args))
    2269                 :         350 :                     return true;
    2270                 :             :             }
    2271                 :       87780 :             break;
    2272                 :        5768 :         case T_AlternativeSubPlan:
    2273                 :        5768 :             return LIST_WALK(((AlternativeSubPlan *) node)->subplans);
    2274                 :      380551 :         case T_FieldSelect:
    2275                 :      380551 :             return WALK(((FieldSelect *) node)->arg);
    2276                 :        2411 :         case T_FieldStore:
    2277                 :             :             {
    2278                 :        2411 :                 FieldStore *fstore = (FieldStore *) node;
    2279                 :             : 
    2280         [ -  + ]:        2411 :                 if (WALK(fstore->arg))
    2281                 :           0 :                     return true;
    2282         [ +  + ]:        2411 :                 if (WALK(fstore->newvals))
    2283                 :           8 :                     return true;
    2284                 :             :             }
    2285                 :        2403 :             break;
    2286                 :      970157 :         case T_RelabelType:
    2287                 :      970157 :             return WALK(((RelabelType *) node)->arg);
    2288                 :      220328 :         case T_CoerceViaIO:
    2289                 :      220328 :             return WALK(((CoerceViaIO *) node)->arg);
    2290                 :       38392 :         case T_ArrayCoerceExpr:
    2291                 :             :             {
    2292                 :       38392 :                 ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
    2293                 :             : 
    2294         [ +  + ]:       38392 :                 if (WALK(acoerce->arg))
    2295                 :        3295 :                     return true;
    2296         [ +  + ]:       35097 :                 if (WALK(acoerce->elemexpr))
    2297                 :          31 :                     return true;
    2298                 :             :             }
    2299                 :       35066 :             break;
    2300                 :        2309 :         case T_ConvertRowtypeExpr:
    2301                 :        2309 :             return WALK(((ConvertRowtypeExpr *) node)->arg);
    2302                 :       25363 :         case T_CollateExpr:
    2303                 :       25363 :             return WALK(((CollateExpr *) node)->arg);
    2304                 :      381120 :         case T_CaseExpr:
    2305                 :             :             {
    2306                 :      381120 :                 CaseExpr   *caseexpr = (CaseExpr *) node;
    2307                 :             : 
    2308         [ +  + ]:      381120 :                 if (WALK(caseexpr->arg))
    2309                 :         253 :                     return true;
    2310                 :             :                 /* we assume walker doesn't care about CaseWhens, either */
    2311   [ +  -  +  +  :     1162227 :                 foreach(temp, caseexpr->args)
                   +  + ]
    2312                 :             :                 {
    2313                 :      788581 :                     CaseWhen   *when = lfirst_node(CaseWhen, temp);
    2314                 :             : 
    2315         [ +  + ]:      788581 :                     if (WALK(when->expr))
    2316                 :        7221 :                         return true;
    2317         [ +  + ]:      786589 :                     if (WALK(when->result))
    2318                 :        5229 :                         return true;
    2319                 :             :                 }
    2320         [ +  + ]:      373646 :                 if (WALK(caseexpr->defresult))
    2321                 :        6883 :                     return true;
    2322                 :             :             }
    2323                 :      366763 :             break;
    2324                 :      161822 :         case T_ArrayExpr:
    2325                 :      161822 :             return WALK(((ArrayExpr *) node)->elements);
    2326                 :       28989 :         case T_RowExpr:
    2327                 :             :             /* Assume colnames isn't interesting */
    2328                 :       28989 :             return WALK(((RowExpr *) node)->args);
    2329                 :        2647 :         case T_RowCompareExpr:
    2330                 :             :             {
    2331                 :        2647 :                 RowCompareExpr *rcexpr = (RowCompareExpr *) node;
    2332                 :             : 
    2333         [ -  + ]:        2647 :                 if (WALK(rcexpr->largs))
    2334                 :           0 :                     return true;
    2335         [ -  + ]:        2647 :                 if (WALK(rcexpr->rargs))
    2336                 :           0 :                     return true;
    2337                 :             :             }
    2338                 :        2647 :             break;
    2339                 :       47711 :         case T_CoalesceExpr:
    2340                 :       47711 :             return WALK(((CoalesceExpr *) node)->args);
    2341                 :        4473 :         case T_MinMaxExpr:
    2342                 :        4473 :             return WALK(((MinMaxExpr *) node)->args);
    2343                 :        3667 :         case T_XmlExpr:
    2344                 :             :             {
    2345                 :        3667 :                 XmlExpr    *xexpr = (XmlExpr *) node;
    2346                 :             : 
    2347         [ +  + ]:        3667 :                 if (WALK(xexpr->named_args))
    2348                 :           8 :                     return true;
    2349                 :             :                 /* we assume walker doesn't care about arg_names */
    2350         [ +  + ]:        3659 :                 if (WALK(xexpr->args))
    2351                 :          31 :                     return true;
    2352                 :             :             }
    2353                 :        3628 :             break;
    2354                 :        4278 :         case T_JsonValueExpr:
    2355                 :             :             {
    2356                 :        4278 :                 JsonValueExpr *jve = (JsonValueExpr *) node;
    2357                 :             : 
    2358         [ +  + ]:        4278 :                 if (WALK(jve->raw_expr))
    2359                 :          40 :                     return true;
    2360         [ -  + ]:        4238 :                 if (WALK(jve->formatted_expr))
    2361                 :           0 :                     return true;
    2362                 :             :             }
    2363                 :        4238 :             break;
    2364                 :        9944 :         case T_JsonConstructorExpr:
    2365                 :             :             {
    2366                 :        9944 :                 JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
    2367                 :             : 
    2368         [ +  + ]:        9944 :                 if (WALK(ctor->args))
    2369                 :          58 :                     return true;
    2370         [ +  + ]:        9886 :                 if (WALK(ctor->func))
    2371                 :          90 :                     return true;
    2372         [ +  + ]:        9796 :                 if (WALK(ctor->coercion))
    2373                 :          10 :                     return true;
    2374                 :             :             }
    2375                 :        9786 :             break;
    2376                 :        2201 :         case T_JsonIsPredicate:
    2377                 :        2201 :             return WALK(((JsonIsPredicate *) node)->expr);
    2378                 :       17939 :         case T_JsonExpr:
    2379                 :             :             {
    2380                 :       17939 :                 JsonExpr   *jexpr = (JsonExpr *) node;
    2381                 :             : 
    2382         [ +  + ]:       17939 :                 if (WALK(jexpr->formatted_expr))
    2383                 :          92 :                     return true;
    2384         [ +  + ]:       17847 :                 if (WALK(jexpr->path_spec))
    2385                 :           4 :                     return true;
    2386         [ +  + ]:       17843 :                 if (WALK(jexpr->passing_values))
    2387                 :           8 :                     return true;
    2388                 :             :                 /* we assume walker doesn't care about passing_names */
    2389         [ +  + ]:       17835 :                 if (WALK(jexpr->on_empty))
    2390                 :          30 :                     return true;
    2391         [ +  + ]:       17805 :                 if (WALK(jexpr->on_error))
    2392                 :          24 :                     return true;
    2393                 :             :             }
    2394                 :       17781 :             break;
    2395                 :       31664 :         case T_JsonBehavior:
    2396                 :             :             {
    2397                 :       31664 :                 JsonBehavior *behavior = (JsonBehavior *) node;
    2398                 :             : 
    2399         [ +  + ]:       31664 :                 if (WALK(behavior->expr))
    2400                 :          54 :                     return true;
    2401                 :             :             }
    2402                 :       31610 :             break;
    2403                 :      202187 :         case T_NullTest:
    2404                 :      202187 :             return WALK(((NullTest *) node)->arg);
    2405                 :       10449 :         case T_BooleanTest:
    2406                 :       10449 :             return WALK(((BooleanTest *) node)->arg);
    2407                 :      288061 :         case T_CoerceToDomain:
    2408                 :      288061 :             return WALK(((CoerceToDomain *) node)->arg);
    2409                 :    12784516 :         case T_TargetEntry:
    2410                 :    12784516 :             return WALK(((TargetEntry *) node)->expr);
    2411                 :      104593 :         case T_Query:
    2412                 :             :             /* Do nothing with a sub-Query, per discussion above */
    2413                 :      104593 :             break;
    2414                 :         267 :         case T_WindowClause:
    2415                 :             :             {
    2416                 :         267 :                 WindowClause *wc = (WindowClause *) node;
    2417                 :             : 
    2418         [ -  + ]:         267 :                 if (WALK(wc->partitionClause))
    2419                 :           0 :                     return true;
    2420         [ -  + ]:         267 :                 if (WALK(wc->orderClause))
    2421                 :           0 :                     return true;
    2422         [ -  + ]:         267 :                 if (WALK(wc->startOffset))
    2423                 :           0 :                     return true;
    2424         [ -  + ]:         267 :                 if (WALK(wc->endOffset))
    2425                 :           0 :                     return true;
    2426                 :             :             }
    2427                 :         267 :             break;
    2428                 :          76 :         case T_CTECycleClause:
    2429                 :             :             {
    2430                 :          76 :                 CTECycleClause *cc = (CTECycleClause *) node;
    2431                 :             : 
    2432         [ -  + ]:          76 :                 if (WALK(cc->cycle_mark_value))
    2433                 :           0 :                     return true;
    2434         [ -  + ]:          76 :                 if (WALK(cc->cycle_mark_default))
    2435                 :           0 :                     return true;
    2436                 :             :             }
    2437                 :          76 :             break;
    2438                 :        6483 :         case T_CommonTableExpr:
    2439                 :             :             {
    2440                 :        6483 :                 CommonTableExpr *cte = (CommonTableExpr *) node;
    2441                 :             : 
    2442                 :             :                 /*
    2443                 :             :                  * Invoke the walker on the CTE's Query node, so it can
    2444                 :             :                  * recurse into the sub-query if it wants to.
    2445                 :             :                  */
    2446         [ +  + ]:        6483 :                 if (WALK(cte->ctequery))
    2447                 :         166 :                     return true;
    2448                 :             : 
    2449         [ -  + ]:        6317 :                 if (WALK(cte->search_clause))
    2450                 :           0 :                     return true;
    2451         [ -  + ]:        6317 :                 if (WALK(cte->cycle_clause))
    2452                 :           0 :                     return true;
    2453                 :             :             }
    2454                 :        6317 :             break;
    2455                 :           0 :         case T_JsonKeyValue:
    2456                 :             :             {
    2457                 :           0 :                 JsonKeyValue *kv = (JsonKeyValue *) node;
    2458                 :             : 
    2459         [ #  # ]:           0 :                 if (WALK(kv->key))
    2460                 :           0 :                     return true;
    2461         [ #  # ]:           0 :                 if (WALK(kv->value))
    2462                 :           0 :                     return true;
    2463                 :             :             }
    2464                 :           0 :             break;
    2465                 :           0 :         case T_JsonObjectConstructor:
    2466                 :             :             {
    2467                 :           0 :                 JsonObjectConstructor *ctor = (JsonObjectConstructor *) node;
    2468                 :             : 
    2469         [ #  # ]:           0 :                 if (LIST_WALK(ctor->exprs))
    2470                 :           0 :                     return true;
    2471                 :             :             }
    2472                 :           0 :             break;
    2473                 :           0 :         case T_JsonArrayConstructor:
    2474                 :             :             {
    2475                 :           0 :                 JsonArrayConstructor *ctor = (JsonArrayConstructor *) node;
    2476                 :             : 
    2477         [ #  # ]:           0 :                 if (LIST_WALK(ctor->exprs))
    2478                 :           0 :                     return true;
    2479                 :             :             }
    2480                 :           0 :             break;
    2481                 :           0 :         case T_JsonArrayQueryConstructor:
    2482                 :             :             {
    2483                 :           0 :                 JsonArrayQueryConstructor *ctor = (JsonArrayQueryConstructor *) node;
    2484                 :             : 
    2485         [ #  # ]:           0 :                 if (WALK(ctor->query))
    2486                 :           0 :                     return true;
    2487                 :             :             }
    2488                 :           0 :             break;
    2489                 :           0 :         case T_JsonAggConstructor:
    2490                 :             :             {
    2491                 :           0 :                 JsonAggConstructor *ctor = (JsonAggConstructor *) node;
    2492                 :             : 
    2493         [ #  # ]:           0 :                 if (WALK(ctor->agg_filter))
    2494                 :           0 :                     return true;
    2495         [ #  # ]:           0 :                 if (WALK(ctor->agg_order))
    2496                 :           0 :                     return true;
    2497         [ #  # ]:           0 :                 if (WALK(ctor->over))
    2498                 :           0 :                     return true;
    2499                 :             :             }
    2500                 :           0 :             break;
    2501                 :           0 :         case T_JsonObjectAgg:
    2502                 :             :             {
    2503                 :           0 :                 JsonObjectAgg *ctor = (JsonObjectAgg *) node;
    2504                 :             : 
    2505         [ #  # ]:           0 :                 if (WALK(ctor->constructor))
    2506                 :           0 :                     return true;
    2507         [ #  # ]:           0 :                 if (WALK(ctor->arg))
    2508                 :           0 :                     return true;
    2509                 :             :             }
    2510                 :           0 :             break;
    2511                 :           0 :         case T_JsonArrayAgg:
    2512                 :             :             {
    2513                 :           0 :                 JsonArrayAgg *ctor = (JsonArrayAgg *) node;
    2514                 :             : 
    2515         [ #  # ]:           0 :                 if (WALK(ctor->constructor))
    2516                 :           0 :                     return true;
    2517         [ #  # ]:           0 :                 if (WALK(ctor->arg))
    2518                 :           0 :                     return true;
    2519                 :             :             }
    2520                 :           0 :             break;
    2521                 :             : 
    2522                 :        2417 :         case T_PartitionBoundSpec:
    2523                 :             :             {
    2524                 :        2417 :                 PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
    2525                 :             : 
    2526         [ -  + ]:        2417 :                 if (WALK(pbs->listdatums))
    2527                 :           0 :                     return true;
    2528         [ -  + ]:        2417 :                 if (WALK(pbs->lowerdatums))
    2529                 :           0 :                     return true;
    2530         [ -  + ]:        2417 :                 if (WALK(pbs->upperdatums))
    2531                 :           0 :                     return true;
    2532                 :             :             }
    2533                 :        2417 :             break;
    2534                 :        3164 :         case T_PartitionRangeDatum:
    2535                 :             :             {
    2536                 :        3164 :                 PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
    2537                 :             : 
    2538         [ -  + ]:        3164 :                 if (WALK(prd->value))
    2539                 :           0 :                     return true;
    2540                 :             :             }
    2541                 :        3164 :             break;
    2542                 :    18020935 :         case T_List:
    2543   [ +  -  +  +  :    61666298 :             foreach(temp, (List *) node)
                   +  + ]
    2544                 :             :             {
    2545         [ +  + ]:    44239830 :                 if (WALK(lfirst(temp)))
    2546                 :      594311 :                     return true;
    2547                 :             :             }
    2548                 :    17426468 :             break;
    2549                 :     1070149 :         case T_FromExpr:
    2550                 :             :             {
    2551                 :     1070149 :                 FromExpr   *from = (FromExpr *) node;
    2552                 :             : 
    2553         [ +  + ]:     1070149 :                 if (LIST_WALK(from->fromlist))
    2554                 :       48411 :                     return true;
    2555         [ +  + ]:     1021738 :                 if (WALK(from->quals))
    2556                 :        2299 :                     return true;
    2557                 :             :             }
    2558                 :     1019431 :             break;
    2559                 :        2559 :         case T_OnConflictExpr:
    2560                 :             :             {
    2561                 :        2559 :                 OnConflictExpr *onconflict = (OnConflictExpr *) node;
    2562                 :             : 
    2563         [ -  + ]:        2559 :                 if (WALK(onconflict->arbiterElems))
    2564                 :           0 :                     return true;
    2565         [ -  + ]:        2559 :                 if (WALK(onconflict->arbiterWhere))
    2566                 :           0 :                     return true;
    2567         [ -  + ]:        2559 :                 if (WALK(onconflict->onConflictSet))
    2568                 :           0 :                     return true;
    2569         [ -  + ]:        2559 :                 if (WALK(onconflict->onConflictWhere))
    2570                 :           0 :                     return true;
    2571         [ -  + ]:        2559 :                 if (WALK(onconflict->exclRelTlist))
    2572                 :           0 :                     return true;
    2573                 :             :             }
    2574                 :        2559 :             break;
    2575                 :        4660 :         case T_MergeAction:
    2576                 :             :             {
    2577                 :        4660 :                 MergeAction *action = (MergeAction *) node;
    2578                 :             : 
    2579         [ +  + ]:        4660 :                 if (WALK(action->qual))
    2580                 :          93 :                     return true;
    2581         [ +  + ]:        4567 :                 if (WALK(action->targetList))
    2582                 :         233 :                     return true;
    2583                 :             :             }
    2584                 :        4334 :             break;
    2585                 :         635 :         case T_PartitionPruneStepOp:
    2586                 :             :             {
    2587                 :         635 :                 PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
    2588                 :             : 
    2589         [ -  + ]:         635 :                 if (WALK(opstep->exprs))
    2590                 :           0 :                     return true;
    2591                 :             :             }
    2592                 :         635 :             break;
    2593                 :         119 :         case T_PartitionPruneStepCombine:
    2594                 :             :             /* no expression subnodes */
    2595                 :         119 :             break;
    2596                 :      249354 :         case T_JoinExpr:
    2597                 :             :             {
    2598                 :      249354 :                 JoinExpr   *join = (JoinExpr *) node;
    2599                 :             : 
    2600         [ +  + ]:      249354 :                 if (WALK(join->larg))
    2601                 :       11556 :                     return true;
    2602         [ +  + ]:      237798 :                 if (WALK(join->rarg))
    2603                 :       15572 :                     return true;
    2604         [ +  + ]:      222226 :                 if (WALK(join->quals))
    2605                 :          48 :                     return true;
    2606                 :             : 
    2607                 :             :                 /*
    2608                 :             :                  * alias clause, using list are deemed uninteresting.
    2609                 :             :                  */
    2610                 :             :             }
    2611                 :      222178 :             break;
    2612                 :       28787 :         case T_SetOperationStmt:
    2613                 :             :             {
    2614                 :       28787 :                 SetOperationStmt *setop = (SetOperationStmt *) node;
    2615                 :             : 
    2616         [ -  + ]:       28787 :                 if (WALK(setop->larg))
    2617                 :           0 :                     return true;
    2618         [ -  + ]:       28787 :                 if (WALK(setop->rarg))
    2619                 :           0 :                     return true;
    2620                 :             : 
    2621                 :             :                 /* groupClauses are deemed uninteresting */
    2622                 :             :             }
    2623                 :       28787 :             break;
    2624                 :           0 :         case T_IndexClause:
    2625                 :             :             {
    2626                 :           0 :                 IndexClause *iclause = (IndexClause *) node;
    2627                 :             : 
    2628         [ #  # ]:           0 :                 if (WALK(iclause->rinfo))
    2629                 :           0 :                     return true;
    2630         [ #  # ]:           0 :                 if (LIST_WALK(iclause->indexquals))
    2631                 :           0 :                     return true;
    2632                 :             :             }
    2633                 :           0 :             break;
    2634                 :       30568 :         case T_PlaceHolderVar:
    2635                 :       30568 :             return WALK(((PlaceHolderVar *) node)->phexpr);
    2636                 :        2525 :         case T_InferenceElem:
    2637                 :        2525 :             return WALK(((InferenceElem *) node)->expr);
    2638                 :        2946 :         case T_ReturningExpr:
    2639                 :        2946 :             return WALK(((ReturningExpr *) node)->retexpr);
    2640                 :        1618 :         case T_AppendRelInfo:
    2641                 :             :             {
    2642                 :        1618 :                 AppendRelInfo *appinfo = (AppendRelInfo *) node;
    2643                 :             : 
    2644         [ -  + ]:        1618 :                 if (LIST_WALK(appinfo->translated_vars))
    2645                 :           0 :                     return true;
    2646                 :             :             }
    2647                 :        1618 :             break;
    2648                 :           0 :         case T_PlaceHolderInfo:
    2649                 :           0 :             return WALK(((PlaceHolderInfo *) node)->ph_var);
    2650                 :      146215 :         case T_RangeTblFunction:
    2651                 :      146215 :             return WALK(((RangeTblFunction *) node)->funcexpr);
    2652                 :         748 :         case T_TableSampleClause:
    2653                 :             :             {
    2654                 :         748 :                 TableSampleClause *tsc = (TableSampleClause *) node;
    2655                 :             : 
    2656         [ +  + ]:         748 :                 if (LIST_WALK(tsc->args))
    2657                 :          10 :                     return true;
    2658         [ -  + ]:         738 :                 if (WALK(tsc->repeatable))
    2659                 :           0 :                     return true;
    2660                 :             :             }
    2661                 :         738 :             break;
    2662                 :        3097 :         case T_TableFunc:
    2663                 :             :             {
    2664                 :        3097 :                 TableFunc  *tf = (TableFunc *) node;
    2665                 :             : 
    2666         [ -  + ]:        3097 :                 if (WALK(tf->ns_uris))
    2667                 :           0 :                     return true;
    2668         [ +  + ]:        3097 :                 if (WALK(tf->docexpr))
    2669                 :          96 :                     return true;
    2670         [ -  + ]:        3001 :                 if (WALK(tf->rowexpr))
    2671                 :           0 :                     return true;
    2672         [ -  + ]:        3001 :                 if (WALK(tf->colexprs))
    2673                 :           0 :                     return true;
    2674         [ -  + ]:        3001 :                 if (WALK(tf->coldefexprs))
    2675                 :           0 :                     return true;
    2676         [ -  + ]:        3001 :                 if (WALK(tf->colvalexprs))
    2677                 :           0 :                     return true;
    2678         [ -  + ]:        3001 :                 if (WALK(tf->passingvalexprs))
    2679                 :           0 :                     return true;
    2680                 :             :             }
    2681                 :        3001 :             break;
    2682                 :           0 :         default:
    2683         [ #  # ]:           0 :             elog(ERROR, "unrecognized node type: %d",
    2684                 :             :                  (int) nodeTag(node));
    2685                 :             :             break;
    2686                 :             :     }
    2687                 :    64380886 :     return false;
    2688                 :             : 
    2689                 :             :     /* The WALK() macro can be re-used below, but LIST_WALK() not so much */
    2690                 :             : #undef LIST_WALK
    2691                 :             : }
    2692                 :             : 
    2693                 :             : /*
    2694                 :             :  * query_tree_walker --- initiate a walk of a Query's expressions
    2695                 :             :  *
    2696                 :             :  * This routine exists just to reduce the number of places that need to know
    2697                 :             :  * where all the expression subtrees of a Query are.  Note it can be used
    2698                 :             :  * for starting a walk at top level of a Query regardless of whether the
    2699                 :             :  * walker intends to descend into subqueries.  It is also useful for
    2700                 :             :  * descending into subqueries within a walker.
    2701                 :             :  *
    2702                 :             :  * Some callers want to suppress visitation of certain items in the sub-Query,
    2703                 :             :  * typically because they need to process them specially, or don't actually
    2704                 :             :  * want to recurse into subqueries.  This is supported by the flags argument,
    2705                 :             :  * which is the bitwise OR of flag values to add or suppress visitation of
    2706                 :             :  * indicated items.  (More flag bits may be added as needed.)
    2707                 :             :  */
    2708                 :             : pg_attribute_no_sanitize_function()
    2709                 :             : bool
    2710                 :     1291287 : query_tree_walker_impl(Query *query,
    2711                 :             :                        tree_walker_callback walker,
    2712                 :             :                        void *context,
    2713                 :             :                        int flags)
    2714                 :             : {
    2715                 :             :     Assert(query != NULL && IsA(query, Query));
    2716                 :             : 
    2717                 :             :     /*
    2718                 :             :      * We don't walk any utilityStmt here. However, we can't easily assert
    2719                 :             :      * that it is absent, since there are at least two code paths by which
    2720                 :             :      * action statements from CREATE RULE end up here, and NOTIFY is allowed
    2721                 :             :      * in a rule action.
    2722                 :             :      */
    2723                 :             : 
    2724         [ +  + ]:     1291287 :     if (WALK(query->targetList))
    2725                 :      223195 :         return true;
    2726         [ -  + ]:     1068072 :     if (WALK(query->withCheckOptions))
    2727                 :           0 :         return true;
    2728         [ -  + ]:     1068072 :     if (WALK(query->onConflict))
    2729                 :           0 :         return true;
    2730         [ +  + ]:     1068072 :     if (WALK(query->mergeActionList))
    2731                 :         326 :         return true;
    2732         [ +  + ]:     1067746 :     if (WALK(query->mergeJoinCondition))
    2733                 :         227 :         return true;
    2734         [ +  + ]:     1067519 :     if (WALK(query->returningList))
    2735                 :          57 :         return true;
    2736         [ +  + ]:     1067462 :     if (WALK(query->jointree))
    2737                 :       50386 :         return true;
    2738         [ -  + ]:     1017068 :     if (WALK(query->setOperations))
    2739                 :           0 :         return true;
    2740         [ -  + ]:     1017068 :     if (WALK(query->havingQual))
    2741                 :           0 :         return true;
    2742         [ +  + ]:     1017068 :     if (WALK(query->limitOffset))
    2743                 :           4 :         return true;
    2744         [ -  + ]:     1017064 :     if (WALK(query->limitCount))
    2745                 :           0 :         return true;
    2746                 :             : 
    2747                 :             :     /*
    2748                 :             :      * Most callers aren't interested in SortGroupClause nodes since those
    2749                 :             :      * don't contain actual expressions. However they do contain OIDs which
    2750                 :             :      * may be needed by dependency walkers etc.
    2751                 :             :      */
    2752         [ +  + ]:     1017064 :     if ((flags & QTW_EXAMINE_SORTGROUP))
    2753                 :             :     {
    2754         [ -  + ]:       64693 :         if (WALK(query->groupClause))
    2755                 :           0 :             return true;
    2756         [ -  + ]:       64693 :         if (WALK(query->windowClause))
    2757                 :           0 :             return true;
    2758         [ -  + ]:       64693 :         if (WALK(query->sortClause))
    2759                 :           0 :             return true;
    2760         [ -  + ]:       64693 :         if (WALK(query->distinctClause))
    2761                 :           0 :             return true;
    2762                 :             :     }
    2763                 :             :     else
    2764                 :             :     {
    2765                 :             :         /*
    2766                 :             :          * But we need to walk the expressions under WindowClause nodes even
    2767                 :             :          * if we're not interested in SortGroupClause nodes.
    2768                 :             :          */
    2769                 :             :         ListCell   *lc;
    2770                 :             : 
    2771   [ +  +  +  +  :      957318 :         foreach(lc, query->windowClause)
                   +  + ]
    2772                 :             :         {
    2773                 :        4952 :             WindowClause *wc = lfirst_node(WindowClause, lc);
    2774                 :             : 
    2775         [ +  + ]:        4952 :             if (WALK(wc->startOffset))
    2776                 :           5 :                 return true;
    2777         [ -  + ]:        4947 :             if (WALK(wc->endOffset))
    2778                 :           0 :                 return true;
    2779                 :             :         }
    2780                 :             :     }
    2781                 :             : 
    2782                 :             :     /*
    2783                 :             :      * groupingSets and rowMarks are not walked:
    2784                 :             :      *
    2785                 :             :      * groupingSets contain only ressortgrouprefs (integers) which are
    2786                 :             :      * meaningless without the corresponding groupClause or tlist.
    2787                 :             :      * Accordingly, any walker that needs to care about them needs to handle
    2788                 :             :      * them itself in its Query processing.
    2789                 :             :      *
    2790                 :             :      * rowMarks is not walked because it contains only rangetable indexes (and
    2791                 :             :      * flags etc.) and therefore should be handled at Query level similarly.
    2792                 :             :      */
    2793                 :             : 
    2794         [ +  + ]:     1017059 :     if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
    2795                 :             :     {
    2796         [ +  + ]:      608407 :         if (WALK(query->cteList))
    2797                 :         162 :             return true;
    2798                 :             :     }
    2799         [ +  + ]:     1016897 :     if (!(flags & QTW_IGNORE_RANGE_TABLE))
    2800                 :             :     {
    2801         [ +  + ]:      641657 :         if (range_table_walker(query->rtable, walker, context, flags))
    2802                 :       16265 :             return true;
    2803                 :             :     }
    2804                 :     1000632 :     return false;
    2805                 :             : }
    2806                 :             : 
    2807                 :             : /*
    2808                 :             :  * range_table_walker is just the part of query_tree_walker that scans
    2809                 :             :  * a query's rangetable.  This is split out since it can be useful on
    2810                 :             :  * its own.
    2811                 :             :  */
    2812                 :             : bool
    2813                 :      645501 : range_table_walker_impl(List *rtable,
    2814                 :             :                         tree_walker_callback walker,
    2815                 :             :                         void *context,
    2816                 :             :                         int flags)
    2817                 :             : {
    2818                 :             :     ListCell   *rt;
    2819                 :             : 
    2820   [ +  +  +  +  :     1676547 :     foreach(rt, rtable)
                   +  + ]
    2821                 :             :     {
    2822                 :     1047311 :         RangeTblEntry *rte = lfirst_node(RangeTblEntry, rt);
    2823                 :             : 
    2824         [ +  + ]:     1047311 :         if (range_table_entry_walker(rte, walker, context, flags))
    2825                 :       16265 :             return true;
    2826                 :             :     }
    2827                 :      629236 :     return false;
    2828                 :             : }
    2829                 :             : 
    2830                 :             : /*
    2831                 :             :  * Some callers even want to scan the expressions in individual RTEs.
    2832                 :             :  */
    2833                 :             : pg_attribute_no_sanitize_function()
    2834                 :             : bool
    2835                 :     1047331 : range_table_entry_walker_impl(RangeTblEntry *rte,
    2836                 :             :                               tree_walker_callback walker,
    2837                 :             :                               void *context,
    2838                 :             :                               int flags)
    2839                 :             : {
    2840                 :             :     /*
    2841                 :             :      * Walkers might need to examine the RTE node itself either before or
    2842                 :             :      * after visiting its contents (or, conceivably, both).  Note that if you
    2843                 :             :      * specify neither flag, the walker won't be called on the RTE at all.
    2844                 :             :      */
    2845         [ +  + ]:     1047331 :     if (flags & QTW_EXAMINE_RTES_BEFORE)
    2846         [ +  + ]:       97998 :         if (WALK(rte))
    2847                 :          10 :             return true;
    2848                 :             : 
    2849   [ +  +  +  +  :     1047321 :     switch (rte->rtekind)
             +  +  +  +  
                      - ]
    2850                 :             :     {
    2851                 :      614127 :         case RTE_RELATION:
    2852         [ +  + ]:      614127 :             if (WALK(rte->tablesample))
    2853                 :          10 :                 return true;
    2854                 :      614117 :             break;
    2855                 :      120626 :         case RTE_SUBQUERY:
    2856         [ +  + ]:      120626 :             if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
    2857         [ +  + ]:      118797 :                 if (WALK(rte->subquery))
    2858                 :        3485 :                     return true;
    2859                 :      117141 :             break;
    2860                 :      182402 :         case RTE_JOIN:
    2861         [ +  + ]:      182402 :             if (!(flags & QTW_IGNORE_JOINALIASES))
    2862         [ -  + ]:      155702 :                 if (WALK(rte->joinaliasvars))
    2863                 :           0 :                     return true;
    2864                 :      182402 :             break;
    2865                 :       68334 :         case RTE_FUNCTION:
    2866         [ +  + ]:       68334 :             if (WALK(rte->functions))
    2867                 :       12703 :                 return true;
    2868                 :       55631 :             break;
    2869                 :         986 :         case RTE_TABLEFUNC:
    2870         [ -  + ]:         986 :             if (WALK(rte->tablefunc))
    2871                 :           0 :                 return true;
    2872                 :         986 :             break;
    2873                 :       22150 :         case RTE_VALUES:
    2874         [ +  + ]:       22150 :             if (WALK(rte->values_lists))
    2875                 :          41 :                 return true;
    2876                 :       22109 :             break;
    2877                 :       32531 :         case RTE_CTE:
    2878                 :             :         case RTE_NAMEDTUPLESTORE:
    2879                 :             :         case RTE_RESULT:
    2880                 :             :             /* nothing to do */
    2881                 :       32531 :             break;
    2882                 :        6165 :         case RTE_GROUP:
    2883         [ +  - ]:        6165 :             if (!(flags & QTW_IGNORE_GROUPEXPRS))
    2884         [ +  + ]:        6165 :                 if (WALK(rte->groupexprs))
    2885                 :          21 :                     return true;
    2886                 :        6144 :             break;
    2887                 :             :     }
    2888                 :             : 
    2889         [ +  + ]:     1031061 :     if (WALK(rte->securityQuals))
    2890                 :          15 :         return true;
    2891                 :             : 
    2892         [ +  + ]:     1031046 :     if (flags & QTW_EXAMINE_RTES_AFTER)
    2893         [ -  + ]:       12510 :         if (WALK(rte))
    2894                 :           0 :             return true;
    2895                 :             : 
    2896                 :     1031046 :     return false;
    2897                 :             : }
    2898                 :             : 
    2899                 :             : 
    2900                 :             : /*
    2901                 :             :  * expression_tree_mutator() is designed to support routines that make a
    2902                 :             :  * modified copy of an expression tree, with some nodes being added,
    2903                 :             :  * removed, or replaced by new subtrees.  The original tree is (normally)
    2904                 :             :  * not changed.  Each recursion level is responsible for returning a copy of
    2905                 :             :  * (or appropriately modified substitute for) the subtree it is handed.
    2906                 :             :  * A mutator routine should look like this:
    2907                 :             :  *
    2908                 :             :  * Node * my_mutator (Node *node, my_struct *context)
    2909                 :             :  * {
    2910                 :             :  *      if (node == NULL)
    2911                 :             :  *          return NULL;
    2912                 :             :  *      // check for nodes that special work is required for, eg:
    2913                 :             :  *      if (IsA(node, Var))
    2914                 :             :  *      {
    2915                 :             :  *          ... create and return modified copy of Var node
    2916                 :             :  *      }
    2917                 :             :  *      else if (IsA(node, ...))
    2918                 :             :  *      {
    2919                 :             :  *          ... do special transformations of other node types
    2920                 :             :  *      }
    2921                 :             :  *      // for any node type not specially processed, do:
    2922                 :             :  *      return expression_tree_mutator(node, my_mutator, context);
    2923                 :             :  * }
    2924                 :             :  *
    2925                 :             :  * The "context" argument points to a struct that holds whatever context
    2926                 :             :  * information the mutator routine needs --- it can be used to return extra
    2927                 :             :  * data gathered by the mutator, too.  This argument is not touched by
    2928                 :             :  * expression_tree_mutator, but it is passed down to recursive sub-invocations
    2929                 :             :  * of my_mutator.  The tree walk is started from a setup routine that
    2930                 :             :  * fills in the appropriate context struct, calls my_mutator with the
    2931                 :             :  * top-level node of the tree, and does any required post-processing.
    2932                 :             :  *
    2933                 :             :  * Each level of recursion must return an appropriately modified Node.
    2934                 :             :  * If expression_tree_mutator() is called, it will make an exact copy
    2935                 :             :  * of the given Node, but invoke my_mutator() to copy the sub-node(s)
    2936                 :             :  * of that Node.  In this way, my_mutator() has full control over the
    2937                 :             :  * copying process but need not directly deal with expression trees
    2938                 :             :  * that it has no interest in.
    2939                 :             :  *
    2940                 :             :  * Just as for expression_tree_walker, the node types handled by
    2941                 :             :  * expression_tree_mutator include all those normally found in target lists
    2942                 :             :  * and qualifier clauses during the planning stage.
    2943                 :             :  *
    2944                 :             :  * expression_tree_mutator will handle SubLink nodes by recursing normally
    2945                 :             :  * into the "testexpr" subtree (which is an expression belonging to the outer
    2946                 :             :  * plan).  It will also call the mutator on the sub-Query node; however, when
    2947                 :             :  * expression_tree_mutator itself is called on a Query node, it does nothing
    2948                 :             :  * and returns the unmodified Query node.  The net effect is that unless the
    2949                 :             :  * mutator does something special at a Query node, sub-selects will not be
    2950                 :             :  * visited or modified; the original sub-select will be linked to by the new
    2951                 :             :  * SubLink node.  Mutators that want to descend into sub-selects will usually
    2952                 :             :  * do so by recognizing Query nodes and calling query_tree_mutator (below).
    2953                 :             :  *
    2954                 :             :  * expression_tree_mutator will handle a SubPlan node by recursing into the
    2955                 :             :  * "testexpr" and the "args" list (which belong to the outer plan), but it
    2956                 :             :  * will simply copy the link to the inner plan, since that's typically what
    2957                 :             :  * expression tree mutators want.  A mutator that wants to modify the subplan
    2958                 :             :  * can force appropriate behavior by recognizing SubPlan expression nodes
    2959                 :             :  * and doing the right thing.
    2960                 :             :  */
    2961                 :             : 
    2962                 :             : pg_attribute_no_sanitize_function()
    2963                 :             : Node *
    2964                 :    15915492 : expression_tree_mutator_impl(Node *node,
    2965                 :             :                              tree_mutator_callback mutator,
    2966                 :             :                              void *context)
    2967                 :             : {
    2968                 :             :     /*
    2969                 :             :      * The mutator has already decided not to modify the current node, but we
    2970                 :             :      * must call the mutator for any sub-nodes.
    2971                 :             :      */
    2972                 :             : 
    2973                 :             : #define FLATCOPY(newnode, node, nodetype)  \
    2974                 :             :     ( (newnode) = palloc_object(nodetype), \
    2975                 :             :       memcpy((newnode), (node), sizeof(nodetype)) )
    2976                 :             : 
    2977                 :             : #define MUTATE(newfield, oldfield, fieldtype)  \
    2978                 :             :         ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
    2979                 :             : 
    2980         [ +  + ]:    15915492 :     if (node == NULL)
    2981                 :       52318 :         return NULL;
    2982                 :             : 
    2983                 :             :     /* Guard against stack overflow due to overly complex expressions */
    2984                 :    15863174 :     check_stack_depth();
    2985                 :             : 
    2986   [ +  +  +  +  :    15863174 :     switch (nodeTag(node))
          +  +  +  -  +  
          +  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  -  -  +  
          -  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  -  
             +  +  +  - ]
    2987                 :             :     {
    2988                 :             :             /*
    2989                 :             :              * Primitive node types with no expression subnodes.  Var and
    2990                 :             :              * Const are frequent enough to deserve special cases, the others
    2991                 :             :              * we just use copyObject for.
    2992                 :             :              */
    2993                 :     3012425 :         case T_Var:
    2994                 :             :             {
    2995                 :     3012425 :                 Var        *var = (Var *) node;
    2996                 :             :                 Var        *newnode;
    2997                 :             : 
    2998                 :     3012425 :                 FLATCOPY(newnode, var, Var);
    2999                 :             :                 /* Assume we need not copy the varnullingrels bitmapset */
    3000                 :     3012425 :                 return (Node *) newnode;
    3001                 :             :             }
    3002                 :             :             break;
    3003                 :     2497814 :         case T_Const:
    3004                 :             :             {
    3005                 :     2497814 :                 Const      *oldnode = (Const *) node;
    3006                 :             :                 Const      *newnode;
    3007                 :             : 
    3008                 :     2497814 :                 FLATCOPY(newnode, oldnode, Const);
    3009                 :             :                 /* XXX we don't bother with datumCopy; should we? */
    3010                 :     2497814 :                 return (Node *) newnode;
    3011                 :             :             }
    3012                 :             :             break;
    3013                 :      103036 :         case T_Param:
    3014                 :             :         case T_CaseTestExpr:
    3015                 :             :         case T_SQLValueFunction:
    3016                 :             :         case T_JsonFormat:
    3017                 :             :         case T_CoerceToDomainValue:
    3018                 :             :         case T_SetToDefault:
    3019                 :             :         case T_CurrentOfExpr:
    3020                 :             :         case T_NextValueExpr:
    3021                 :             :         case T_RangeTblRef:
    3022                 :             :         case T_SortGroupClause:
    3023                 :             :         case T_CTESearchClause:
    3024                 :             :         case T_MergeSupportFunc:
    3025                 :      103036 :             return copyObject(node);
    3026                 :        1105 :         case T_WithCheckOption:
    3027                 :             :             {
    3028                 :        1105 :                 WithCheckOption *wco = (WithCheckOption *) node;
    3029                 :             :                 WithCheckOption *newnode;
    3030                 :             : 
    3031                 :        1105 :                 FLATCOPY(newnode, wco, WithCheckOption);
    3032                 :        1105 :                 MUTATE(newnode->qual, wco->qual, Node *);
    3033                 :        1105 :                 return (Node *) newnode;
    3034                 :             :             }
    3035                 :      142366 :         case T_Aggref:
    3036                 :             :             {
    3037                 :      142366 :                 Aggref     *aggref = (Aggref *) node;
    3038                 :             :                 Aggref     *newnode;
    3039                 :             : 
    3040                 :      142366 :                 FLATCOPY(newnode, aggref, Aggref);
    3041                 :             :                 /* assume mutation doesn't change types of arguments */
    3042                 :      142366 :                 newnode->aggargtypes = list_copy(aggref->aggargtypes);
    3043                 :      142366 :                 MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
    3044                 :      142366 :                 MUTATE(newnode->args, aggref->args, List *);
    3045                 :      142366 :                 MUTATE(newnode->aggorder, aggref->aggorder, List *);
    3046                 :      142366 :                 MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
    3047                 :      142366 :                 MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
    3048                 :      142366 :                 return (Node *) newnode;
    3049                 :             :             }
    3050                 :             :             break;
    3051                 :        1273 :         case T_GroupingFunc:
    3052                 :             :             {
    3053                 :        1273 :                 GroupingFunc *grouping = (GroupingFunc *) node;
    3054                 :             :                 GroupingFunc *newnode;
    3055                 :             : 
    3056                 :        1273 :                 FLATCOPY(newnode, grouping, GroupingFunc);
    3057                 :        1273 :                 MUTATE(newnode->args, grouping->args, List *);
    3058                 :             : 
    3059                 :             :                 /*
    3060                 :             :                  * We assume here that mutating the arguments does not change
    3061                 :             :                  * the semantics, i.e. that the arguments are not mutated in a
    3062                 :             :                  * way that makes them semantically different from their
    3063                 :             :                  * previously matching expressions in the GROUP BY clause.
    3064                 :             :                  *
    3065                 :             :                  * If a mutator somehow wanted to do this, it would have to
    3066                 :             :                  * handle the refs and cols lists itself as appropriate.
    3067                 :             :                  */
    3068                 :        1273 :                 newnode->refs = list_copy(grouping->refs);
    3069                 :        1273 :                 newnode->cols = list_copy(grouping->cols);
    3070                 :             : 
    3071                 :        1273 :                 return (Node *) newnode;
    3072                 :             :             }
    3073                 :             :             break;
    3074                 :        4980 :         case T_WindowFunc:
    3075                 :             :             {
    3076                 :        4980 :                 WindowFunc *wfunc = (WindowFunc *) node;
    3077                 :             :                 WindowFunc *newnode;
    3078                 :             : 
    3079                 :        4980 :                 FLATCOPY(newnode, wfunc, WindowFunc);
    3080                 :        4980 :                 MUTATE(newnode->args, wfunc->args, List *);
    3081                 :        4980 :                 MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
    3082                 :        4980 :                 return (Node *) newnode;
    3083                 :             :             }
    3084                 :             :             break;
    3085                 :           0 :         case T_WindowFuncRunCondition:
    3086                 :             :             {
    3087                 :           0 :                 WindowFuncRunCondition *wfuncrc = (WindowFuncRunCondition *) node;
    3088                 :             :                 WindowFuncRunCondition *newnode;
    3089                 :             : 
    3090                 :           0 :                 FLATCOPY(newnode, wfuncrc, WindowFuncRunCondition);
    3091                 :           0 :                 MUTATE(newnode->arg, wfuncrc->arg, Expr *);
    3092                 :           0 :                 return (Node *) newnode;
    3093                 :             :             }
    3094                 :             :             break;
    3095                 :       57804 :         case T_SubscriptingRef:
    3096                 :             :             {
    3097                 :       57804 :                 SubscriptingRef *sbsref = (SubscriptingRef *) node;
    3098                 :             :                 SubscriptingRef *newnode;
    3099                 :             : 
    3100                 :       57804 :                 FLATCOPY(newnode, sbsref, SubscriptingRef);
    3101                 :       57804 :                 MUTATE(newnode->refupperindexpr, sbsref->refupperindexpr,
    3102                 :             :                        List *);
    3103                 :       57804 :                 MUTATE(newnode->reflowerindexpr, sbsref->reflowerindexpr,
    3104                 :             :                        List *);
    3105                 :       57804 :                 MUTATE(newnode->refexpr, sbsref->refexpr,
    3106                 :             :                        Expr *);
    3107                 :       57804 :                 MUTATE(newnode->refassgnexpr, sbsref->refassgnexpr,
    3108                 :             :                        Expr *);
    3109                 :             : 
    3110                 :       57804 :                 return (Node *) newnode;
    3111                 :             :             }
    3112                 :             :             break;
    3113                 :      264976 :         case T_FuncExpr:
    3114                 :             :             {
    3115                 :      264976 :                 FuncExpr   *expr = (FuncExpr *) node;
    3116                 :             :                 FuncExpr   *newnode;
    3117                 :             : 
    3118                 :      264976 :                 FLATCOPY(newnode, expr, FuncExpr);
    3119                 :      264976 :                 MUTATE(newnode->args, expr->args, List *);
    3120                 :      264976 :                 return (Node *) newnode;
    3121                 :             :             }
    3122                 :             :             break;
    3123                 :           0 :         case T_NamedArgExpr:
    3124                 :             :             {
    3125                 :           0 :                 NamedArgExpr *nexpr = (NamedArgExpr *) node;
    3126                 :             :                 NamedArgExpr *newnode;
    3127                 :             : 
    3128                 :           0 :                 FLATCOPY(newnode, nexpr, NamedArgExpr);
    3129                 :           0 :                 MUTATE(newnode->arg, nexpr->arg, Expr *);
    3130                 :           0 :                 return (Node *) newnode;
    3131                 :             :             }
    3132                 :             :             break;
    3133                 :     1058702 :         case T_OpExpr:
    3134                 :             :             {
    3135                 :     1058702 :                 OpExpr     *expr = (OpExpr *) node;
    3136                 :             :                 OpExpr     *newnode;
    3137                 :             : 
    3138                 :     1058702 :                 FLATCOPY(newnode, expr, OpExpr);
    3139                 :     1058702 :                 MUTATE(newnode->args, expr->args, List *);
    3140                 :     1058698 :                 return (Node *) newnode;
    3141                 :             :             }
    3142                 :             :             break;
    3143                 :        1800 :         case T_DistinctExpr:
    3144                 :             :             {
    3145                 :        1800 :                 DistinctExpr *expr = (DistinctExpr *) node;
    3146                 :             :                 DistinctExpr *newnode;
    3147                 :             : 
    3148                 :        1800 :                 FLATCOPY(newnode, expr, DistinctExpr);
    3149                 :        1800 :                 MUTATE(newnode->args, expr->args, List *);
    3150                 :        1800 :                 return (Node *) newnode;
    3151                 :             :             }
    3152                 :             :             break;
    3153                 :        1510 :         case T_NullIfExpr:
    3154                 :             :             {
    3155                 :        1510 :                 NullIfExpr *expr = (NullIfExpr *) node;
    3156                 :             :                 NullIfExpr *newnode;
    3157                 :             : 
    3158                 :        1510 :                 FLATCOPY(newnode, expr, NullIfExpr);
    3159                 :        1510 :                 MUTATE(newnode->args, expr->args, List *);
    3160                 :        1510 :                 return (Node *) newnode;
    3161                 :             :             }
    3162                 :             :             break;
    3163                 :       66794 :         case T_ScalarArrayOpExpr:
    3164                 :             :             {
    3165                 :       66794 :                 ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
    3166                 :             :                 ScalarArrayOpExpr *newnode;
    3167                 :             : 
    3168                 :       66794 :                 FLATCOPY(newnode, expr, ScalarArrayOpExpr);
    3169                 :       66794 :                 MUTATE(newnode->args, expr->args, List *);
    3170                 :       66794 :                 return (Node *) newnode;
    3171                 :             :             }
    3172                 :             :             break;
    3173                 :      150586 :         case T_BoolExpr:
    3174                 :             :             {
    3175                 :      150586 :                 BoolExpr   *expr = (BoolExpr *) node;
    3176                 :             :                 BoolExpr   *newnode;
    3177                 :             : 
    3178                 :      150586 :                 FLATCOPY(newnode, expr, BoolExpr);
    3179                 :      150586 :                 MUTATE(newnode->args, expr->args, List *);
    3180                 :      150586 :                 return (Node *) newnode;
    3181                 :             :             }
    3182                 :             :             break;
    3183                 :       40803 :         case T_SubLink:
    3184                 :             :             {
    3185                 :       40803 :                 SubLink    *sublink = (SubLink *) node;
    3186                 :             :                 SubLink    *newnode;
    3187                 :             : 
    3188                 :       40803 :                 FLATCOPY(newnode, sublink, SubLink);
    3189                 :       40803 :                 MUTATE(newnode->testexpr, sublink->testexpr, Node *);
    3190                 :             : 
    3191                 :             :                 /*
    3192                 :             :                  * Also invoke the mutator on the sublink's Query node, so it
    3193                 :             :                  * can recurse into the sub-query if it wants to.
    3194                 :             :                  */
    3195                 :       40803 :                 MUTATE(newnode->subselect, sublink->subselect, Node *);
    3196                 :       40803 :                 return (Node *) newnode;
    3197                 :             :             }
    3198                 :             :             break;
    3199                 :       14189 :         case T_SubPlan:
    3200                 :             :             {
    3201                 :       14189 :                 SubPlan    *subplan = (SubPlan *) node;
    3202                 :             :                 SubPlan    *newnode;
    3203                 :             : 
    3204                 :       14189 :                 FLATCOPY(newnode, subplan, SubPlan);
    3205                 :             :                 /* transform testexpr */
    3206                 :       14189 :                 MUTATE(newnode->testexpr, subplan->testexpr, Node *);
    3207                 :             :                 /* transform args list (params to be passed to subplan) */
    3208                 :       14189 :                 MUTATE(newnode->args, subplan->args, List *);
    3209                 :             :                 /* but not the sub-Plan itself, which is referenced as-is */
    3210                 :       14189 :                 return (Node *) newnode;
    3211                 :             :             }
    3212                 :             :             break;
    3213                 :         180 :         case T_AlternativeSubPlan:
    3214                 :             :             {
    3215                 :         180 :                 AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
    3216                 :             :                 AlternativeSubPlan *newnode;
    3217                 :             : 
    3218                 :         180 :                 FLATCOPY(newnode, asplan, AlternativeSubPlan);
    3219                 :         180 :                 MUTATE(newnode->subplans, asplan->subplans, List *);
    3220                 :         180 :                 return (Node *) newnode;
    3221                 :             :             }
    3222                 :             :             break;
    3223                 :       92814 :         case T_FieldSelect:
    3224                 :             :             {
    3225                 :       92814 :                 FieldSelect *fselect = (FieldSelect *) node;
    3226                 :             :                 FieldSelect *newnode;
    3227                 :             : 
    3228                 :       92814 :                 FLATCOPY(newnode, fselect, FieldSelect);
    3229                 :       92814 :                 MUTATE(newnode->arg, fselect->arg, Expr *);
    3230                 :       92814 :                 return (Node *) newnode;
    3231                 :             :             }
    3232                 :             :             break;
    3233                 :         360 :         case T_FieldStore:
    3234                 :             :             {
    3235                 :         360 :                 FieldStore *fstore = (FieldStore *) node;
    3236                 :             :                 FieldStore *newnode;
    3237                 :             : 
    3238                 :         360 :                 FLATCOPY(newnode, fstore, FieldStore);
    3239                 :         360 :                 MUTATE(newnode->arg, fstore->arg, Expr *);
    3240                 :         360 :                 MUTATE(newnode->newvals, fstore->newvals, List *);
    3241                 :         360 :                 newnode->fieldnums = list_copy(fstore->fieldnums);
    3242                 :         360 :                 return (Node *) newnode;
    3243                 :             :             }
    3244                 :             :             break;
    3245                 :      118053 :         case T_RelabelType:
    3246                 :             :             {
    3247                 :      118053 :                 RelabelType *relabel = (RelabelType *) node;
    3248                 :             :                 RelabelType *newnode;
    3249                 :             : 
    3250                 :      118053 :                 FLATCOPY(newnode, relabel, RelabelType);
    3251                 :      118053 :                 MUTATE(newnode->arg, relabel->arg, Expr *);
    3252                 :      118053 :                 return (Node *) newnode;
    3253                 :             :             }
    3254                 :             :             break;
    3255                 :       31699 :         case T_CoerceViaIO:
    3256                 :             :             {
    3257                 :       31699 :                 CoerceViaIO *iocoerce = (CoerceViaIO *) node;
    3258                 :             :                 CoerceViaIO *newnode;
    3259                 :             : 
    3260                 :       31699 :                 FLATCOPY(newnode, iocoerce, CoerceViaIO);
    3261                 :       31699 :                 MUTATE(newnode->arg, iocoerce->arg, Expr *);
    3262                 :       31699 :                 return (Node *) newnode;
    3263                 :             :             }
    3264                 :             :             break;
    3265                 :       10370 :         case T_ArrayCoerceExpr:
    3266                 :             :             {
    3267                 :       10370 :                 ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
    3268                 :             :                 ArrayCoerceExpr *newnode;
    3269                 :             : 
    3270                 :       10370 :                 FLATCOPY(newnode, acoerce, ArrayCoerceExpr);
    3271                 :       10370 :                 MUTATE(newnode->arg, acoerce->arg, Expr *);
    3272                 :       10370 :                 MUTATE(newnode->elemexpr, acoerce->elemexpr, Expr *);
    3273                 :       10370 :                 return (Node *) newnode;
    3274                 :             :             }
    3275                 :             :             break;
    3276                 :         278 :         case T_ConvertRowtypeExpr:
    3277                 :             :             {
    3278                 :         278 :                 ConvertRowtypeExpr *convexpr = (ConvertRowtypeExpr *) node;
    3279                 :             :                 ConvertRowtypeExpr *newnode;
    3280                 :             : 
    3281                 :         278 :                 FLATCOPY(newnode, convexpr, ConvertRowtypeExpr);
    3282                 :         278 :                 MUTATE(newnode->arg, convexpr->arg, Expr *);
    3283                 :         278 :                 return (Node *) newnode;
    3284                 :             :             }
    3285                 :             :             break;
    3286                 :        5912 :         case T_CollateExpr:
    3287                 :             :             {
    3288                 :        5912 :                 CollateExpr *collate = (CollateExpr *) node;
    3289                 :             :                 CollateExpr *newnode;
    3290                 :             : 
    3291                 :        5912 :                 FLATCOPY(newnode, collate, CollateExpr);
    3292                 :        5912 :                 MUTATE(newnode->arg, collate->arg, Expr *);
    3293                 :        5912 :                 return (Node *) newnode;
    3294                 :             :             }
    3295                 :             :             break;
    3296                 :       66667 :         case T_CaseExpr:
    3297                 :             :             {
    3298                 :       66667 :                 CaseExpr   *caseexpr = (CaseExpr *) node;
    3299                 :             :                 CaseExpr   *newnode;
    3300                 :             : 
    3301                 :       66667 :                 FLATCOPY(newnode, caseexpr, CaseExpr);
    3302                 :       66667 :                 MUTATE(newnode->arg, caseexpr->arg, Expr *);
    3303                 :       66667 :                 MUTATE(newnode->args, caseexpr->args, List *);
    3304                 :       66667 :                 MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
    3305                 :       66667 :                 return (Node *) newnode;
    3306                 :             :             }
    3307                 :             :             break;
    3308                 :      158776 :         case T_CaseWhen:
    3309                 :             :             {
    3310                 :      158776 :                 CaseWhen   *casewhen = (CaseWhen *) node;
    3311                 :             :                 CaseWhen   *newnode;
    3312                 :             : 
    3313                 :      158776 :                 FLATCOPY(newnode, casewhen, CaseWhen);
    3314                 :      158776 :                 MUTATE(newnode->expr, casewhen->expr, Expr *);
    3315                 :      158776 :                 MUTATE(newnode->result, casewhen->result, Expr *);
    3316                 :      158776 :                 return (Node *) newnode;
    3317                 :             :             }
    3318                 :             :             break;
    3319                 :       31455 :         case T_ArrayExpr:
    3320                 :             :             {
    3321                 :       31455 :                 ArrayExpr  *arrayexpr = (ArrayExpr *) node;
    3322                 :             :                 ArrayExpr  *newnode;
    3323                 :             : 
    3324                 :       31455 :                 FLATCOPY(newnode, arrayexpr, ArrayExpr);
    3325                 :       31455 :                 MUTATE(newnode->elements, arrayexpr->elements, List *);
    3326                 :       31455 :                 return (Node *) newnode;
    3327                 :             :             }
    3328                 :             :             break;
    3329                 :        7667 :         case T_RowExpr:
    3330                 :             :             {
    3331                 :        7667 :                 RowExpr    *rowexpr = (RowExpr *) node;
    3332                 :             :                 RowExpr    *newnode;
    3333                 :             : 
    3334                 :        7667 :                 FLATCOPY(newnode, rowexpr, RowExpr);
    3335                 :        7667 :                 MUTATE(newnode->args, rowexpr->args, List *);
    3336                 :             :                 /* Assume colnames needn't be duplicated */
    3337                 :        7667 :                 return (Node *) newnode;
    3338                 :             :             }
    3339                 :             :             break;
    3340                 :         673 :         case T_RowCompareExpr:
    3341                 :             :             {
    3342                 :         673 :                 RowCompareExpr *rcexpr = (RowCompareExpr *) node;
    3343                 :             :                 RowCompareExpr *newnode;
    3344                 :             : 
    3345                 :         673 :                 FLATCOPY(newnode, rcexpr, RowCompareExpr);
    3346                 :         673 :                 MUTATE(newnode->largs, rcexpr->largs, List *);
    3347                 :         673 :                 MUTATE(newnode->rargs, rcexpr->rargs, List *);
    3348                 :         673 :                 return (Node *) newnode;
    3349                 :             :             }
    3350                 :             :             break;
    3351                 :       10977 :         case T_CoalesceExpr:
    3352                 :             :             {
    3353                 :       10977 :                 CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
    3354                 :             :                 CoalesceExpr *newnode;
    3355                 :             : 
    3356                 :       10977 :                 FLATCOPY(newnode, coalesceexpr, CoalesceExpr);
    3357                 :       10977 :                 MUTATE(newnode->args, coalesceexpr->args, List *);
    3358                 :       10977 :                 return (Node *) newnode;
    3359                 :             :             }
    3360                 :             :             break;
    3361                 :        1130 :         case T_MinMaxExpr:
    3362                 :             :             {
    3363                 :        1130 :                 MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
    3364                 :             :                 MinMaxExpr *newnode;
    3365                 :             : 
    3366                 :        1130 :                 FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
    3367                 :        1130 :                 MUTATE(newnode->args, minmaxexpr->args, List *);
    3368                 :        1130 :                 return (Node *) newnode;
    3369                 :             :             }
    3370                 :             :             break;
    3371                 :         672 :         case T_XmlExpr:
    3372                 :             :             {
    3373                 :         672 :                 XmlExpr    *xexpr = (XmlExpr *) node;
    3374                 :             :                 XmlExpr    *newnode;
    3375                 :             : 
    3376                 :         672 :                 FLATCOPY(newnode, xexpr, XmlExpr);
    3377                 :         672 :                 MUTATE(newnode->named_args, xexpr->named_args, List *);
    3378                 :             :                 /* assume mutator does not care about arg_names */
    3379                 :         672 :                 MUTATE(newnode->args, xexpr->args, List *);
    3380                 :         672 :                 return (Node *) newnode;
    3381                 :             :             }
    3382                 :             :             break;
    3383                 :        1267 :         case T_JsonReturning:
    3384                 :             :             {
    3385                 :        1267 :                 JsonReturning *jr = (JsonReturning *) node;
    3386                 :             :                 JsonReturning *newnode;
    3387                 :             : 
    3388                 :        1267 :                 FLATCOPY(newnode, jr, JsonReturning);
    3389                 :        1267 :                 MUTATE(newnode->format, jr->format, JsonFormat *);
    3390                 :             : 
    3391                 :        1267 :                 return (Node *) newnode;
    3392                 :             :             }
    3393                 :         149 :         case T_JsonValueExpr:
    3394                 :             :             {
    3395                 :         149 :                 JsonValueExpr *jve = (JsonValueExpr *) node;
    3396                 :             :                 JsonValueExpr *newnode;
    3397                 :             : 
    3398                 :         149 :                 FLATCOPY(newnode, jve, JsonValueExpr);
    3399                 :         149 :                 MUTATE(newnode->raw_expr, jve->raw_expr, Expr *);
    3400                 :         149 :                 MUTATE(newnode->formatted_expr, jve->formatted_expr, Expr *);
    3401                 :         149 :                 MUTATE(newnode->format, jve->format, JsonFormat *);
    3402                 :             : 
    3403                 :         149 :                 return (Node *) newnode;
    3404                 :             :             }
    3405                 :        1267 :         case T_JsonConstructorExpr:
    3406                 :             :             {
    3407                 :        1267 :                 JsonConstructorExpr *jce = (JsonConstructorExpr *) node;
    3408                 :             :                 JsonConstructorExpr *newnode;
    3409                 :             : 
    3410                 :        1267 :                 FLATCOPY(newnode, jce, JsonConstructorExpr);
    3411                 :        1267 :                 MUTATE(newnode->args, jce->args, List *);
    3412                 :        1267 :                 MUTATE(newnode->func, jce->func, Expr *);
    3413                 :        1267 :                 MUTATE(newnode->coercion, jce->coercion, Expr *);
    3414                 :        1267 :                 MUTATE(newnode->returning, jce->returning, JsonReturning *);
    3415                 :             : 
    3416                 :        1267 :                 return (Node *) newnode;
    3417                 :             :             }
    3418                 :         511 :         case T_JsonIsPredicate:
    3419                 :             :             {
    3420                 :         511 :                 JsonIsPredicate *pred = (JsonIsPredicate *) node;
    3421                 :             :                 JsonIsPredicate *newnode;
    3422                 :             : 
    3423                 :         511 :                 FLATCOPY(newnode, pred, JsonIsPredicate);
    3424                 :         511 :                 MUTATE(newnode->expr, pred->expr, Node *);
    3425                 :         511 :                 MUTATE(newnode->format, pred->format, JsonFormat *);
    3426                 :             : 
    3427                 :         511 :                 return (Node *) newnode;
    3428                 :             :             }
    3429                 :        3873 :         case T_JsonExpr:
    3430                 :             :             {
    3431                 :        3873 :                 JsonExpr   *jexpr = (JsonExpr *) node;
    3432                 :             :                 JsonExpr   *newnode;
    3433                 :             : 
    3434                 :        3873 :                 FLATCOPY(newnode, jexpr, JsonExpr);
    3435                 :        3873 :                 MUTATE(newnode->formatted_expr, jexpr->formatted_expr, Node *);
    3436                 :        3873 :                 MUTATE(newnode->path_spec, jexpr->path_spec, Node *);
    3437                 :        3869 :                 MUTATE(newnode->passing_values, jexpr->passing_values, List *);
    3438                 :             :                 /* assume mutator does not care about passing_names */
    3439                 :        3869 :                 MUTATE(newnode->on_empty, jexpr->on_empty, JsonBehavior *);
    3440                 :        3845 :                 MUTATE(newnode->on_error, jexpr->on_error, JsonBehavior *);
    3441                 :        3841 :                 return (Node *) newnode;
    3442                 :             :             }
    3443                 :             :             break;
    3444                 :        6788 :         case T_JsonBehavior:
    3445                 :             :             {
    3446                 :        6788 :                 JsonBehavior *behavior = (JsonBehavior *) node;
    3447                 :             :                 JsonBehavior *newnode;
    3448                 :             : 
    3449                 :        6788 :                 FLATCOPY(newnode, behavior, JsonBehavior);
    3450                 :        6788 :                 MUTATE(newnode->expr, behavior->expr, Node *);
    3451                 :        6760 :                 return (Node *) newnode;
    3452                 :             :             }
    3453                 :             :             break;
    3454                 :       36235 :         case T_NullTest:
    3455                 :             :             {
    3456                 :       36235 :                 NullTest   *ntest = (NullTest *) node;
    3457                 :             :                 NullTest   *newnode;
    3458                 :             : 
    3459                 :       36235 :                 FLATCOPY(newnode, ntest, NullTest);
    3460                 :       36235 :                 MUTATE(newnode->arg, ntest->arg, Expr *);
    3461                 :       36235 :                 return (Node *) newnode;
    3462                 :             :             }
    3463                 :             :             break;
    3464                 :        1800 :         case T_BooleanTest:
    3465                 :             :             {
    3466                 :        1800 :                 BooleanTest *btest = (BooleanTest *) node;
    3467                 :             :                 BooleanTest *newnode;
    3468                 :             : 
    3469                 :        1800 :                 FLATCOPY(newnode, btest, BooleanTest);
    3470                 :        1800 :                 MUTATE(newnode->arg, btest->arg, Expr *);
    3471                 :        1800 :                 return (Node *) newnode;
    3472                 :             :             }
    3473                 :             :             break;
    3474                 :       13922 :         case T_CoerceToDomain:
    3475                 :             :             {
    3476                 :       13922 :                 CoerceToDomain *ctest = (CoerceToDomain *) node;
    3477                 :             :                 CoerceToDomain *newnode;
    3478                 :             : 
    3479                 :       13922 :                 FLATCOPY(newnode, ctest, CoerceToDomain);
    3480                 :       13922 :                 MUTATE(newnode->arg, ctest->arg, Expr *);
    3481                 :       13922 :                 return (Node *) newnode;
    3482                 :             :             }
    3483                 :             :             break;
    3484                 :        1633 :         case T_ReturningExpr:
    3485                 :             :             {
    3486                 :        1633 :                 ReturningExpr *rexpr = (ReturningExpr *) node;
    3487                 :             :                 ReturningExpr *newnode;
    3488                 :             : 
    3489                 :        1633 :                 FLATCOPY(newnode, rexpr, ReturningExpr);
    3490                 :        1633 :                 MUTATE(newnode->retexpr, rexpr->retexpr, Expr *);
    3491                 :        1633 :                 return (Node *) newnode;
    3492                 :             :             }
    3493                 :             :             break;
    3494                 :     3392617 :         case T_TargetEntry:
    3495                 :             :             {
    3496                 :     3392617 :                 TargetEntry *targetentry = (TargetEntry *) node;
    3497                 :             :                 TargetEntry *newnode;
    3498                 :             : 
    3499                 :     3392617 :                 FLATCOPY(newnode, targetentry, TargetEntry);
    3500                 :     3392617 :                 MUTATE(newnode->expr, targetentry->expr, Expr *);
    3501                 :     3389798 :                 return (Node *) newnode;
    3502                 :             :             }
    3503                 :             :             break;
    3504                 :       28942 :         case T_Query:
    3505                 :             :             /* Do nothing with a sub-Query, per discussion above */
    3506                 :       28942 :             return node;
    3507                 :           0 :         case T_WindowClause:
    3508                 :             :             {
    3509                 :           0 :                 WindowClause *wc = (WindowClause *) node;
    3510                 :             :                 WindowClause *newnode;
    3511                 :             : 
    3512                 :           0 :                 FLATCOPY(newnode, wc, WindowClause);
    3513                 :           0 :                 MUTATE(newnode->partitionClause, wc->partitionClause, List *);
    3514                 :           0 :                 MUTATE(newnode->orderClause, wc->orderClause, List *);
    3515                 :           0 :                 MUTATE(newnode->startOffset, wc->startOffset, Node *);
    3516                 :           0 :                 MUTATE(newnode->endOffset, wc->endOffset, Node *);
    3517                 :           0 :                 return (Node *) newnode;
    3518                 :             :             }
    3519                 :             :             break;
    3520                 :           0 :         case T_CTECycleClause:
    3521                 :             :             {
    3522                 :           0 :                 CTECycleClause *cc = (CTECycleClause *) node;
    3523                 :             :                 CTECycleClause *newnode;
    3524                 :             : 
    3525                 :           0 :                 FLATCOPY(newnode, cc, CTECycleClause);
    3526                 :           0 :                 MUTATE(newnode->cycle_mark_value, cc->cycle_mark_value, Node *);
    3527                 :           0 :                 MUTATE(newnode->cycle_mark_default, cc->cycle_mark_default, Node *);
    3528                 :           0 :                 return (Node *) newnode;
    3529                 :             :             }
    3530                 :             :             break;
    3531                 :         177 :         case T_CommonTableExpr:
    3532                 :             :             {
    3533                 :         177 :                 CommonTableExpr *cte = (CommonTableExpr *) node;
    3534                 :             :                 CommonTableExpr *newnode;
    3535                 :             : 
    3536                 :         177 :                 FLATCOPY(newnode, cte, CommonTableExpr);
    3537                 :             : 
    3538                 :             :                 /*
    3539                 :             :                  * Also invoke the mutator on the CTE's Query node, so it can
    3540                 :             :                  * recurse into the sub-query if it wants to.
    3541                 :             :                  */
    3542                 :         177 :                 MUTATE(newnode->ctequery, cte->ctequery, Node *);
    3543                 :             : 
    3544                 :         177 :                 MUTATE(newnode->search_clause, cte->search_clause, CTESearchClause *);
    3545                 :         177 :                 MUTATE(newnode->cycle_clause, cte->cycle_clause, CTECycleClause *);
    3546                 :             : 
    3547                 :         177 :                 return (Node *) newnode;
    3548                 :             :             }
    3549                 :             :             break;
    3550                 :           0 :         case T_PartitionBoundSpec:
    3551                 :             :             {
    3552                 :           0 :                 PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
    3553                 :             :                 PartitionBoundSpec *newnode;
    3554                 :             : 
    3555                 :           0 :                 FLATCOPY(newnode, pbs, PartitionBoundSpec);
    3556                 :           0 :                 MUTATE(newnode->listdatums, pbs->listdatums, List *);
    3557                 :           0 :                 MUTATE(newnode->lowerdatums, pbs->lowerdatums, List *);
    3558                 :           0 :                 MUTATE(newnode->upperdatums, pbs->upperdatums, List *);
    3559                 :           0 :                 return (Node *) newnode;
    3560                 :             :             }
    3561                 :             :             break;
    3562                 :           0 :         case T_PartitionRangeDatum:
    3563                 :             :             {
    3564                 :           0 :                 PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
    3565                 :             :                 PartitionRangeDatum *newnode;
    3566                 :             : 
    3567                 :           0 :                 FLATCOPY(newnode, prd, PartitionRangeDatum);
    3568                 :           0 :                 MUTATE(newnode->value, prd->value, Node *);
    3569                 :           0 :                 return (Node *) newnode;
    3570                 :             :             }
    3571                 :             :             break;
    3572                 :     4278493 :         case T_List:
    3573                 :             :             {
    3574                 :             :                 /*
    3575                 :             :                  * We assume the mutator isn't interested in the list nodes
    3576                 :             :                  * per se, so just invoke it on each list element. NOTE: this
    3577                 :             :                  * would fail badly on a list with integer elements!
    3578                 :             :                  */
    3579                 :             :                 List       *resultlist;
    3580                 :             :                 ListCell   *temp;
    3581                 :             : 
    3582                 :     4278493 :                 resultlist = NIL;
    3583   [ +  -  +  +  :    13877317 :                 foreach(temp, (List *) node)
                   +  + ]
    3584                 :             :                 {
    3585                 :     9598824 :                     resultlist = lappend(resultlist,
    3586                 :     9601740 :                                          mutator((Node *) lfirst(temp),
    3587                 :             :                                                  context));
    3588                 :             :                 }
    3589                 :     4275577 :                 return (Node *) resultlist;
    3590                 :             :             }
    3591                 :             :             break;
    3592                 :       23020 :         case T_FromExpr:
    3593                 :             :             {
    3594                 :       23020 :                 FromExpr   *from = (FromExpr *) node;
    3595                 :             :                 FromExpr   *newnode;
    3596                 :             : 
    3597                 :       23020 :                 FLATCOPY(newnode, from, FromExpr);
    3598                 :       23020 :                 MUTATE(newnode->fromlist, from->fromlist, List *);
    3599                 :       23020 :                 MUTATE(newnode->quals, from->quals, Node *);
    3600                 :       23020 :                 return (Node *) newnode;
    3601                 :             :             }
    3602                 :             :             break;
    3603                 :         414 :         case T_OnConflictExpr:
    3604                 :             :             {
    3605                 :         414 :                 OnConflictExpr *oc = (OnConflictExpr *) node;
    3606                 :             :                 OnConflictExpr *newnode;
    3607                 :             : 
    3608                 :         414 :                 FLATCOPY(newnode, oc, OnConflictExpr);
    3609                 :         414 :                 MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
    3610                 :         414 :                 MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
    3611                 :         414 :                 MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
    3612                 :         414 :                 MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
    3613                 :         414 :                 MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
    3614                 :             : 
    3615                 :         414 :                 return (Node *) newnode;
    3616                 :             :             }
    3617                 :             :             break;
    3618                 :         712 :         case T_MergeAction:
    3619                 :             :             {
    3620                 :         712 :                 MergeAction *action = (MergeAction *) node;
    3621                 :             :                 MergeAction *newnode;
    3622                 :             : 
    3623                 :         712 :                 FLATCOPY(newnode, action, MergeAction);
    3624                 :         712 :                 MUTATE(newnode->qual, action->qual, Node *);
    3625                 :         712 :                 MUTATE(newnode->targetList, action->targetList, List *);
    3626                 :             : 
    3627                 :         712 :                 return (Node *) newnode;
    3628                 :             :             }
    3629                 :             :             break;
    3630                 :         138 :         case T_PartitionPruneStepOp:
    3631                 :             :             {
    3632                 :         138 :                 PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
    3633                 :             :                 PartitionPruneStepOp *newnode;
    3634                 :             : 
    3635                 :         138 :                 FLATCOPY(newnode, opstep, PartitionPruneStepOp);
    3636                 :         138 :                 MUTATE(newnode->exprs, opstep->exprs, List *);
    3637                 :             : 
    3638                 :         138 :                 return (Node *) newnode;
    3639                 :             :             }
    3640                 :             :             break;
    3641                 :          14 :         case T_PartitionPruneStepCombine:
    3642                 :             :             /* no expression sub-nodes */
    3643                 :          14 :             return copyObject(node);
    3644                 :        6535 :         case T_JoinExpr:
    3645                 :             :             {
    3646                 :        6535 :                 JoinExpr   *join = (JoinExpr *) node;
    3647                 :             :                 JoinExpr   *newnode;
    3648                 :             : 
    3649                 :        6535 :                 FLATCOPY(newnode, join, JoinExpr);
    3650                 :        6535 :                 MUTATE(newnode->larg, join->larg, Node *);
    3651                 :        6535 :                 MUTATE(newnode->rarg, join->rarg, Node *);
    3652                 :        6535 :                 MUTATE(newnode->quals, join->quals, Node *);
    3653                 :             :                 /* We do not mutate alias or using by default */
    3654                 :        6535 :                 return (Node *) newnode;
    3655                 :             :             }
    3656                 :             :             break;
    3657                 :         201 :         case T_SetOperationStmt:
    3658                 :             :             {
    3659                 :         201 :                 SetOperationStmt *setop = (SetOperationStmt *) node;
    3660                 :             :                 SetOperationStmt *newnode;
    3661                 :             : 
    3662                 :         201 :                 FLATCOPY(newnode, setop, SetOperationStmt);
    3663                 :         201 :                 MUTATE(newnode->larg, setop->larg, Node *);
    3664                 :         201 :                 MUTATE(newnode->rarg, setop->rarg, Node *);
    3665                 :             :                 /* We do not mutate groupClauses by default */
    3666                 :         201 :                 return (Node *) newnode;
    3667                 :             :             }
    3668                 :             :             break;
    3669                 :         614 :         case T_IndexClause:
    3670                 :             :             {
    3671                 :         614 :                 IndexClause *iclause = (IndexClause *) node;
    3672                 :             :                 IndexClause *newnode;
    3673                 :             : 
    3674                 :         614 :                 FLATCOPY(newnode, iclause, IndexClause);
    3675                 :         614 :                 MUTATE(newnode->rinfo, iclause->rinfo, RestrictInfo *);
    3676                 :         614 :                 MUTATE(newnode->indexquals, iclause->indexquals, List *);
    3677                 :         614 :                 return (Node *) newnode;
    3678                 :             :             }
    3679                 :             :             break;
    3680                 :       13869 :         case T_PlaceHolderVar:
    3681                 :             :             {
    3682                 :       13869 :                 PlaceHolderVar *phv = (PlaceHolderVar *) node;
    3683                 :             :                 PlaceHolderVar *newnode;
    3684                 :             : 
    3685                 :       13869 :                 FLATCOPY(newnode, phv, PlaceHolderVar);
    3686                 :       13869 :                 MUTATE(newnode->phexpr, phv->phexpr, Expr *);
    3687                 :             :                 /* Assume we need not copy the relids bitmapsets */
    3688                 :       13869 :                 return (Node *) newnode;
    3689                 :             :             }
    3690                 :             :             break;
    3691                 :        2456 :         case T_InferenceElem:
    3692                 :             :             {
    3693                 :        2456 :                 InferenceElem *inferenceelemdexpr = (InferenceElem *) node;
    3694                 :             :                 InferenceElem *newnode;
    3695                 :             : 
    3696                 :        2456 :                 FLATCOPY(newnode, inferenceelemdexpr, InferenceElem);
    3697                 :        2456 :                 MUTATE(newnode->expr, newnode->expr, Node *);
    3698                 :        2456 :                 return (Node *) newnode;
    3699                 :             :             }
    3700                 :             :             break;
    3701                 :       19194 :         case T_AppendRelInfo:
    3702                 :             :             {
    3703                 :       19194 :                 AppendRelInfo *appinfo = (AppendRelInfo *) node;
    3704                 :             :                 AppendRelInfo *newnode;
    3705                 :             : 
    3706                 :       19194 :                 FLATCOPY(newnode, appinfo, AppendRelInfo);
    3707                 :       19194 :                 MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
    3708                 :             :                 /* Assume nothing need be done with parent_colnos[] */
    3709                 :       19194 :                 return (Node *) newnode;
    3710                 :             :             }
    3711                 :             :             break;
    3712                 :           0 :         case T_PlaceHolderInfo:
    3713                 :             :             {
    3714                 :           0 :                 PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
    3715                 :             :                 PlaceHolderInfo *newnode;
    3716                 :             : 
    3717                 :           0 :                 FLATCOPY(newnode, phinfo, PlaceHolderInfo);
    3718                 :           0 :                 MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
    3719                 :             :                 /* Assume we need not copy the relids bitmapsets */
    3720                 :           0 :                 return (Node *) newnode;
    3721                 :             :             }
    3722                 :             :             break;
    3723                 :       69013 :         case T_RangeTblFunction:
    3724                 :             :             {
    3725                 :       69013 :                 RangeTblFunction *rtfunc = (RangeTblFunction *) node;
    3726                 :             :                 RangeTblFunction *newnode;
    3727                 :             : 
    3728                 :       69013 :                 FLATCOPY(newnode, rtfunc, RangeTblFunction);
    3729                 :       69013 :                 MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
    3730                 :             :                 /* Assume we need not copy the coldef info lists */
    3731                 :       69013 :                 return (Node *) newnode;
    3732                 :             :             }
    3733                 :             :             break;
    3734                 :         482 :         case T_TableSampleClause:
    3735                 :             :             {
    3736                 :         482 :                 TableSampleClause *tsc = (TableSampleClause *) node;
    3737                 :             :                 TableSampleClause *newnode;
    3738                 :             : 
    3739                 :         482 :                 FLATCOPY(newnode, tsc, TableSampleClause);
    3740                 :         482 :                 MUTATE(newnode->args, tsc->args, List *);
    3741                 :         482 :                 MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
    3742                 :         482 :                 return (Node *) newnode;
    3743                 :             :             }
    3744                 :             :             break;
    3745                 :         992 :         case T_TableFunc:
    3746                 :             :             {
    3747                 :         992 :                 TableFunc  *tf = (TableFunc *) node;
    3748                 :             :                 TableFunc  *newnode;
    3749                 :             : 
    3750                 :         992 :                 FLATCOPY(newnode, tf, TableFunc);
    3751                 :         992 :                 MUTATE(newnode->ns_uris, tf->ns_uris, List *);
    3752                 :         992 :                 MUTATE(newnode->docexpr, tf->docexpr, Node *);
    3753                 :         992 :                 MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
    3754                 :         992 :                 MUTATE(newnode->colexprs, tf->colexprs, List *);
    3755                 :         992 :                 MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
    3756                 :         992 :                 MUTATE(newnode->colvalexprs, tf->colvalexprs, List *);
    3757                 :         984 :                 MUTATE(newnode->passingvalexprs, tf->passingvalexprs, List *);
    3758                 :         984 :                 return (Node *) newnode;
    3759                 :             :             }
    3760                 :             :             break;
    3761                 :           0 :         default:
    3762         [ #  # ]:           0 :             elog(ERROR, "unrecognized node type: %d",
    3763                 :             :                  (int) nodeTag(node));
    3764                 :             :             break;
    3765                 :             :     }
    3766                 :             :     /* can't get here, but keep compiler happy */
    3767                 :             :     return NULL;
    3768                 :             : }
    3769                 :             : 
    3770                 :             : 
    3771                 :             : /*
    3772                 :             :  * query_tree_mutator --- initiate modification of a Query's expressions
    3773                 :             :  *
    3774                 :             :  * This routine exists just to reduce the number of places that need to know
    3775                 :             :  * where all the expression subtrees of a Query are.  Note it can be used
    3776                 :             :  * for starting a walk at top level of a Query regardless of whether the
    3777                 :             :  * mutator intends to descend into subqueries.  It is also useful for
    3778                 :             :  * descending into subqueries within a mutator.
    3779                 :             :  *
    3780                 :             :  * Some callers want to suppress mutating of certain items in the Query,
    3781                 :             :  * typically because they need to process them specially, or don't actually
    3782                 :             :  * want to recurse into subqueries.  This is supported by the flags argument,
    3783                 :             :  * which is the bitwise OR of flag values to suppress mutating of
    3784                 :             :  * indicated items.  (More flag bits may be added as needed.)
    3785                 :             :  *
    3786                 :             :  * Normally the top-level Query node itself is copied, but some callers want
    3787                 :             :  * it to be modified in-place; they must pass QTW_DONT_COPY_QUERY in flags.
    3788                 :             :  * All modified substructure is safely copied in any case.
    3789                 :             :  */
    3790                 :             : pg_attribute_no_sanitize_function()
    3791                 :             : Query *
    3792                 :       22793 : query_tree_mutator_impl(Query *query,
    3793                 :             :                         tree_mutator_callback mutator,
    3794                 :             :                         void *context,
    3795                 :             :                         int flags)
    3796                 :             : {
    3797                 :             :     Assert(query != NULL && IsA(query, Query));
    3798                 :             : 
    3799         [ +  - ]:       22793 :     if (!(flags & QTW_DONT_COPY_QUERY))
    3800                 :             :     {
    3801                 :             :         Query      *newquery;
    3802                 :             : 
    3803                 :       22793 :         FLATCOPY(newquery, query, Query);
    3804                 :       22793 :         query = newquery;
    3805                 :             :     }
    3806                 :             : 
    3807                 :       22793 :     MUTATE(query->targetList, query->targetList, List *);
    3808                 :       22793 :     MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
    3809                 :       22793 :     MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
    3810                 :       22793 :     MUTATE(query->mergeActionList, query->mergeActionList, List *);
    3811                 :       22793 :     MUTATE(query->mergeJoinCondition, query->mergeJoinCondition, Node *);
    3812                 :       22793 :     MUTATE(query->returningList, query->returningList, List *);
    3813                 :       22793 :     MUTATE(query->jointree, query->jointree, FromExpr *);
    3814                 :       22793 :     MUTATE(query->setOperations, query->setOperations, Node *);
    3815                 :       22793 :     MUTATE(query->havingQual, query->havingQual, Node *);
    3816                 :       22793 :     MUTATE(query->limitOffset, query->limitOffset, Node *);
    3817                 :       22793 :     MUTATE(query->limitCount, query->limitCount, Node *);
    3818                 :             : 
    3819                 :             :     /*
    3820                 :             :      * Most callers aren't interested in SortGroupClause nodes since those
    3821                 :             :      * don't contain actual expressions. However they do contain OIDs, which
    3822                 :             :      * may be of interest to some mutators.
    3823                 :             :      */
    3824                 :             : 
    3825         [ -  + ]:       22793 :     if ((flags & QTW_EXAMINE_SORTGROUP))
    3826                 :             :     {
    3827                 :           0 :         MUTATE(query->groupClause, query->groupClause, List *);
    3828                 :           0 :         MUTATE(query->windowClause, query->windowClause, List *);
    3829                 :           0 :         MUTATE(query->sortClause, query->sortClause, List *);
    3830                 :           0 :         MUTATE(query->distinctClause, query->distinctClause, List *);
    3831                 :             :     }
    3832                 :             :     else
    3833                 :             :     {
    3834                 :             :         /*
    3835                 :             :          * But we need to mutate the expressions under WindowClause nodes even
    3836                 :             :          * if we're not interested in SortGroupClause nodes.
    3837                 :             :          */
    3838                 :             :         List       *resultlist;
    3839                 :             :         ListCell   *temp;
    3840                 :             : 
    3841                 :       22793 :         resultlist = NIL;
    3842   [ +  +  +  +  :       22941 :         foreach(temp, query->windowClause)
                   +  + ]
    3843                 :             :         {
    3844                 :         148 :             WindowClause *wc = lfirst_node(WindowClause, temp);
    3845                 :             :             WindowClause *newnode;
    3846                 :             : 
    3847                 :         148 :             FLATCOPY(newnode, wc, WindowClause);
    3848                 :         148 :             MUTATE(newnode->startOffset, wc->startOffset, Node *);
    3849                 :         148 :             MUTATE(newnode->endOffset, wc->endOffset, Node *);
    3850                 :             : 
    3851                 :         148 :             resultlist = lappend(resultlist, (Node *) newnode);
    3852                 :             :         }
    3853                 :       22793 :         query->windowClause = resultlist;
    3854                 :             :     }
    3855                 :             : 
    3856                 :             :     /*
    3857                 :             :      * groupingSets and rowMarks are not mutated:
    3858                 :             :      *
    3859                 :             :      * groupingSets contain only ressortgroup refs (integers) which are
    3860                 :             :      * meaningless without the groupClause or tlist. Accordingly, any mutator
    3861                 :             :      * that needs to care about them needs to handle them itself in its Query
    3862                 :             :      * processing.
    3863                 :             :      *
    3864                 :             :      * rowMarks contains only rangetable indexes (and flags etc.) and
    3865                 :             :      * therefore should be handled at Query level similarly.
    3866                 :             :      */
    3867                 :             : 
    3868         [ +  - ]:       22793 :     if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
    3869                 :       22793 :         MUTATE(query->cteList, query->cteList, List *);
    3870                 :             :     else                        /* else copy CTE list as-is */
    3871                 :           0 :         query->cteList = copyObject(query->cteList);
    3872                 :       22793 :     query->rtable = range_table_mutator(query->rtable,
    3873                 :             :                                         mutator, context, flags);
    3874                 :       22793 :     return query;
    3875                 :             : }
    3876                 :             : 
    3877                 :             : /*
    3878                 :             :  * range_table_mutator is just the part of query_tree_mutator that processes
    3879                 :             :  * a query's rangetable.  This is split out since it can be useful on
    3880                 :             :  * its own.
    3881                 :             :  */
    3882                 :             : pg_attribute_no_sanitize_function()
    3883                 :             : List *
    3884                 :       22793 : range_table_mutator_impl(List *rtable,
    3885                 :             :                          tree_mutator_callback mutator,
    3886                 :             :                          void *context,
    3887                 :             :                          int flags)
    3888                 :             : {
    3889                 :       22793 :     List       *newrt = NIL;
    3890                 :             :     ListCell   *rt;
    3891                 :             : 
    3892   [ +  +  +  +  :       67993 :     foreach(rt, rtable)
                   +  + ]
    3893                 :             :     {
    3894                 :       45200 :         RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
    3895                 :             :         RangeTblEntry *newrte;
    3896                 :             : 
    3897                 :       45200 :         FLATCOPY(newrte, rte, RangeTblEntry);
    3898   [ +  +  +  +  :       45200 :         switch (rte->rtekind)
             -  +  +  +  
                      - ]
    3899                 :             :         {
    3900                 :       27641 :             case RTE_RELATION:
    3901                 :       27641 :                 MUTATE(newrte->tablesample, rte->tablesample,
    3902                 :             :                        TableSampleClause *);
    3903                 :             :                 /* we don't bother to copy eref, aliases, etc; OK? */
    3904                 :       27641 :                 break;
    3905                 :        3645 :             case RTE_SUBQUERY:
    3906         [ +  - ]:        3645 :                 if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
    3907                 :        3645 :                     MUTATE(newrte->subquery, rte->subquery, Query *);
    3908                 :             :                 else
    3909                 :             :                 {
    3910                 :             :                     /* else, copy RT subqueries as-is */
    3911                 :           0 :                     newrte->subquery = copyObject(rte->subquery);
    3912                 :             :                 }
    3913                 :        3645 :                 break;
    3914                 :        6558 :             case RTE_JOIN:
    3915         [ +  + ]:        6558 :                 if (!(flags & QTW_IGNORE_JOINALIASES))
    3916                 :        6225 :                     MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
    3917                 :             :                 else
    3918                 :             :                 {
    3919                 :             :                     /* else, copy join aliases as-is */
    3920                 :         333 :                     newrte->joinaliasvars = copyObject(rte->joinaliasvars);
    3921                 :             :                 }
    3922                 :        6558 :                 break;
    3923                 :        5614 :             case RTE_FUNCTION:
    3924                 :        5614 :                 MUTATE(newrte->functions, rte->functions, List *);
    3925                 :        5614 :                 break;
    3926                 :           0 :             case RTE_TABLEFUNC:
    3927                 :           0 :                 MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
    3928                 :           0 :                 break;
    3929                 :        1044 :             case RTE_VALUES:
    3930                 :        1044 :                 MUTATE(newrte->values_lists, rte->values_lists, List *);
    3931                 :        1044 :                 break;
    3932                 :         491 :             case RTE_CTE:
    3933                 :             :             case RTE_NAMEDTUPLESTORE:
    3934                 :             :             case RTE_RESULT:
    3935                 :             :                 /* nothing to do */
    3936                 :         491 :                 break;
    3937                 :         207 :             case RTE_GROUP:
    3938         [ +  - ]:         207 :                 if (!(flags & QTW_IGNORE_GROUPEXPRS))
    3939                 :         207 :                     MUTATE(newrte->groupexprs, rte->groupexprs, List *);
    3940                 :             :                 else
    3941                 :             :                 {
    3942                 :             :                     /* else, copy grouping exprs as-is */
    3943                 :           0 :                     newrte->groupexprs = copyObject(rte->groupexprs);
    3944                 :             :                 }
    3945                 :         207 :                 break;
    3946                 :             :         }
    3947                 :       45200 :         MUTATE(newrte->securityQuals, rte->securityQuals, List *);
    3948                 :       45200 :         newrt = lappend(newrt, newrte);
    3949                 :             :     }
    3950                 :       22793 :     return newrt;
    3951                 :             : }
    3952                 :             : 
    3953                 :             : /*
    3954                 :             :  * query_or_expression_tree_walker --- hybrid form
    3955                 :             :  *
    3956                 :             :  * This routine will invoke query_tree_walker if called on a Query node,
    3957                 :             :  * else will invoke the walker directly.  This is a useful way of starting
    3958                 :             :  * the recursion when the walker's normal change of state is not appropriate
    3959                 :             :  * for the outermost Query node.
    3960                 :             :  */
    3961                 :             : pg_attribute_no_sanitize_function()
    3962                 :             : bool
    3963                 :     3287973 : query_or_expression_tree_walker_impl(Node *node,
    3964                 :             :                                      tree_walker_callback walker,
    3965                 :             :                                      void *context,
    3966                 :             :                                      int flags)
    3967                 :             : {
    3968   [ +  +  +  + ]:     3287973 :     if (node && IsA(node, Query))
    3969                 :      315058 :         return query_tree_walker((Query *) node,
    3970                 :             :                                  walker,
    3971                 :             :                                  context,
    3972                 :             :                                  flags);
    3973                 :             :     else
    3974                 :     2972915 :         return WALK(node);
    3975                 :             : }
    3976                 :             : 
    3977                 :             : /*
    3978                 :             :  * query_or_expression_tree_mutator --- hybrid form
    3979                 :             :  *
    3980                 :             :  * This routine will invoke query_tree_mutator if called on a Query node,
    3981                 :             :  * else will invoke the mutator directly.  This is a useful way of starting
    3982                 :             :  * the recursion when the mutator's normal change of state is not appropriate
    3983                 :             :  * for the outermost Query node.
    3984                 :             :  */
    3985                 :             : pg_attribute_no_sanitize_function()
    3986                 :             : Node *
    3987                 :      486700 : query_or_expression_tree_mutator_impl(Node *node,
    3988                 :             :                                       tree_mutator_callback mutator,
    3989                 :             :                                       void *context,
    3990                 :             :                                       int flags)
    3991                 :             : {
    3992   [ +  +  +  + ]:      486700 :     if (node && IsA(node, Query))
    3993                 :        6964 :         return (Node *) query_tree_mutator((Query *) node,
    3994                 :             :                                            mutator,
    3995                 :             :                                            context,
    3996                 :             :                                            flags);
    3997                 :             :     else
    3998                 :      479736 :         return mutator(node, context);
    3999                 :             : }
    4000                 :             : 
    4001                 :             : 
    4002                 :             : /*
    4003                 :             :  * raw_expression_tree_walker --- walk raw parse trees
    4004                 :             :  *
    4005                 :             :  * This has exactly the same API as expression_tree_walker, but instead of
    4006                 :             :  * walking post-analysis parse trees, it knows how to walk the node types
    4007                 :             :  * found in raw grammar output.  (There is not currently any need for a
    4008                 :             :  * combined walker, so we keep them separate in the name of efficiency.)
    4009                 :             :  * Unlike expression_tree_walker, there is no special rule about query
    4010                 :             :  * boundaries: we descend to everything that's possibly interesting.
    4011                 :             :  *
    4012                 :             :  * Currently, the node type coverage here extends only to DML statements
    4013                 :             :  * (SELECT/INSERT/UPDATE/DELETE/MERGE) and nodes that can appear in them,
    4014                 :             :  * because this is used mainly during analysis of CTEs, and only DML
    4015                 :             :  * statements can appear in CTEs.
    4016                 :             :  */
    4017                 :             : pg_attribute_no_sanitize_function()
    4018                 :             : bool
    4019                 :     8006080 : raw_expression_tree_walker_impl(Node *node,
    4020                 :             :                                 tree_walker_callback walker,
    4021                 :             :                                 void *context)
    4022                 :             : {
    4023                 :             :     ListCell   *temp;
    4024                 :             : 
    4025                 :             :     /*
    4026                 :             :      * The walker has already visited the current node, and so we need only
    4027                 :             :      * recurse into any sub-nodes it has.
    4028                 :             :      */
    4029         [ -  + ]:     8006080 :     if (node == NULL)
    4030                 :           0 :         return false;
    4031                 :             : 
    4032                 :             :     /* Guard against stack overflow due to overly complex expressions */
    4033                 :     8006080 :     check_stack_depth();
    4034                 :             : 
    4035   [ +  +  +  +  :     8006080 :     switch (nodeTag(node))
          +  +  +  +  +  
          +  +  +  +  +  
          +  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
             +  +  +  +  
                      - ]
    4036                 :             :     {
    4037                 :      995492 :         case T_JsonFormat:
    4038                 :             :         case T_SetToDefault:
    4039                 :             :         case T_CurrentOfExpr:
    4040                 :             :         case T_SQLValueFunction:
    4041                 :             :         case T_Integer:
    4042                 :             :         case T_Float:
    4043                 :             :         case T_Boolean:
    4044                 :             :         case T_String:
    4045                 :             :         case T_BitString:
    4046                 :             :         case T_ParamRef:
    4047                 :             :         case T_A_Const:
    4048                 :             :         case T_A_Star:
    4049                 :             :         case T_MergeSupportFunc:
    4050                 :             :         case T_ReturningOption:
    4051                 :             :             /* primitive node types with no subnodes */
    4052                 :      995492 :             break;
    4053                 :      262213 :         case T_Alias:
    4054                 :             :             /* we assume the colnames list isn't interesting */
    4055                 :      262213 :             break;
    4056                 :      414631 :         case T_RangeVar:
    4057                 :      414631 :             return WALK(((RangeVar *) node)->alias);
    4058                 :         328 :         case T_GroupingFunc:
    4059                 :         328 :             return WALK(((GroupingFunc *) node)->args);
    4060                 :       42221 :         case T_SubLink:
    4061                 :             :             {
    4062                 :       42221 :                 SubLink    *sublink = (SubLink *) node;
    4063                 :             : 
    4064         [ -  + ]:       42221 :                 if (WALK(sublink->testexpr))
    4065                 :           0 :                     return true;
    4066                 :             :                 /* we assume the operName is not interesting */
    4067         [ -  + ]:       42221 :                 if (WALK(sublink->subselect))
    4068                 :           0 :                     return true;
    4069                 :             :             }
    4070                 :       42221 :             break;
    4071                 :       28240 :         case T_CaseExpr:
    4072                 :             :             {
    4073                 :       28240 :                 CaseExpr   *caseexpr = (CaseExpr *) node;
    4074                 :             : 
    4075         [ -  + ]:       28240 :                 if (WALK(caseexpr->arg))
    4076                 :           0 :                     return true;
    4077                 :             :                 /* we assume walker doesn't care about CaseWhens, either */
    4078   [ +  -  +  +  :       76063 :                 foreach(temp, caseexpr->args)
                   +  + ]
    4079                 :             :                 {
    4080                 :       47823 :                     CaseWhen   *when = lfirst_node(CaseWhen, temp);
    4081                 :             : 
    4082         [ -  + ]:       47823 :                     if (WALK(when->expr))
    4083                 :           0 :                         return true;
    4084         [ -  + ]:       47823 :                     if (WALK(when->result))
    4085                 :           0 :                         return true;
    4086                 :             :                 }
    4087         [ -  + ]:       28240 :                 if (WALK(caseexpr->defresult))
    4088                 :           0 :                     return true;
    4089                 :             :             }
    4090                 :       28240 :             break;
    4091                 :        5258 :         case T_RowExpr:
    4092                 :             :             /* Assume colnames isn't interesting */
    4093                 :        5258 :             return WALK(((RowExpr *) node)->args);
    4094                 :        3720 :         case T_CoalesceExpr:
    4095                 :        3720 :             return WALK(((CoalesceExpr *) node)->args);
    4096                 :         262 :         case T_MinMaxExpr:
    4097                 :         262 :             return WALK(((MinMaxExpr *) node)->args);
    4098                 :         415 :         case T_XmlExpr:
    4099                 :             :             {
    4100                 :         415 :                 XmlExpr    *xexpr = (XmlExpr *) node;
    4101                 :             : 
    4102         [ -  + ]:         415 :                 if (WALK(xexpr->named_args))
    4103                 :           0 :                     return true;
    4104                 :             :                 /* we assume walker doesn't care about arg_names */
    4105         [ -  + ]:         415 :                 if (WALK(xexpr->args))
    4106                 :           0 :                     return true;
    4107                 :             :             }
    4108                 :         415 :             break;
    4109                 :        1178 :         case T_JsonReturning:
    4110                 :        1178 :             return WALK(((JsonReturning *) node)->format);
    4111                 :        2942 :         case T_JsonValueExpr:
    4112                 :             :             {
    4113                 :        2942 :                 JsonValueExpr *jve = (JsonValueExpr *) node;
    4114                 :             : 
    4115         [ -  + ]:        2942 :                 if (WALK(jve->raw_expr))
    4116                 :           0 :                     return true;
    4117         [ -  + ]:        2942 :                 if (WALK(jve->formatted_expr))
    4118                 :           0 :                     return true;
    4119         [ -  + ]:        2942 :                 if (WALK(jve->format))
    4120                 :           0 :                     return true;
    4121                 :             :             }
    4122                 :        2942 :             break;
    4123                 :         108 :         case T_JsonParseExpr:
    4124                 :             :             {
    4125                 :         108 :                 JsonParseExpr *jpe = (JsonParseExpr *) node;
    4126                 :             : 
    4127         [ -  + ]:         108 :                 if (WALK(jpe->expr))
    4128                 :           0 :                     return true;
    4129         [ -  + ]:         108 :                 if (WALK(jpe->output))
    4130                 :           0 :                     return true;
    4131                 :             :             }
    4132                 :         108 :             break;
    4133                 :          70 :         case T_JsonScalarExpr:
    4134                 :             :             {
    4135                 :          70 :                 JsonScalarExpr *jse = (JsonScalarExpr *) node;
    4136                 :             : 
    4137         [ -  + ]:          70 :                 if (WALK(jse->expr))
    4138                 :           0 :                     return true;
    4139         [ -  + ]:          70 :                 if (WALK(jse->output))
    4140                 :           0 :                     return true;
    4141                 :             :             }
    4142                 :          70 :             break;
    4143                 :          68 :         case T_JsonSerializeExpr:
    4144                 :             :             {
    4145                 :          68 :                 JsonSerializeExpr *jse = (JsonSerializeExpr *) node;
    4146                 :             : 
    4147         [ -  + ]:          68 :                 if (WALK(jse->expr))
    4148                 :           0 :                     return true;
    4149         [ -  + ]:          68 :                 if (WALK(jse->output))
    4150                 :           0 :                     return true;
    4151                 :             :             }
    4152                 :          68 :             break;
    4153                 :           0 :         case T_JsonConstructorExpr:
    4154                 :             :             {
    4155                 :           0 :                 JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
    4156                 :             : 
    4157         [ #  # ]:           0 :                 if (WALK(ctor->args))
    4158                 :           0 :                     return true;
    4159         [ #  # ]:           0 :                 if (WALK(ctor->func))
    4160                 :           0 :                     return true;
    4161         [ #  # ]:           0 :                 if (WALK(ctor->coercion))
    4162                 :           0 :                     return true;
    4163         [ #  # ]:           0 :                 if (WALK(ctor->returning))
    4164                 :           0 :                     return true;
    4165                 :             :             }
    4166                 :           0 :             break;
    4167                 :         288 :         case T_JsonIsPredicate:
    4168                 :         288 :             return WALK(((JsonIsPredicate *) node)->expr);
    4169                 :         264 :         case T_JsonArgument:
    4170                 :         264 :             return WALK(((JsonArgument *) node)->val);
    4171                 :        1040 :         case T_JsonFuncExpr:
    4172                 :             :             {
    4173                 :        1040 :                 JsonFuncExpr *jfe = (JsonFuncExpr *) node;
    4174                 :             : 
    4175         [ -  + ]:        1040 :                 if (WALK(jfe->context_item))
    4176                 :           0 :                     return true;
    4177         [ -  + ]:        1040 :                 if (WALK(jfe->pathspec))
    4178                 :           0 :                     return true;
    4179         [ -  + ]:        1040 :                 if (WALK(jfe->passing))
    4180                 :           0 :                     return true;
    4181         [ -  + ]:        1040 :                 if (WALK(jfe->output))
    4182                 :           0 :                     return true;
    4183         [ -  + ]:        1040 :                 if (WALK(jfe->on_empty))
    4184                 :           0 :                     return true;
    4185         [ -  + ]:        1040 :                 if (WALK(jfe->on_error))
    4186                 :           0 :                     return true;
    4187                 :             :             }
    4188                 :        1040 :             break;
    4189                 :         824 :         case T_JsonBehavior:
    4190                 :             :             {
    4191                 :         824 :                 JsonBehavior *jb = (JsonBehavior *) node;
    4192                 :             : 
    4193         [ -  + ]:         824 :                 if (WALK(jb->expr))
    4194                 :           0 :                     return true;
    4195                 :             :             }
    4196                 :         824 :             break;
    4197                 :         480 :         case T_JsonTable:
    4198                 :             :             {
    4199                 :         480 :                 JsonTable  *jt = (JsonTable *) node;
    4200                 :             : 
    4201         [ -  + ]:         480 :                 if (WALK(jt->context_item))
    4202                 :           0 :                     return true;
    4203         [ -  + ]:         480 :                 if (WALK(jt->pathspec))
    4204                 :           0 :                     return true;
    4205         [ -  + ]:         480 :                 if (WALK(jt->passing))
    4206                 :           0 :                     return true;
    4207         [ -  + ]:         480 :                 if (WALK(jt->columns))
    4208                 :           0 :                     return true;
    4209         [ -  + ]:         480 :                 if (WALK(jt->on_error))
    4210                 :           0 :                     return true;
    4211                 :             :             }
    4212                 :         480 :             break;
    4213                 :        1712 :         case T_JsonTableColumn:
    4214                 :             :             {
    4215                 :        1712 :                 JsonTableColumn *jtc = (JsonTableColumn *) node;
    4216                 :             : 
    4217         [ -  + ]:        1712 :                 if (WALK(jtc->typeName))
    4218                 :           0 :                     return true;
    4219         [ -  + ]:        1712 :                 if (WALK(jtc->on_empty))
    4220                 :           0 :                     return true;
    4221         [ -  + ]:        1712 :                 if (WALK(jtc->on_error))
    4222                 :           0 :                     return true;
    4223         [ -  + ]:        1712 :                 if (WALK(jtc->columns))
    4224                 :           0 :                     return true;
    4225                 :             :             }
    4226                 :        1712 :             break;
    4227                 :         480 :         case T_JsonTablePathSpec:
    4228                 :         480 :             return WALK(((JsonTablePathSpec *) node)->string);
    4229                 :       15573 :         case T_NullTest:
    4230                 :       15573 :             return WALK(((NullTest *) node)->arg);
    4231                 :         724 :         case T_BooleanTest:
    4232                 :         724 :             return WALK(((BooleanTest *) node)->arg);
    4233                 :       71636 :         case T_JoinExpr:
    4234                 :             :             {
    4235                 :       71636 :                 JoinExpr   *join = (JoinExpr *) node;
    4236                 :             : 
    4237         [ -  + ]:       71636 :                 if (WALK(join->larg))
    4238                 :           0 :                     return true;
    4239         [ -  + ]:       71636 :                 if (WALK(join->rarg))
    4240                 :           0 :                     return true;
    4241         [ -  + ]:       71636 :                 if (WALK(join->quals))
    4242                 :           0 :                     return true;
    4243         [ -  + ]:       71636 :                 if (WALK(join->alias))
    4244                 :           0 :                     return true;
    4245                 :             :                 /* using list is deemed uninteresting */
    4246                 :             :             }
    4247                 :       71636 :             break;
    4248                 :          20 :         case T_IntoClause:
    4249                 :             :             {
    4250                 :          20 :                 IntoClause *into = (IntoClause *) node;
    4251                 :             : 
    4252         [ -  + ]:          20 :                 if (WALK(into->rel))
    4253                 :           0 :                     return true;
    4254                 :             :                 /* colNames, options are deemed uninteresting */
    4255                 :             :                 /* viewQuery should be null in raw parsetree, but check it */
    4256         [ -  + ]:          20 :                 if (WALK(into->viewQuery))
    4257                 :           0 :                     return true;
    4258                 :             :             }
    4259                 :          20 :             break;
    4260                 :     1506136 :         case T_List:
    4261   [ +  -  +  +  :     4214978 :             foreach(temp, (List *) node)
                   +  + ]
    4262                 :             :             {
    4263         [ -  + ]:     2708910 :                 if (WALK((Node *) lfirst(temp)))
    4264                 :           0 :                     return true;
    4265                 :             :             }
    4266                 :     1506068 :             break;
    4267                 :       45445 :         case T_InsertStmt:
    4268                 :             :             {
    4269                 :       45445 :                 InsertStmt *stmt = (InsertStmt *) node;
    4270                 :             : 
    4271         [ -  + ]:       45445 :                 if (WALK(stmt->relation))
    4272                 :           0 :                     return true;
    4273         [ -  + ]:       45445 :                 if (WALK(stmt->cols))
    4274                 :           0 :                     return true;
    4275         [ -  + ]:       45445 :                 if (WALK(stmt->selectStmt))
    4276                 :           0 :                     return true;
    4277         [ -  + ]:       45445 :                 if (WALK(stmt->onConflictClause))
    4278                 :           0 :                     return true;
    4279         [ -  + ]:       45445 :                 if (WALK(stmt->returningClause))
    4280                 :           0 :                     return true;
    4281         [ -  + ]:       45445 :                 if (WALK(stmt->withClause))
    4282                 :           0 :                     return true;
    4283                 :             :             }
    4284                 :       45445 :             break;
    4285                 :        2985 :         case T_DeleteStmt:
    4286                 :             :             {
    4287                 :        2985 :                 DeleteStmt *stmt = (DeleteStmt *) node;
    4288                 :             : 
    4289         [ -  + ]:        2985 :                 if (WALK(stmt->relation))
    4290                 :           0 :                     return true;
    4291         [ -  + ]:        2985 :                 if (WALK(stmt->usingClause))
    4292                 :           0 :                     return true;
    4293         [ -  + ]:        2985 :                 if (WALK(stmt->whereClause))
    4294                 :           0 :                     return true;
    4295         [ -  + ]:        2985 :                 if (WALK(stmt->returningClause))
    4296                 :           0 :                     return true;
    4297         [ -  + ]:        2985 :                 if (WALK(stmt->withClause))
    4298                 :           0 :                     return true;
    4299                 :             :             }
    4300                 :        2985 :             break;
    4301                 :        8814 :         case T_UpdateStmt:
    4302                 :             :             {
    4303                 :        8814 :                 UpdateStmt *stmt = (UpdateStmt *) node;
    4304                 :             : 
    4305         [ -  + ]:        8814 :                 if (WALK(stmt->relation))
    4306                 :           0 :                     return true;
    4307         [ -  + ]:        8814 :                 if (WALK(stmt->targetList))
    4308                 :           0 :                     return true;
    4309         [ -  + ]:        8814 :                 if (WALK(stmt->whereClause))
    4310                 :           0 :                     return true;
    4311         [ -  + ]:        8814 :                 if (WALK(stmt->fromClause))
    4312                 :           0 :                     return true;
    4313         [ -  + ]:        8814 :                 if (WALK(stmt->returningClause))
    4314                 :           0 :                     return true;
    4315         [ -  + ]:        8814 :                 if (WALK(stmt->withClause))
    4316                 :           0 :                     return true;
    4317                 :             :             }
    4318                 :        8814 :             break;
    4319                 :        1423 :         case T_MergeStmt:
    4320                 :             :             {
    4321                 :        1423 :                 MergeStmt  *stmt = (MergeStmt *) node;
    4322                 :             : 
    4323         [ -  + ]:        1423 :                 if (WALK(stmt->relation))
    4324                 :           0 :                     return true;
    4325         [ -  + ]:        1423 :                 if (WALK(stmt->sourceRelation))
    4326                 :           0 :                     return true;
    4327         [ -  + ]:        1423 :                 if (WALK(stmt->joinCondition))
    4328                 :           0 :                     return true;
    4329         [ -  + ]:        1423 :                 if (WALK(stmt->mergeWhenClauses))
    4330                 :           0 :                     return true;
    4331         [ -  + ]:        1423 :                 if (WALK(stmt->returningClause))
    4332                 :           0 :                     return true;
    4333         [ -  + ]:        1423 :                 if (WALK(stmt->withClause))
    4334                 :           0 :                     return true;
    4335                 :             :             }
    4336                 :        1423 :             break;
    4337                 :        2199 :         case T_MergeWhenClause:
    4338                 :             :             {
    4339                 :        2199 :                 MergeWhenClause *mergeWhenClause = (MergeWhenClause *) node;
    4340                 :             : 
    4341         [ -  + ]:        2199 :                 if (WALK(mergeWhenClause->condition))
    4342                 :           0 :                     return true;
    4343         [ -  + ]:        2199 :                 if (WALK(mergeWhenClause->targetList))
    4344                 :           0 :                     return true;
    4345         [ -  + ]:        2199 :                 if (WALK(mergeWhenClause->values))
    4346                 :           0 :                     return true;
    4347                 :             :             }
    4348                 :        2199 :             break;
    4349                 :        2655 :         case T_ReturningClause:
    4350                 :             :             {
    4351                 :        2655 :                 ReturningClause *returning = (ReturningClause *) node;
    4352                 :             : 
    4353         [ -  + ]:        2655 :                 if (WALK(returning->options))
    4354                 :           0 :                     return true;
    4355         [ -  + ]:        2655 :                 if (WALK(returning->exprs))
    4356                 :           0 :                     return true;
    4357                 :             :             }
    4358                 :        2655 :             break;
    4359                 :      468635 :         case T_SelectStmt:
    4360                 :             :             {
    4361                 :      468635 :                 SelectStmt *stmt = (SelectStmt *) node;
    4362                 :             : 
    4363         [ -  + ]:      468635 :                 if (WALK(stmt->distinctClause))
    4364                 :           0 :                     return true;
    4365         [ -  + ]:      468635 :                 if (WALK(stmt->intoClause))
    4366                 :           0 :                     return true;
    4367         [ -  + ]:      468635 :                 if (WALK(stmt->targetList))
    4368                 :           0 :                     return true;
    4369         [ -  + ]:      468631 :                 if (WALK(stmt->fromClause))
    4370                 :           0 :                     return true;
    4371         [ -  + ]:      468575 :                 if (WALK(stmt->whereClause))
    4372                 :           0 :                     return true;
    4373         [ -  + ]:      468571 :                 if (WALK(stmt->groupClause))
    4374                 :           0 :                     return true;
    4375         [ -  + ]:      468571 :                 if (WALK(stmt->havingClause))
    4376                 :           0 :                     return true;
    4377         [ -  + ]:      468571 :                 if (WALK(stmt->windowClause))
    4378                 :           0 :                     return true;
    4379         [ -  + ]:      468571 :                 if (WALK(stmt->valuesLists))
    4380                 :           0 :                     return true;
    4381         [ -  + ]:      468571 :                 if (WALK(stmt->sortClause))
    4382                 :           0 :                     return true;
    4383         [ -  + ]:      468571 :                 if (WALK(stmt->limitOffset))
    4384                 :           0 :                     return true;
    4385         [ -  + ]:      468571 :                 if (WALK(stmt->limitCount))
    4386                 :           0 :                     return true;
    4387         [ -  + ]:      468571 :                 if (WALK(stmt->lockingClause))
    4388                 :           0 :                     return true;
    4389         [ -  + ]:      468571 :                 if (WALK(stmt->withClause))
    4390                 :           0 :                     return true;
    4391         [ -  + ]:      468571 :                 if (WALK(stmt->larg))
    4392                 :           0 :                     return true;
    4393         [ -  + ]:      468571 :                 if (WALK(stmt->rarg))
    4394                 :           0 :                     return true;
    4395                 :             :             }
    4396                 :      468563 :             break;
    4397                 :           0 :         case T_PLAssignStmt:
    4398                 :             :             {
    4399                 :           0 :                 PLAssignStmt *stmt = (PLAssignStmt *) node;
    4400                 :             : 
    4401         [ #  # ]:           0 :                 if (WALK(stmt->indirection))
    4402                 :           0 :                     return true;
    4403         [ #  # ]:           0 :                 if (WALK(stmt->val))
    4404                 :           0 :                     return true;
    4405                 :             :             }
    4406                 :           0 :             break;
    4407                 :      521449 :         case T_A_Expr:
    4408                 :             :             {
    4409                 :      521449 :                 A_Expr     *expr = (A_Expr *) node;
    4410                 :             : 
    4411         [ -  + ]:      521449 :                 if (WALK(expr->lexpr))
    4412                 :           0 :                     return true;
    4413         [ -  + ]:      521449 :                 if (WALK(expr->rexpr))
    4414                 :           0 :                     return true;
    4415                 :             :                 /* operator name is deemed uninteresting */
    4416                 :             :             }
    4417                 :      521449 :             break;
    4418                 :      169268 :         case T_BoolExpr:
    4419                 :             :             {
    4420                 :      169268 :                 BoolExpr   *expr = (BoolExpr *) node;
    4421                 :             : 
    4422         [ -  + ]:      169268 :                 if (WALK(expr->args))
    4423                 :           0 :                     return true;
    4424                 :             :             }
    4425                 :      169268 :             break;
    4426                 :     1534274 :         case T_ColumnRef:
    4427                 :             :             /* we assume the fields contain nothing interesting */
    4428                 :     1534274 :             break;
    4429                 :      292774 :         case T_FuncCall:
    4430                 :             :             {
    4431                 :      292774 :                 FuncCall   *fcall = (FuncCall *) node;
    4432                 :             : 
    4433         [ -  + ]:      292774 :                 if (WALK(fcall->args))
    4434                 :           0 :                     return true;
    4435         [ -  + ]:      292774 :                 if (WALK(fcall->agg_order))
    4436                 :           0 :                     return true;
    4437         [ -  + ]:      292774 :                 if (WALK(fcall->agg_filter))
    4438                 :           0 :                     return true;
    4439         [ -  + ]:      292774 :                 if (WALK(fcall->over))
    4440                 :           0 :                     return true;
    4441                 :             :                 /* function name is deemed uninteresting */
    4442                 :             :             }
    4443                 :      292774 :             break;
    4444                 :       25519 :         case T_NamedArgExpr:
    4445                 :       25519 :             return WALK(((NamedArgExpr *) node)->arg);
    4446                 :       13332 :         case T_A_Indices:
    4447                 :             :             {
    4448                 :       13332 :                 A_Indices  *indices = (A_Indices *) node;
    4449                 :             : 
    4450         [ -  + ]:       13332 :                 if (WALK(indices->lidx))
    4451                 :           0 :                     return true;
    4452         [ -  + ]:       13332 :                 if (WALK(indices->uidx))
    4453                 :           0 :                     return true;
    4454                 :             :             }
    4455                 :       13332 :             break;
    4456                 :       22072 :         case T_A_Indirection:
    4457                 :             :             {
    4458                 :       22072 :                 A_Indirection *indir = (A_Indirection *) node;
    4459                 :             : 
    4460         [ -  + ]:       22072 :                 if (WALK(indir->arg))
    4461                 :           0 :                     return true;
    4462         [ -  + ]:       22072 :                 if (WALK(indir->indirection))
    4463                 :           0 :                     return true;
    4464                 :             :             }
    4465                 :       22072 :             break;
    4466                 :        6644 :         case T_A_ArrayExpr:
    4467                 :        6644 :             return WALK(((A_ArrayExpr *) node)->elements);
    4468                 :      906054 :         case T_ResTarget:
    4469                 :             :             {
    4470                 :      906054 :                 ResTarget  *rt = (ResTarget *) node;
    4471                 :             : 
    4472         [ -  + ]:      906054 :                 if (WALK(rt->indirection))
    4473                 :           0 :                     return true;
    4474         [ -  + ]:      906054 :                 if (WALK(rt->val))
    4475                 :           0 :                     return true;
    4476                 :             :             }
    4477                 :      906050 :             break;
    4478                 :         261 :         case T_MultiAssignRef:
    4479                 :         261 :             return WALK(((MultiAssignRef *) node)->source);
    4480                 :      224515 :         case T_TypeCast:
    4481                 :             :             {
    4482                 :      224515 :                 TypeCast   *tc = (TypeCast *) node;
    4483                 :             : 
    4484         [ -  + ]:      224515 :                 if (WALK(tc->arg))
    4485                 :           0 :                     return true;
    4486         [ -  + ]:      224515 :                 if (WALK(tc->typeName))
    4487                 :           0 :                     return true;
    4488                 :             :             }
    4489                 :      224515 :             break;
    4490                 :        6952 :         case T_CollateClause:
    4491                 :        6952 :             return WALK(((CollateClause *) node)->arg);
    4492                 :       77068 :         case T_SortBy:
    4493                 :       77068 :             return WALK(((SortBy *) node)->node);
    4494                 :        3670 :         case T_WindowDef:
    4495                 :             :             {
    4496                 :        3670 :                 WindowDef  *wd = (WindowDef *) node;
    4497                 :             : 
    4498         [ -  + ]:        3670 :                 if (WALK(wd->partitionClause))
    4499                 :           0 :                     return true;
    4500         [ -  + ]:        3670 :                 if (WALK(wd->orderClause))
    4501                 :           0 :                     return true;
    4502         [ -  + ]:        3670 :                 if (WALK(wd->startOffset))
    4503                 :           0 :                     return true;
    4504         [ -  + ]:        3670 :                 if (WALK(wd->endOffset))
    4505                 :           0 :                     return true;
    4506                 :             :             }
    4507                 :        3670 :             break;
    4508                 :       17394 :         case T_RangeSubselect:
    4509                 :             :             {
    4510                 :       17394 :                 RangeSubselect *rs = (RangeSubselect *) node;
    4511                 :             : 
    4512         [ -  + ]:       17394 :                 if (WALK(rs->subquery))
    4513                 :           0 :                     return true;
    4514         [ -  + ]:       17390 :                 if (WALK(rs->alias))
    4515                 :           0 :                     return true;
    4516                 :             :             }
    4517                 :       17390 :             break;
    4518                 :       41481 :         case T_RangeFunction:
    4519                 :             :             {
    4520                 :       41481 :                 RangeFunction *rf = (RangeFunction *) node;
    4521                 :             : 
    4522         [ -  + ]:       41481 :                 if (WALK(rf->functions))
    4523                 :           0 :                     return true;
    4524         [ -  + ]:       41481 :                 if (WALK(rf->alias))
    4525                 :           0 :                     return true;
    4526         [ -  + ]:       41481 :                 if (WALK(rf->coldeflist))
    4527                 :           0 :                     return true;
    4528                 :             :             }
    4529                 :       41481 :             break;
    4530                 :         234 :         case T_RangeTableSample:
    4531                 :             :             {
    4532                 :         234 :                 RangeTableSample *rts = (RangeTableSample *) node;
    4533                 :             : 
    4534         [ -  + ]:         234 :                 if (WALK(rts->relation))
    4535                 :           0 :                     return true;
    4536                 :             :                 /* method name is deemed uninteresting */
    4537         [ -  + ]:         234 :                 if (WALK(rts->args))
    4538                 :           0 :                     return true;
    4539         [ -  + ]:         234 :                 if (WALK(rts->repeatable))
    4540                 :           0 :                     return true;
    4541                 :             :             }
    4542                 :         234 :             break;
    4543                 :         154 :         case T_RangeTableFunc:
    4544                 :             :             {
    4545                 :         154 :                 RangeTableFunc *rtf = (RangeTableFunc *) node;
    4546                 :             : 
    4547         [ -  + ]:         154 :                 if (WALK(rtf->docexpr))
    4548                 :           0 :                     return true;
    4549         [ -  + ]:         154 :                 if (WALK(rtf->rowexpr))
    4550                 :           0 :                     return true;
    4551         [ -  + ]:         154 :                 if (WALK(rtf->namespaces))
    4552                 :           0 :                     return true;
    4553         [ -  + ]:         154 :                 if (WALK(rtf->columns))
    4554                 :           0 :                     return true;
    4555         [ -  + ]:         154 :                 if (WALK(rtf->alias))
    4556                 :           0 :                     return true;
    4557                 :             :             }
    4558                 :         154 :             break;
    4559                 :         545 :         case T_RangeTableFuncCol:
    4560                 :             :             {
    4561                 :         545 :                 RangeTableFuncCol *rtfc = (RangeTableFuncCol *) node;
    4562                 :             : 
    4563         [ -  + ]:         545 :                 if (WALK(rtfc->colexpr))
    4564                 :           0 :                     return true;
    4565         [ -  + ]:         545 :                 if (WALK(rtfc->coldefexpr))
    4566                 :           0 :                     return true;
    4567                 :             :             }
    4568                 :         545 :             break;
    4569                 :      228094 :         case T_TypeName:
    4570                 :             :             {
    4571                 :      228094 :                 TypeName   *tn = (TypeName *) node;
    4572                 :             : 
    4573         [ -  + ]:      228094 :                 if (WALK(tn->typmods))
    4574                 :           0 :                     return true;
    4575         [ -  + ]:      228094 :                 if (WALK(tn->arrayBounds))
    4576                 :           0 :                     return true;
    4577                 :             :                 /* type name itself is deemed uninteresting */
    4578                 :             :             }
    4579                 :      228094 :             break;
    4580                 :        1189 :         case T_ColumnDef:
    4581                 :             :             {
    4582                 :        1189 :                 ColumnDef  *coldef = (ColumnDef *) node;
    4583                 :             : 
    4584         [ -  + ]:        1189 :                 if (WALK(coldef->typeName))
    4585                 :           0 :                     return true;
    4586         [ -  + ]:        1189 :                 if (WALK(coldef->raw_default))
    4587                 :           0 :                     return true;
    4588         [ -  + ]:        1189 :                 if (WALK(coldef->collClause))
    4589                 :           0 :                     return true;
    4590                 :             :                 /* for now, constraints are ignored */
    4591                 :             :             }
    4592                 :        1189 :             break;
    4593                 :        1612 :         case T_IndexElem:
    4594                 :             :             {
    4595                 :        1612 :                 IndexElem  *indelem = (IndexElem *) node;
    4596                 :             : 
    4597         [ -  + ]:        1612 :                 if (WALK(indelem->expr))
    4598                 :           0 :                     return true;
    4599                 :             :                 /* collation and opclass names are deemed uninteresting */
    4600                 :             :             }
    4601                 :        1612 :             break;
    4602                 :        1236 :         case T_GroupingSet:
    4603                 :        1236 :             return WALK(((GroupingSet *) node)->content);
    4604                 :        8012 :         case T_LockingClause:
    4605                 :        8012 :             return WALK(((LockingClause *) node)->lockedRels);
    4606                 :         144 :         case T_XmlSerialize:
    4607                 :             :             {
    4608                 :         144 :                 XmlSerialize *xs = (XmlSerialize *) node;
    4609                 :             : 
    4610         [ -  + ]:         144 :                 if (WALK(xs->expr))
    4611                 :           0 :                     return true;
    4612         [ -  + ]:         144 :                 if (WALK(xs->typeName))
    4613                 :           0 :                     return true;
    4614                 :             :             }
    4615                 :         144 :             break;
    4616                 :        3337 :         case T_WithClause:
    4617                 :        3337 :             return WALK(((WithClause *) node)->ctes);
    4618                 :        1496 :         case T_InferClause:
    4619                 :             :             {
    4620                 :        1496 :                 InferClause *stmt = (InferClause *) node;
    4621                 :             : 
    4622         [ -  + ]:        1496 :                 if (WALK(stmt->indexElems))
    4623                 :           0 :                     return true;
    4624         [ -  + ]:        1496 :                 if (WALK(stmt->whereClause))
    4625                 :           0 :                     return true;
    4626                 :             :             }
    4627                 :        1496 :             break;
    4628                 :        1648 :         case T_OnConflictClause:
    4629                 :             :             {
    4630                 :        1648 :                 OnConflictClause *stmt = (OnConflictClause *) node;
    4631                 :             : 
    4632         [ -  + ]:        1648 :                 if (WALK(stmt->infer))
    4633                 :           0 :                     return true;
    4634         [ -  + ]:        1648 :                 if (WALK(stmt->targetList))
    4635                 :           0 :                     return true;
    4636         [ -  + ]:        1648 :                 if (WALK(stmt->whereClause))
    4637                 :           0 :                     return true;
    4638                 :             :             }
    4639                 :        1648 :             break;
    4640                 :        4123 :         case T_CommonTableExpr:
    4641                 :             :             /* search_clause and cycle_clause are not interesting here */
    4642                 :        4123 :             return WALK(((CommonTableExpr *) node)->ctequery);
    4643                 :        1178 :         case T_JsonOutput:
    4644                 :             :             {
    4645                 :        1178 :                 JsonOutput *out = (JsonOutput *) node;
    4646                 :             : 
    4647         [ -  + ]:        1178 :                 if (WALK(out->typeName))
    4648                 :           0 :                     return true;
    4649         [ -  + ]:        1178 :                 if (WALK(out->returning))
    4650                 :           0 :                     return true;
    4651                 :             :             }
    4652                 :        1178 :             break;
    4653                 :         570 :         case T_JsonKeyValue:
    4654                 :             :             {
    4655                 :         570 :                 JsonKeyValue *jkv = (JsonKeyValue *) node;
    4656                 :             : 
    4657         [ -  + ]:         570 :                 if (WALK(jkv->key))
    4658                 :           0 :                     return true;
    4659         [ -  + ]:         570 :                 if (WALK(jkv->value))
    4660                 :           0 :                     return true;
    4661                 :             :             }
    4662                 :         570 :             break;
    4663                 :         310 :         case T_JsonObjectConstructor:
    4664                 :             :             {
    4665                 :         310 :                 JsonObjectConstructor *joc = (JsonObjectConstructor *) node;
    4666                 :             : 
    4667         [ -  + ]:         310 :                 if (WALK(joc->output))
    4668                 :           0 :                     return true;
    4669         [ -  + ]:         310 :                 if (WALK(joc->exprs))
    4670                 :           0 :                     return true;
    4671                 :             :             }
    4672                 :         310 :             break;
    4673                 :         144 :         case T_JsonArrayConstructor:
    4674                 :             :             {
    4675                 :         144 :                 JsonArrayConstructor *jac = (JsonArrayConstructor *) node;
    4676                 :             : 
    4677         [ -  + ]:         144 :                 if (WALK(jac->output))
    4678                 :           0 :                     return true;
    4679         [ -  + ]:         144 :                 if (WALK(jac->exprs))
    4680                 :           0 :                     return true;
    4681                 :             :             }
    4682                 :         144 :             break;
    4683                 :         376 :         case T_JsonAggConstructor:
    4684                 :             :             {
    4685                 :         376 :                 JsonAggConstructor *ctor = (JsonAggConstructor *) node;
    4686                 :             : 
    4687         [ -  + ]:         376 :                 if (WALK(ctor->output))
    4688                 :           0 :                     return true;
    4689         [ -  + ]:         376 :                 if (WALK(ctor->agg_order))
    4690                 :           0 :                     return true;
    4691         [ -  + ]:         376 :                 if (WALK(ctor->agg_filter))
    4692                 :           0 :                     return true;
    4693         [ -  + ]:         376 :                 if (WALK(ctor->over))
    4694                 :           0 :                     return true;
    4695                 :             :             }
    4696                 :         376 :             break;
    4697                 :         152 :         case T_JsonObjectAgg:
    4698                 :             :             {
    4699                 :         152 :                 JsonObjectAgg *joa = (JsonObjectAgg *) node;
    4700                 :             : 
    4701         [ -  + ]:         152 :                 if (WALK(joa->constructor))
    4702                 :           0 :                     return true;
    4703         [ -  + ]:         152 :                 if (WALK(joa->arg))
    4704                 :           0 :                     return true;
    4705                 :             :             }
    4706                 :         152 :             break;
    4707                 :         224 :         case T_JsonArrayAgg:
    4708                 :             :             {
    4709                 :         224 :                 JsonArrayAgg *jaa = (JsonArrayAgg *) node;
    4710                 :             : 
    4711         [ -  + ]:         224 :                 if (WALK(jaa->constructor))
    4712                 :           0 :                     return true;
    4713         [ -  + ]:         224 :                 if (WALK(jaa->arg))
    4714                 :           0 :                     return true;
    4715                 :             :             }
    4716                 :         224 :             break;
    4717                 :          96 :         case T_JsonArrayQueryConstructor:
    4718                 :             :             {
    4719                 :          96 :                 JsonArrayQueryConstructor *jaqc = (JsonArrayQueryConstructor *) node;
    4720                 :             : 
    4721         [ -  + ]:          96 :                 if (WALK(jaqc->output))
    4722                 :           0 :                     return true;
    4723         [ -  + ]:          96 :                 if (WALK(jaqc->query))
    4724                 :           0 :                     return true;
    4725                 :             :             }
    4726                 :          96 :             break;
    4727                 :           0 :         default:
    4728         [ #  # ]:           0 :             elog(ERROR, "unrecognized node type: %d",
    4729                 :             :                  (int) nodeTag(node));
    4730                 :             :             break;
    4731                 :             :     }
    4732                 :     7430074 :     return false;
    4733                 :             : }
    4734                 :             : 
    4735                 :             : /*
    4736                 :             :  * planstate_tree_walker --- walk plan state trees
    4737                 :             :  *
    4738                 :             :  * The walker has already visited the current node, and so we need only
    4739                 :             :  * recurse into any sub-nodes it has.
    4740                 :             :  */
    4741                 :             : pg_attribute_no_sanitize_function()
    4742                 :             : bool
    4743                 :      914209 : planstate_tree_walker_impl(PlanState *planstate,
    4744                 :             :                            planstate_tree_walker_callback walker,
    4745                 :             :                            void *context)
    4746                 :             : {
    4747                 :      914209 :     Plan       *plan = planstate->plan;
    4748                 :             :     ListCell   *lc;
    4749                 :             : 
    4750                 :             :     /* We don't need implicit coercions to Node here */
    4751                 :             : #define PSWALK(n) walker(n, context)
    4752                 :             : 
    4753                 :             :     /* Guard against stack overflow due to overly complex plan trees */
    4754                 :      914209 :     check_stack_depth();
    4755                 :             : 
    4756                 :             :     /* initPlan-s */
    4757         [ -  + ]:      914209 :     if (planstate_walk_subplans(planstate->initPlan, walker, context))
    4758                 :           0 :         return true;
    4759                 :             : 
    4760                 :             :     /* lefttree */
    4761         [ +  + ]:      914209 :     if (outerPlanState(planstate))
    4762                 :             :     {
    4763         [ -  + ]:      362945 :         if (PSWALK(outerPlanState(planstate)))
    4764                 :           0 :             return true;
    4765                 :             :     }
    4766                 :             : 
    4767                 :             :     /* righttree */
    4768         [ +  + ]:      914209 :     if (innerPlanState(planstate))
    4769                 :             :     {
    4770         [ -  + ]:      102588 :         if (PSWALK(innerPlanState(planstate)))
    4771                 :           0 :             return true;
    4772                 :             :     }
    4773                 :             : 
    4774                 :             :     /* special child plans */
    4775   [ +  +  +  +  :      914209 :     switch (nodeTag(plan))
                +  +  + ]
    4776                 :             :     {
    4777                 :       13009 :         case T_Append:
    4778         [ -  + ]:       13009 :             if (planstate_walk_members(((AppendState *) planstate)->appendplans,
    4779                 :             :                                        ((AppendState *) planstate)->as_nplans,
    4780                 :             :                                        walker, context))
    4781                 :           0 :                 return true;
    4782                 :       13009 :             break;
    4783                 :         414 :         case T_MergeAppend:
    4784         [ -  + ]:         414 :             if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
    4785                 :             :                                        ((MergeAppendState *) planstate)->ms_nplans,
    4786                 :             :                                        walker, context))
    4787                 :           0 :                 return true;
    4788                 :         414 :             break;
    4789                 :         150 :         case T_BitmapAnd:
    4790         [ -  + ]:         150 :             if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
    4791                 :             :                                        ((BitmapAndState *) planstate)->nplans,
    4792                 :             :                                        walker, context))
    4793                 :           0 :                 return true;
    4794                 :         150 :             break;
    4795                 :         270 :         case T_BitmapOr:
    4796         [ -  + ]:         270 :             if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
    4797                 :             :                                        ((BitmapOrState *) planstate)->nplans,
    4798                 :             :                                        walker, context))
    4799                 :           0 :                 return true;
    4800                 :         270 :             break;
    4801                 :       13724 :         case T_SubqueryScan:
    4802         [ -  + ]:       13724 :             if (PSWALK(((SubqueryScanState *) planstate)->subplan))
    4803                 :           0 :                 return true;
    4804                 :       13724 :             break;
    4805                 :          14 :         case T_CustomScan:
    4806   [ -  +  -  -  :          14 :             foreach(lc, ((CustomScanState *) planstate)->custom_ps)
                   -  + ]
    4807                 :             :             {
    4808         [ #  # ]:           0 :                 if (PSWALK(lfirst(lc)))
    4809                 :           0 :                     return true;
    4810                 :             :             }
    4811                 :          14 :             break;
    4812                 :      886628 :         default:
    4813                 :      886628 :             break;
    4814                 :             :     }
    4815                 :             : 
    4816                 :             :     /* subPlan-s */
    4817         [ -  + ]:      914209 :     if (planstate_walk_subplans(planstate->subPlan, walker, context))
    4818                 :           0 :         return true;
    4819                 :             : 
    4820                 :      914209 :     return false;
    4821                 :             : }
    4822                 :             : 
    4823                 :             : /*
    4824                 :             :  * Walk a list of SubPlans (or initPlans, which also use SubPlan nodes).
    4825                 :             :  */
    4826                 :             : pg_attribute_no_sanitize_function()
    4827                 :             : static bool
    4828                 :     1828418 : planstate_walk_subplans(List *plans,
    4829                 :             :                         planstate_tree_walker_callback walker,
    4830                 :             :                         void *context)
    4831                 :             : {
    4832                 :             :     ListCell   *lc;
    4833                 :             : 
    4834   [ +  +  +  +  :     1856310 :     foreach(lc, plans)
                   +  + ]
    4835                 :             :     {
    4836                 :       27892 :         SubPlanState *sps = lfirst_node(SubPlanState, lc);
    4837                 :             : 
    4838         [ -  + ]:       27892 :         if (PSWALK(sps->planstate))
    4839                 :           0 :             return true;
    4840                 :             :     }
    4841                 :             : 
    4842                 :     1828418 :     return false;
    4843                 :             : }
    4844                 :             : 
    4845                 :             : /*
    4846                 :             :  * Walk the constituent plans of a ModifyTable, Append, MergeAppend,
    4847                 :             :  * BitmapAnd, or BitmapOr node.
    4848                 :             :  */
    4849                 :             : pg_attribute_no_sanitize_function()
    4850                 :             : static bool
    4851                 :       13843 : planstate_walk_members(PlanState **planstates, int nplans,
    4852                 :             :                        planstate_tree_walker_callback walker,
    4853                 :             :                        void *context)
    4854                 :             : {
    4855         [ +  + ]:       58714 :     for (int j = 0; j < nplans; j++)
    4856                 :             :     {
    4857         [ -  + ]:       44871 :         if (PSWALK(planstates[j]))
    4858                 :           0 :             return true;
    4859                 :             :     }
    4860                 :             : 
    4861                 :       13843 :     return false;
    4862                 :             : }
        

Generated by: LCOV version 2.0-1