LCOV - differential code coverage report
Current view: top level - src/backend/nodes - nodeFuncs.c (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 71.4 % 2714 1939 775 1939
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 32 32 32
Baseline: lcov-20250906-005545-baseline Branches: 60.8 % 1583 962 621 962
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 81.2 % 32 26 6 26
(360..) days: 71.3 % 2682 1913 769 1913
Function coverage date bins:
(360..) days: 100.0 % 32 32 32
Branch coverage date bins:
(30,360] days: 50.0 % 12 6 6 6
(360..) days: 60.9 % 1571 956 615 956

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

Generated by: LCOV version 2.4-beta