LCOV - differential code coverage report
Current view: top level - src/backend/nodes - makefuncs.c (source / functions) Coverage Total Hit UNC LBC UIC GIC GNC CBC EUB ECB
Current: Differential Code Coverage HEAD vs 15 Lines: 98.5 % 330 325 38 3 2 144 36 145 5 139
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 38 38 33 5 38
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 [..60] days: 100.0 % 35 35 35
Legend: Lines: hit not hit (60,120] days: 100.0 % 1 1 1
(240..) days: 98.3 % 294 289 3 2 144 145 5 139
Function coverage date bins:
[..60] days: 100.0 % 5 5 5
(240..) days: 50.0 % 66 33 33 33

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

Generated by: LCOV version v1.16-55-g56c0a2a