LCOV - code coverage report
Current view: top level - src/backend/nodes - makefuncs.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17beta1 Lines: 338 342 98.8 %
Date: 2024-06-14 19:10:57 Functions: 41 41 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * makefuncs.c
       4             :  *    creator functions for various nodes. The functions here are for the
       5             :  *    most frequently created nodes.
       6             :  *
       7             :  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
       8             :  * Portions Copyright (c) 1994, Regents of the University of California
       9             :  *
      10             :  *
      11             :  * IDENTIFICATION
      12             :  *    src/backend/nodes/makefuncs.c
      13             :  *
      14             :  *-------------------------------------------------------------------------
      15             :  */
      16             : #include "postgres.h"
      17             : 
      18             : #include "catalog/pg_class.h"
      19             : #include "catalog/pg_type.h"
      20             : #include "nodes/makefuncs.h"
      21             : #include "nodes/nodeFuncs.h"
      22             : #include "utils/lsyscache.h"
      23             : 
      24             : 
      25             : /*
      26             :  * makeA_Expr -
      27             :  *      makes an A_Expr node
      28             :  */
      29             : A_Expr *
      30       66266 : makeA_Expr(A_Expr_Kind kind, List *name,
      31             :            Node *lexpr, Node *rexpr, int location)
      32             : {
      33       66266 :     A_Expr     *a = makeNode(A_Expr);
      34             : 
      35       66266 :     a->kind = kind;
      36       66266 :     a->name = name;
      37       66266 :     a->lexpr = lexpr;
      38       66266 :     a->rexpr = rexpr;
      39       66266 :     a->location = location;
      40       66266 :     return a;
      41             : }
      42             : 
      43             : /*
      44             :  * makeSimpleA_Expr -
      45             :  *      As above, given a simple (unqualified) operator name
      46             :  */
      47             : A_Expr *
      48      492712 : makeSimpleA_Expr(A_Expr_Kind kind, char *name,
      49             :                  Node *lexpr, Node *rexpr, int location)
      50             : {
      51      492712 :     A_Expr     *a = makeNode(A_Expr);
      52             : 
      53      492712 :     a->kind = kind;
      54      492712 :     a->name = list_make1(makeString((char *) name));
      55      492712 :     a->lexpr = lexpr;
      56      492712 :     a->rexpr = rexpr;
      57      492712 :     a->location = location;
      58      492712 :     return a;
      59             : }
      60             : 
      61             : /*
      62             :  * makeVar -
      63             :  *    creates a Var node
      64             :  */
      65             : Var *
      66     8668480 : makeVar(int varno,
      67             :         AttrNumber varattno,
      68             :         Oid vartype,
      69             :         int32 vartypmod,
      70             :         Oid varcollid,
      71             :         Index varlevelsup)
      72             : {
      73     8668480 :     Var        *var = makeNode(Var);
      74             : 
      75     8668480 :     var->varno = varno;
      76     8668480 :     var->varattno = varattno;
      77     8668480 :     var->vartype = vartype;
      78     8668480 :     var->vartypmod = vartypmod;
      79     8668480 :     var->varcollid = varcollid;
      80     8668480 :     var->varlevelsup = varlevelsup;
      81             : 
      82             :     /*
      83             :      * Only a few callers need to make Var nodes with non-null varnullingrels,
      84             :      * or with varnosyn/varattnosyn different from varno/varattno.  We don't
      85             :      * provide separate arguments for them, but just initialize them to NULL
      86             :      * and the given varno/varattno.  This reduces code clutter and chance of
      87             :      * error for most callers.
      88             :      */
      89     8668480 :     var->varnullingrels = NULL;
      90     8668480 :     var->varnosyn = (Index) varno;
      91     8668480 :     var->varattnosyn = varattno;
      92             : 
      93             :     /* Likewise, we just set location to "unknown" here */
      94     8668480 :     var->location = -1;
      95             : 
      96     8668480 :     return var;
      97             : }
      98             : 
      99             : /*
     100             :  * makeVarFromTargetEntry -
     101             :  *      convenience function to create a same-level Var node from a
     102             :  *      TargetEntry
     103             :  */
     104             : Var *
     105      114592 : makeVarFromTargetEntry(int varno,
     106             :                        TargetEntry *tle)
     107             : {
     108      572960 :     return makeVar(varno,
     109      114592 :                    tle->resno,
     110      114592 :                    exprType((Node *) tle->expr),
     111      114592 :                    exprTypmod((Node *) tle->expr),
     112      114592 :                    exprCollation((Node *) tle->expr),
     113             :                    0);
     114             : }
     115             : 
     116             : /*
     117             :  * makeWholeRowVar -
     118             :  *    creates a Var node representing a whole row of the specified RTE
     119             :  *
     120             :  * A whole-row reference is a Var with varno set to the correct range
     121             :  * table entry, and varattno == 0 to signal that it references the whole
     122             :  * tuple.  (Use of zero here is unclean, since it could easily be confused
     123             :  * with error cases, but it's not worth changing now.)  The vartype indicates
     124             :  * a rowtype; either a named composite type, or a domain over a named
     125             :  * composite type (only possible if the RTE is a function returning that),
     126             :  * or RECORD.  This function encapsulates the logic for determining the
     127             :  * correct rowtype OID to use.
     128             :  *
     129             :  * If allowScalar is true, then for the case where the RTE is a single function
     130             :  * returning a non-composite result type, we produce a normal Var referencing
     131             :  * the function's result directly, instead of the single-column composite
     132             :  * value that the whole-row notation might otherwise suggest.
     133             :  */
     134             : Var *
     135        8240 : makeWholeRowVar(RangeTblEntry *rte,
     136             :                 int varno,
     137             :                 Index varlevelsup,
     138             :                 bool allowScalar)
     139             : {
     140             :     Var        *result;
     141             :     Oid         toid;
     142             :     Node       *fexpr;
     143             : 
     144        8240 :     switch (rte->rtekind)
     145             :     {
     146        6888 :         case RTE_RELATION:
     147             :             /* relation: the rowtype is a named composite type */
     148        6888 :             toid = get_rel_type_id(rte->relid);
     149        6888 :             if (!OidIsValid(toid))
     150           0 :                 ereport(ERROR,
     151             :                         (errcode(ERRCODE_WRONG_OBJECT_TYPE),
     152             :                          errmsg("relation \"%s\" does not have a composite type",
     153             :                                 get_rel_name(rte->relid))));
     154        6888 :             result = makeVar(varno,
     155             :                              InvalidAttrNumber,
     156             :                              toid,
     157             :                              -1,
     158             :                              InvalidOid,
     159             :                              varlevelsup);
     160        6888 :             break;
     161             : 
     162         160 :         case RTE_FUNCTION:
     163             : 
     164             :             /*
     165             :              * If there's more than one function, or ordinality is requested,
     166             :              * force a RECORD result, since there's certainly more than one
     167             :              * column involved and it can't be a known named type.
     168             :              */
     169         160 :             if (rte->funcordinality || list_length(rte->functions) != 1)
     170             :             {
     171             :                 /* always produces an anonymous RECORD result */
     172           6 :                 result = makeVar(varno,
     173             :                                  InvalidAttrNumber,
     174             :                                  RECORDOID,
     175             :                                  -1,
     176             :                                  InvalidOid,
     177             :                                  varlevelsup);
     178           6 :                 break;
     179             :             }
     180             : 
     181         154 :             fexpr = ((RangeTblFunction *) linitial(rte->functions))->funcexpr;
     182         154 :             toid = exprType(fexpr);
     183         154 :             if (type_is_rowtype(toid))
     184             :             {
     185             :                 /* func returns composite; same as relation case */
     186          60 :                 result = makeVar(varno,
     187             :                                  InvalidAttrNumber,
     188             :                                  toid,
     189             :                                  -1,
     190             :                                  InvalidOid,
     191             :                                  varlevelsup);
     192             :             }
     193          94 :             else if (allowScalar)
     194             :             {
     195             :                 /* func returns scalar; just return its output as-is */
     196          26 :                 result = makeVar(varno,
     197             :                                  1,
     198             :                                  toid,
     199             :                                  -1,
     200             :                                  exprCollation(fexpr),
     201             :                                  varlevelsup);
     202             :             }
     203             :             else
     204             :             {
     205             :                 /* func returns scalar, but we want a composite result */
     206          68 :                 result = makeVar(varno,
     207             :                                  InvalidAttrNumber,
     208             :                                  RECORDOID,
     209             :                                  -1,
     210             :                                  InvalidOid,
     211             :                                  varlevelsup);
     212             :             }
     213         154 :             break;
     214             : 
     215        1192 :         default:
     216             : 
     217             :             /*
     218             :              * RTE is a join, subselect, tablefunc, or VALUES.  We represent
     219             :              * this as a whole-row Var of RECORD type. (Note that in most
     220             :              * cases the Var will be expanded to a RowExpr during planning,
     221             :              * but that is not our concern here.)
     222             :              */
     223        1192 :             result = makeVar(varno,
     224             :                              InvalidAttrNumber,
     225             :                              RECORDOID,
     226             :                              -1,
     227             :                              InvalidOid,
     228             :                              varlevelsup);
     229        1192 :             break;
     230             :     }
     231             : 
     232        8240 :     return result;
     233             : }
     234             : 
     235             : /*
     236             :  * makeTargetEntry -
     237             :  *    creates a TargetEntry node
     238             :  */
     239             : TargetEntry *
     240     7012186 : makeTargetEntry(Expr *expr,
     241             :                 AttrNumber resno,
     242             :                 char *resname,
     243             :                 bool resjunk)
     244             : {
     245     7012186 :     TargetEntry *tle = makeNode(TargetEntry);
     246             : 
     247     7012186 :     tle->expr = expr;
     248     7012186 :     tle->resno = resno;
     249     7012186 :     tle->resname = resname;
     250             : 
     251             :     /*
     252             :      * We always set these fields to 0. If the caller wants to change them he
     253             :      * must do so explicitly.  Few callers do that, so omitting these
     254             :      * arguments reduces the chance of error.
     255             :      */
     256     7012186 :     tle->ressortgroupref = 0;
     257     7012186 :     tle->resorigtbl = InvalidOid;
     258     7012186 :     tle->resorigcol = 0;
     259             : 
     260     7012186 :     tle->resjunk = resjunk;
     261             : 
     262     7012186 :     return tle;
     263             : }
     264             : 
     265             : /*
     266             :  * flatCopyTargetEntry -
     267             :  *    duplicate a TargetEntry, but don't copy substructure
     268             :  *
     269             :  * This is commonly used when we just want to modify the resno or substitute
     270             :  * a new expression.
     271             :  */
     272             : TargetEntry *
     273      486822 : flatCopyTargetEntry(TargetEntry *src_tle)
     274             : {
     275      486822 :     TargetEntry *tle = makeNode(TargetEntry);
     276             : 
     277             :     Assert(IsA(src_tle, TargetEntry));
     278      486822 :     memcpy(tle, src_tle, sizeof(TargetEntry));
     279      486822 :     return tle;
     280             : }
     281             : 
     282             : /*
     283             :  * makeFromExpr -
     284             :  *    creates a FromExpr node
     285             :  */
     286             : FromExpr *
     287      570146 : makeFromExpr(List *fromlist, Node *quals)
     288             : {
     289      570146 :     FromExpr   *f = makeNode(FromExpr);
     290             : 
     291      570146 :     f->fromlist = fromlist;
     292      570146 :     f->quals = quals;
     293      570146 :     return f;
     294             : }
     295             : 
     296             : /*
     297             :  * makeConst -
     298             :  *    creates a Const node
     299             :  */
     300             : Const *
     301     2332254 : makeConst(Oid consttype,
     302             :           int32 consttypmod,
     303             :           Oid constcollid,
     304             :           int constlen,
     305             :           Datum constvalue,
     306             :           bool constisnull,
     307             :           bool constbyval)
     308             : {
     309     2332254 :     Const      *cnst = makeNode(Const);
     310             : 
     311             :     /*
     312             :      * If it's a varlena value, force it to be in non-expanded (non-toasted)
     313             :      * format; this avoids any possible dependency on external values and
     314             :      * improves consistency of representation, which is important for equal().
     315             :      */
     316     2332254 :     if (!constisnull && constlen == -1)
     317      126906 :         constvalue = PointerGetDatum(PG_DETOAST_DATUM(constvalue));
     318             : 
     319     2332254 :     cnst->consttype = consttype;
     320     2332254 :     cnst->consttypmod = consttypmod;
     321     2332254 :     cnst->constcollid = constcollid;
     322     2332254 :     cnst->constlen = constlen;
     323     2332254 :     cnst->constvalue = constvalue;
     324     2332254 :     cnst->constisnull = constisnull;
     325     2332254 :     cnst->constbyval = constbyval;
     326     2332254 :     cnst->location = -1;     /* "unknown" */
     327             : 
     328     2332254 :     return cnst;
     329             : }
     330             : 
     331             : /*
     332             :  * makeNullConst -
     333             :  *    creates a Const node representing a NULL of the specified type/typmod
     334             :  *
     335             :  * This is a convenience routine that just saves a lookup of the type's
     336             :  * storage properties.
     337             :  */
     338             : Const *
     339        7428 : makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
     340             : {
     341             :     int16       typLen;
     342             :     bool        typByVal;
     343             : 
     344        7428 :     get_typlenbyval(consttype, &typLen, &typByVal);
     345        7428 :     return makeConst(consttype,
     346             :                      consttypmod,
     347             :                      constcollid,
     348             :                      (int) typLen,
     349             :                      (Datum) 0,
     350             :                      true,
     351             :                      typByVal);
     352             : }
     353             : 
     354             : /*
     355             :  * makeBoolConst -
     356             :  *    creates a Const node representing a boolean value (can be NULL too)
     357             :  */
     358             : Node *
     359        5988 : makeBoolConst(bool value, bool isnull)
     360             : {
     361             :     /* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
     362        5988 :     return (Node *) makeConst(BOOLOID, -1, InvalidOid, 1,
     363             :                               BoolGetDatum(value), isnull, true);
     364             : }
     365             : 
     366             : /*
     367             :  * makeBoolExpr -
     368             :  *    creates a BoolExpr node
     369             :  */
     370             : Expr *
     371      259022 : makeBoolExpr(BoolExprType boolop, List *args, int location)
     372             : {
     373      259022 :     BoolExpr   *b = makeNode(BoolExpr);
     374             : 
     375      259022 :     b->boolop = boolop;
     376      259022 :     b->args = args;
     377      259022 :     b->location = location;
     378             : 
     379      259022 :     return (Expr *) b;
     380             : }
     381             : 
     382             : /*
     383             :  * makeAlias -
     384             :  *    creates an Alias node
     385             :  *
     386             :  * NOTE: the given name is copied, but the colnames list (if any) isn't.
     387             :  */
     388             : Alias *
     389      927048 : makeAlias(const char *aliasname, List *colnames)
     390             : {
     391      927048 :     Alias      *a = makeNode(Alias);
     392             : 
     393      927048 :     a->aliasname = pstrdup(aliasname);
     394      927048 :     a->colnames = colnames;
     395             : 
     396      927048 :     return a;
     397             : }
     398             : 
     399             : /*
     400             :  * makeRelabelType -
     401             :  *    creates a RelabelType node
     402             :  */
     403             : RelabelType *
     404      116404 : makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid,
     405             :                 CoercionForm rformat)
     406             : {
     407      116404 :     RelabelType *r = makeNode(RelabelType);
     408             : 
     409      116404 :     r->arg = arg;
     410      116404 :     r->resulttype = rtype;
     411      116404 :     r->resulttypmod = rtypmod;
     412      116404 :     r->resultcollid = rcollid;
     413      116404 :     r->relabelformat = rformat;
     414      116404 :     r->location = -1;
     415             : 
     416      116404 :     return r;
     417             : }
     418             : 
     419             : /*
     420             :  * makeRangeVar -
     421             :  *    creates a RangeVar node (rather oversimplified case)
     422             :  */
     423             : RangeVar *
     424      662968 : makeRangeVar(char *schemaname, char *relname, int location)
     425             : {
     426      662968 :     RangeVar   *r = makeNode(RangeVar);
     427             : 
     428      662968 :     r->catalogname = NULL;
     429      662968 :     r->schemaname = schemaname;
     430      662968 :     r->relname = relname;
     431      662968 :     r->inh = true;
     432      662968 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
     433      662968 :     r->alias = NULL;
     434      662968 :     r->location = location;
     435             : 
     436      662968 :     return r;
     437             : }
     438             : 
     439             : /*
     440             :  * makeTypeName -
     441             :  *  build a TypeName node for an unqualified name.
     442             :  *
     443             :  * typmod is defaulted, but can be changed later by caller.
     444             :  */
     445             : TypeName *
     446      245020 : makeTypeName(char *typnam)
     447             : {
     448      245020 :     return makeTypeNameFromNameList(list_make1(makeString(typnam)));
     449             : }
     450             : 
     451             : /*
     452             :  * makeTypeNameFromNameList -
     453             :  *  build a TypeName node for a String list representing a qualified name.
     454             :  *
     455             :  * typmod is defaulted, but can be changed later by caller.
     456             :  */
     457             : TypeName *
     458      473096 : makeTypeNameFromNameList(List *names)
     459             : {
     460      473096 :     TypeName   *n = makeNode(TypeName);
     461             : 
     462      473096 :     n->names = names;
     463      473096 :     n->typmods = NIL;
     464      473096 :     n->typemod = -1;
     465      473096 :     n->location = -1;
     466      473096 :     return n;
     467             : }
     468             : 
     469             : /*
     470             :  * makeTypeNameFromOid -
     471             :  *  build a TypeName node to represent a type already known by OID/typmod.
     472             :  */
     473             : TypeName *
     474      155100 : makeTypeNameFromOid(Oid typeOid, int32 typmod)
     475             : {
     476      155100 :     TypeName   *n = makeNode(TypeName);
     477             : 
     478      155100 :     n->typeOid = typeOid;
     479      155100 :     n->typemod = typmod;
     480      155100 :     n->location = -1;
     481      155100 :     return n;
     482             : }
     483             : 
     484             : /*
     485             :  * makeColumnDef -
     486             :  *  build a ColumnDef node to represent a simple column definition.
     487             :  *
     488             :  * Type and collation are specified by OID.
     489             :  * Other properties are all basic to start with.
     490             :  */
     491             : ColumnDef *
     492      153900 : makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
     493             : {
     494      153900 :     ColumnDef  *n = makeNode(ColumnDef);
     495             : 
     496      153900 :     n->colname = pstrdup(colname);
     497      153900 :     n->typeName = makeTypeNameFromOid(typeOid, typmod);
     498      153900 :     n->inhcount = 0;
     499      153900 :     n->is_local = true;
     500      153900 :     n->is_not_null = false;
     501      153900 :     n->is_from_type = false;
     502      153900 :     n->storage = 0;
     503      153900 :     n->raw_default = NULL;
     504      153900 :     n->cooked_default = NULL;
     505      153900 :     n->collClause = NULL;
     506      153900 :     n->collOid = collOid;
     507      153900 :     n->constraints = NIL;
     508      153900 :     n->fdwoptions = NIL;
     509      153900 :     n->location = -1;
     510             : 
     511      153900 :     return n;
     512             : }
     513             : 
     514             : /*
     515             :  * makeFuncExpr -
     516             :  *  build an expression tree representing a function call.
     517             :  *
     518             :  * The argument expressions must have been transformed already.
     519             :  */
     520             : FuncExpr *
     521      149304 : makeFuncExpr(Oid funcid, Oid rettype, List *args,
     522             :              Oid funccollid, Oid inputcollid, CoercionForm fformat)
     523             : {
     524             :     FuncExpr   *funcexpr;
     525             : 
     526      149304 :     funcexpr = makeNode(FuncExpr);
     527      149304 :     funcexpr->funcid = funcid;
     528      149304 :     funcexpr->funcresulttype = rettype;
     529      149304 :     funcexpr->funcretset = false;    /* only allowed case here */
     530      149304 :     funcexpr->funcvariadic = false; /* only allowed case here */
     531      149304 :     funcexpr->funcformat = fformat;
     532      149304 :     funcexpr->funccollid = funccollid;
     533      149304 :     funcexpr->inputcollid = inputcollid;
     534      149304 :     funcexpr->args = args;
     535      149304 :     funcexpr->location = -1;
     536             : 
     537      149304 :     return funcexpr;
     538             : }
     539             : 
     540             : /*
     541             :  * makeStringConst -
     542             :  *  build a A_Const node of type T_String for given string
     543             :  */
     544             : Node *
     545      568296 : makeStringConst(char *str, int location)
     546             : {
     547      568296 :     A_Const    *n = makeNode(A_Const);
     548             : 
     549      568296 :     n->val.sval.type = T_String;
     550      568296 :     n->val.sval.sval = str;
     551      568296 :     n->location = location;
     552             : 
     553      568296 :     return (Node *) n;
     554             : }
     555             : 
     556             : /*
     557             :  * makeDefElem -
     558             :  *  build a DefElem node
     559             :  *
     560             :  * This is sufficient for the "typical" case with an unqualified option name
     561             :  * and no special action.
     562             :  */
     563             : DefElem *
     564      207980 : makeDefElem(char *name, Node *arg, int location)
     565             : {
     566      207980 :     DefElem    *res = makeNode(DefElem);
     567             : 
     568      207980 :     res->defnamespace = NULL;
     569      207980 :     res->defname = name;
     570      207980 :     res->arg = arg;
     571      207980 :     res->defaction = DEFELEM_UNSPEC;
     572      207980 :     res->location = location;
     573             : 
     574      207980 :     return res;
     575             : }
     576             : 
     577             : /*
     578             :  * makeDefElemExtended -
     579             :  *  build a DefElem node with all fields available to be specified
     580             :  */
     581             : DefElem *
     582         194 : makeDefElemExtended(char *nameSpace, char *name, Node *arg,
     583             :                     DefElemAction defaction, int location)
     584             : {
     585         194 :     DefElem    *res = makeNode(DefElem);
     586             : 
     587         194 :     res->defnamespace = nameSpace;
     588         194 :     res->defname = name;
     589         194 :     res->arg = arg;
     590         194 :     res->defaction = defaction;
     591         194 :     res->location = location;
     592             : 
     593         194 :     return res;
     594             : }
     595             : 
     596             : /*
     597             :  * makeFuncCall -
     598             :  *
     599             :  * Initialize a FuncCall struct with the information every caller must
     600             :  * supply.  Any non-default parameters have to be inserted by the caller.
     601             :  */
     602             : FuncCall *
     603      338314 : makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
     604             : {
     605      338314 :     FuncCall   *n = makeNode(FuncCall);
     606             : 
     607      338314 :     n->funcname = name;
     608      338314 :     n->args = args;
     609      338314 :     n->agg_order = NIL;
     610      338314 :     n->agg_filter = NULL;
     611      338314 :     n->over = NULL;
     612      338314 :     n->agg_within_group = false;
     613      338314 :     n->agg_star = false;
     614      338314 :     n->agg_distinct = false;
     615      338314 :     n->func_variadic = false;
     616      338314 :     n->funcformat = funcformat;
     617      338314 :     n->location = location;
     618      338314 :     return n;
     619             : }
     620             : 
     621             : /*
     622             :  * make_opclause
     623             :  *    Creates an operator clause given its operator info, left operand
     624             :  *    and right operand (pass NULL to create single-operand clause),
     625             :  *    and collation info.
     626             :  */
     627             : Expr *
     628      129168 : make_opclause(Oid opno, Oid opresulttype, bool opretset,
     629             :               Expr *leftop, Expr *rightop,
     630             :               Oid opcollid, Oid inputcollid)
     631             : {
     632      129168 :     OpExpr     *expr = makeNode(OpExpr);
     633             : 
     634      129168 :     expr->opno = opno;
     635      129168 :     expr->opfuncid = InvalidOid;
     636      129168 :     expr->opresulttype = opresulttype;
     637      129168 :     expr->opretset = opretset;
     638      129168 :     expr->opcollid = opcollid;
     639      129168 :     expr->inputcollid = inputcollid;
     640      129168 :     if (rightop)
     641      129168 :         expr->args = list_make2(leftop, rightop);
     642             :     else
     643           0 :         expr->args = list_make1(leftop);
     644      129168 :     expr->location = -1;
     645      129168 :     return (Expr *) expr;
     646             : }
     647             : 
     648             : /*
     649             :  * make_andclause
     650             :  *
     651             :  * Creates an 'and' clause given a list of its subclauses.
     652             :  */
     653             : Expr *
     654      250030 : make_andclause(List *andclauses)
     655             : {
     656      250030 :     BoolExpr   *expr = makeNode(BoolExpr);
     657             : 
     658      250030 :     expr->boolop = AND_EXPR;
     659      250030 :     expr->args = andclauses;
     660      250030 :     expr->location = -1;
     661      250030 :     return (Expr *) expr;
     662             : }
     663             : 
     664             : /*
     665             :  * make_orclause
     666             :  *
     667             :  * Creates an 'or' clause given a list of its subclauses.
     668             :  */
     669             : Expr *
     670       34448 : make_orclause(List *orclauses)
     671             : {
     672       34448 :     BoolExpr   *expr = makeNode(BoolExpr);
     673             : 
     674       34448 :     expr->boolop = OR_EXPR;
     675       34448 :     expr->args = orclauses;
     676       34448 :     expr->location = -1;
     677       34448 :     return (Expr *) expr;
     678             : }
     679             : 
     680             : /*
     681             :  * make_notclause
     682             :  *
     683             :  * Create a 'not' clause given the expression to be negated.
     684             :  */
     685             : Expr *
     686        9400 : make_notclause(Expr *notclause)
     687             : {
     688        9400 :     BoolExpr   *expr = makeNode(BoolExpr);
     689             : 
     690        9400 :     expr->boolop = NOT_EXPR;
     691        9400 :     expr->args = list_make1(notclause);
     692        9400 :     expr->location = -1;
     693        9400 :     return (Expr *) expr;
     694             : }
     695             : 
     696             : /*
     697             :  * make_and_qual
     698             :  *
     699             :  * Variant of make_andclause for ANDing two qual conditions together.
     700             :  * Qual conditions have the property that a NULL nodetree is interpreted
     701             :  * as 'true'.
     702             :  *
     703             :  * NB: this makes no attempt to preserve AND/OR flatness; so it should not
     704             :  * be used on a qual that has already been run through prepqual.c.
     705             :  */
     706             : Node *
     707        2848 : make_and_qual(Node *qual1, Node *qual2)
     708             : {
     709        2848 :     if (qual1 == NULL)
     710        1372 :         return qual2;
     711        1476 :     if (qual2 == NULL)
     712           0 :         return qual1;
     713        1476 :     return (Node *) make_andclause(list_make2(qual1, qual2));
     714             : }
     715             : 
     716             : /*
     717             :  * The planner and executor usually represent qualification expressions
     718             :  * as lists of boolean expressions with implicit AND semantics.
     719             :  *
     720             :  * These functions convert between an AND-semantics expression list and the
     721             :  * ordinary representation of a boolean expression.
     722             :  *
     723             :  * Note that an empty list is considered equivalent to TRUE.
     724             :  */
     725             : Expr *
     726       50754 : make_ands_explicit(List *andclauses)
     727             : {
     728       50754 :     if (andclauses == NIL)
     729           0 :         return (Expr *) makeBoolConst(true, false);
     730       50754 :     else if (list_length(andclauses) == 1)
     731       36652 :         return (Expr *) linitial(andclauses);
     732             :     else
     733       14102 :         return make_andclause(andclauses);
     734             : }
     735             : 
     736             : List *
     737      355320 : make_ands_implicit(Expr *clause)
     738             : {
     739             :     /*
     740             :      * NB: because the parser sets the qual field to NULL in a query that has
     741             :      * no WHERE clause, we must consider a NULL input clause as TRUE, even
     742             :      * though one might more reasonably think it FALSE.
     743             :      */
     744      355320 :     if (clause == NULL)
     745       58254 :         return NIL;             /* NULL -> NIL list == TRUE */
     746      297066 :     else if (is_andclause(clause))
     747       94078 :         return ((BoolExpr *) clause)->args;
     748      202988 :     else if (IsA(clause, Const) &&
     749        5192 :              !((Const *) clause)->constisnull &&
     750        2524 :              DatumGetBool(((Const *) clause)->constvalue))
     751        1544 :         return NIL;             /* constant TRUE input -> NIL list */
     752             :     else
     753      201444 :         return list_make1(clause);
     754             : }
     755             : 
     756             : /*
     757             :  * makeIndexInfo
     758             :  *    create an IndexInfo node
     759             :  */
     760             : IndexInfo *
     761     2852254 : makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
     762             :               List *predicates, bool unique, bool nulls_not_distinct,
     763             :               bool isready, bool concurrent, bool summarizing)
     764             : {
     765     2852254 :     IndexInfo  *n = makeNode(IndexInfo);
     766             : 
     767     2852254 :     n->ii_NumIndexAttrs = numattrs;
     768     2852254 :     n->ii_NumIndexKeyAttrs = numkeyattrs;
     769             :     Assert(n->ii_NumIndexKeyAttrs != 0);
     770             :     Assert(n->ii_NumIndexKeyAttrs <= n->ii_NumIndexAttrs);
     771     2852254 :     n->ii_Unique = unique;
     772     2852254 :     n->ii_NullsNotDistinct = nulls_not_distinct;
     773     2852254 :     n->ii_ReadyForInserts = isready;
     774     2852254 :     n->ii_CheckedUnchanged = false;
     775     2852254 :     n->ii_IndexUnchanged = false;
     776     2852254 :     n->ii_Concurrent = concurrent;
     777     2852254 :     n->ii_Summarizing = summarizing;
     778             : 
     779             :     /* summarizing indexes cannot contain non-key attributes */
     780             :     Assert(!summarizing || (numkeyattrs == numattrs));
     781             : 
     782             :     /* expressions */
     783     2852254 :     n->ii_Expressions = expressions;
     784     2852254 :     n->ii_ExpressionsState = NIL;
     785             : 
     786             :     /* predicates  */
     787     2852254 :     n->ii_Predicate = predicates;
     788     2852254 :     n->ii_PredicateState = NULL;
     789             : 
     790             :     /* exclusion constraints */
     791     2852254 :     n->ii_ExclusionOps = NULL;
     792     2852254 :     n->ii_ExclusionProcs = NULL;
     793     2852254 :     n->ii_ExclusionStrats = NULL;
     794             : 
     795             :     /* speculative inserts */
     796     2852254 :     n->ii_UniqueOps = NULL;
     797     2852254 :     n->ii_UniqueProcs = NULL;
     798     2852254 :     n->ii_UniqueStrats = NULL;
     799             : 
     800             :     /* initialize index-build state to default */
     801     2852254 :     n->ii_BrokenHotChain = false;
     802     2852254 :     n->ii_ParallelWorkers = 0;
     803             : 
     804             :     /* set up for possible use by index AM */
     805     2852254 :     n->ii_Am = amoid;
     806     2852254 :     n->ii_AmCache = NULL;
     807     2852254 :     n->ii_Context = CurrentMemoryContext;
     808             : 
     809     2852254 :     return n;
     810             : }
     811             : 
     812             : /*
     813             :  * makeGroupingSet
     814             :  *
     815             :  */
     816             : GroupingSet *
     817        4762 : makeGroupingSet(GroupingSetKind kind, List *content, int location)
     818             : {
     819        4762 :     GroupingSet *n = makeNode(GroupingSet);
     820             : 
     821        4762 :     n->kind = kind;
     822        4762 :     n->content = content;
     823        4762 :     n->location = location;
     824        4762 :     return n;
     825             : }
     826             : 
     827             : /*
     828             :  * makeVacuumRelation -
     829             :  *    create a VacuumRelation node
     830             :  */
     831             : VacuumRelation *
     832       34364 : makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
     833             : {
     834       34364 :     VacuumRelation *v = makeNode(VacuumRelation);
     835             : 
     836       34364 :     v->relation = relation;
     837       34364 :     v->oid = oid;
     838       34364 :     v->va_cols = va_cols;
     839       34364 :     return v;
     840             : }
     841             : 
     842             : /*
     843             :  * makeJsonFormat -
     844             :  *    creates a JsonFormat node
     845             :  */
     846             : JsonFormat *
     847        8990 : makeJsonFormat(JsonFormatType type, JsonEncoding encoding, int location)
     848             : {
     849        8990 :     JsonFormat *jf = makeNode(JsonFormat);
     850             : 
     851        8990 :     jf->format_type = type;
     852        8990 :     jf->encoding = encoding;
     853        8990 :     jf->location = location;
     854             : 
     855        8990 :     return jf;
     856             : }
     857             : 
     858             : /*
     859             :  * makeJsonValueExpr -
     860             :  *    creates a JsonValueExpr node
     861             :  */
     862             : JsonValueExpr *
     863        4624 : makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr,
     864             :                   JsonFormat *format)
     865             : {
     866        4624 :     JsonValueExpr *jve = makeNode(JsonValueExpr);
     867             : 
     868        4624 :     jve->raw_expr = raw_expr;
     869        4624 :     jve->formatted_expr = formatted_expr;
     870        4624 :     jve->format = format;
     871             : 
     872        4624 :     return jve;
     873             : }
     874             : 
     875             : /*
     876             :  * makeJsonBehavior -
     877             :  *    creates a JsonBehavior node
     878             :  */
     879             : JsonBehavior *
     880        2902 : makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
     881             : {
     882        2902 :     JsonBehavior *behavior = makeNode(JsonBehavior);
     883             : 
     884        2902 :     behavior->btype = btype;
     885        2902 :     behavior->expr = expr;
     886        2902 :     behavior->location = location;
     887             : 
     888        2902 :     return behavior;
     889             : }
     890             : 
     891             : /*
     892             :  * makeJsonKeyValue -
     893             :  *    creates a JsonKeyValue node
     894             :  */
     895             : Node *
     896         676 : makeJsonKeyValue(Node *key, Node *value)
     897             : {
     898         676 :     JsonKeyValue *n = makeNode(JsonKeyValue);
     899             : 
     900         676 :     n->key = (Expr *) key;
     901         676 :     n->value = castNode(JsonValueExpr, value);
     902             : 
     903         676 :     return (Node *) n;
     904             : }
     905             : 
     906             : /*
     907             :  * makeJsonIsPredicate -
     908             :  *    creates a JsonIsPredicate node
     909             :  */
     910             : Node *
     911         694 : makeJsonIsPredicate(Node *expr, JsonFormat *format, JsonValueType item_type,
     912             :                     bool unique_keys, int location)
     913             : {
     914         694 :     JsonIsPredicate *n = makeNode(JsonIsPredicate);
     915             : 
     916         694 :     n->expr = expr;
     917         694 :     n->format = format;
     918         694 :     n->item_type = item_type;
     919         694 :     n->unique_keys = unique_keys;
     920         694 :     n->location = location;
     921             : 
     922         694 :     return (Node *) n;
     923             : }
     924             : 
     925             : /*
     926             :  * makeJsonTablePathSpec -
     927             :  *      Make JsonTablePathSpec node from given path string and name (if any)
     928             :  */
     929             : JsonTablePathSpec *
     930        1474 : makeJsonTablePathSpec(char *string, char *name, int string_location,
     931             :                       int name_location)
     932             : {
     933        1474 :     JsonTablePathSpec *pathspec = makeNode(JsonTablePathSpec);
     934             : 
     935             :     Assert(string != NULL);
     936        1474 :     pathspec->string = makeStringConst(string, string_location);
     937        1474 :     if (name != NULL)
     938         208 :         pathspec->name = pstrdup(name);
     939             : 
     940        1474 :     pathspec->name_location = name_location;
     941        1474 :     pathspec->location = string_location;
     942             : 
     943        1474 :     return pathspec;
     944             : }
     945             : 
     946             : /*
     947             :  * makeJsonTablePath -
     948             :  *      Make JsonTablePath node for given path string and name
     949             :  */
     950             : JsonTablePath *
     951         604 : makeJsonTablePath(Const *pathvalue, char *pathname)
     952             : {
     953         604 :     JsonTablePath *path = makeNode(JsonTablePath);
     954             : 
     955             :     Assert(IsA(pathvalue, Const));
     956         604 :     path->value = pathvalue;
     957         604 :     path->name = pathname;
     958             : 
     959         604 :     return path;
     960             : }

Generated by: LCOV version 1.14