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 68290 : makeA_Expr(A_Expr_Kind kind, List *name,
31 : Node *lexpr, Node *rexpr, int location)
32 : {
33 68290 : A_Expr *a = makeNode(A_Expr);
34 :
35 68290 : a->kind = kind;
36 68290 : a->name = name;
37 68290 : a->lexpr = lexpr;
38 68290 : a->rexpr = rexpr;
39 68290 : a->location = location;
40 68290 : return a;
41 : }
42 :
43 : /*
44 : * makeSimpleA_Expr -
45 : * As above, given a simple (unqualified) operator name
46 : */
47 : A_Expr *
48 514082 : makeSimpleA_Expr(A_Expr_Kind kind, char *name,
49 : Node *lexpr, Node *rexpr, int location)
50 : {
51 514082 : A_Expr *a = makeNode(A_Expr);
52 :
53 514082 : a->kind = kind;
54 514082 : a->name = list_make1(makeString((char *) name));
55 514082 : a->lexpr = lexpr;
56 514082 : a->rexpr = rexpr;
57 514082 : a->location = location;
58 514082 : return a;
59 : }
60 :
61 : /*
62 : * makeVar -
63 : * creates a Var node
64 : */
65 : Var *
66 9218024 : makeVar(int varno,
67 : AttrNumber varattno,
68 : Oid vartype,
69 : int32 vartypmod,
70 : Oid varcollid,
71 : Index varlevelsup)
72 : {
73 9218024 : Var *var = makeNode(Var);
74 :
75 9218024 : var->varno = varno;
76 9218024 : var->varattno = varattno;
77 9218024 : var->vartype = vartype;
78 9218024 : var->vartypmod = vartypmod;
79 9218024 : var->varcollid = varcollid;
80 9218024 : 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 9218024 : var->varnullingrels = NULL;
90 9218024 : var->varnosyn = (Index) varno;
91 9218024 : var->varattnosyn = varattno;
92 :
93 : /* Likewise, we just set location to "unknown" here */
94 9218024 : var->location = -1;
95 :
96 9218024 : 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 115646 : makeVarFromTargetEntry(int varno,
106 : TargetEntry *tle)
107 : {
108 578230 : return makeVar(varno,
109 115646 : tle->resno,
110 115646 : exprType((Node *) tle->expr),
111 115646 : exprTypmod((Node *) tle->expr),
112 115646 : 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 8204 : makeWholeRowVar(RangeTblEntry *rte,
136 : int varno,
137 : Index varlevelsup,
138 : bool allowScalar)
139 : {
140 : Var *result;
141 : Oid toid;
142 : Node *fexpr;
143 :
144 8204 : switch (rte->rtekind)
145 : {
146 6882 : case RTE_RELATION:
147 : /* relation: the rowtype is a named composite type */
148 6882 : toid = get_rel_type_id(rte->relid);
149 6882 : 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 6882 : result = makeVar(varno,
155 : InvalidAttrNumber,
156 : toid,
157 : -1,
158 : InvalidOid,
159 : varlevelsup);
160 6882 : break;
161 :
162 148 : 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 148 : 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 142 : fexpr = ((RangeTblFunction *) linitial(rte->functions))->funcexpr;
182 142 : toid = exprType(fexpr);
183 142 : 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 82 : 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 56 : result = makeVar(varno,
207 : InvalidAttrNumber,
208 : RECORDOID,
209 : -1,
210 : InvalidOid,
211 : varlevelsup);
212 : }
213 142 : break;
214 :
215 1174 : 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 1174 : result = makeVar(varno,
224 : InvalidAttrNumber,
225 : RECORDOID,
226 : -1,
227 : InvalidOid,
228 : varlevelsup);
229 1174 : break;
230 : }
231 :
232 8204 : return result;
233 : }
234 :
235 : /*
236 : * makeTargetEntry -
237 : * creates a TargetEntry node
238 : */
239 : TargetEntry *
240 7328350 : makeTargetEntry(Expr *expr,
241 : AttrNumber resno,
242 : char *resname,
243 : bool resjunk)
244 : {
245 7328350 : TargetEntry *tle = makeNode(TargetEntry);
246 :
247 7328350 : tle->expr = expr;
248 7328350 : tle->resno = resno;
249 7328350 : 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 7328350 : tle->ressortgroupref = 0;
257 7328350 : tle->resorigtbl = InvalidOid;
258 7328350 : tle->resorigcol = 0;
259 :
260 7328350 : tle->resjunk = resjunk;
261 :
262 7328350 : 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 516848 : flatCopyTargetEntry(TargetEntry *src_tle)
274 : {
275 516848 : TargetEntry *tle = makeNode(TargetEntry);
276 :
277 : Assert(IsA(src_tle, TargetEntry));
278 516848 : memcpy(tle, src_tle, sizeof(TargetEntry));
279 516848 : return tle;
280 : }
281 :
282 : /*
283 : * makeFromExpr -
284 : * creates a FromExpr node
285 : */
286 : FromExpr *
287 574150 : makeFromExpr(List *fromlist, Node *quals)
288 : {
289 574150 : FromExpr *f = makeNode(FromExpr);
290 :
291 574150 : f->fromlist = fromlist;
292 574150 : f->quals = quals;
293 574150 : return f;
294 : }
295 :
296 : /*
297 : * makeConst -
298 : * creates a Const node
299 : */
300 : Const *
301 2336584 : makeConst(Oid consttype,
302 : int32 consttypmod,
303 : Oid constcollid,
304 : int constlen,
305 : Datum constvalue,
306 : bool constisnull,
307 : bool constbyval)
308 : {
309 2336584 : 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 2336584 : if (!constisnull && constlen == -1)
317 126544 : constvalue = PointerGetDatum(PG_DETOAST_DATUM(constvalue));
318 :
319 2336584 : cnst->consttype = consttype;
320 2336584 : cnst->consttypmod = consttypmod;
321 2336584 : cnst->constcollid = constcollid;
322 2336584 : cnst->constlen = constlen;
323 2336584 : cnst->constvalue = constvalue;
324 2336584 : cnst->constisnull = constisnull;
325 2336584 : cnst->constbyval = constbyval;
326 2336584 : cnst->location = -1; /* "unknown" */
327 :
328 2336584 : 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 7698 : makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
340 : {
341 : int16 typLen;
342 : bool typByVal;
343 :
344 7698 : get_typlenbyval(consttype, &typLen, &typByVal);
345 7698 : 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 6038 : makeBoolConst(bool value, bool isnull)
360 : {
361 : /* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
362 6038 : 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 270698 : makeBoolExpr(BoolExprType boolop, List *args, int location)
372 : {
373 270698 : BoolExpr *b = makeNode(BoolExpr);
374 :
375 270698 : b->boolop = boolop;
376 270698 : b->args = args;
377 270698 : b->location = location;
378 :
379 270698 : 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 943094 : makeAlias(const char *aliasname, List *colnames)
390 : {
391 943094 : Alias *a = makeNode(Alias);
392 :
393 943094 : a->aliasname = pstrdup(aliasname);
394 943094 : a->colnames = colnames;
395 :
396 943094 : return a;
397 : }
398 :
399 : /*
400 : * makeRelabelType -
401 : * creates a RelabelType node
402 : */
403 : RelabelType *
404 121260 : makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid,
405 : CoercionForm rformat)
406 : {
407 121260 : RelabelType *r = makeNode(RelabelType);
408 :
409 121260 : r->arg = arg;
410 121260 : r->resulttype = rtype;
411 121260 : r->resulttypmod = rtypmod;
412 121260 : r->resultcollid = rcollid;
413 121260 : r->relabelformat = rformat;
414 121260 : r->location = -1;
415 :
416 121260 : return r;
417 : }
418 :
419 : /*
420 : * makeRangeVar -
421 : * creates a RangeVar node (rather oversimplified case)
422 : */
423 : RangeVar *
424 673456 : makeRangeVar(char *schemaname, char *relname, int location)
425 : {
426 673456 : RangeVar *r = makeNode(RangeVar);
427 :
428 673456 : r->catalogname = NULL;
429 673456 : r->schemaname = schemaname;
430 673456 : r->relname = relname;
431 673456 : r->inh = true;
432 673456 : r->relpersistence = RELPERSISTENCE_PERMANENT;
433 673456 : r->alias = NULL;
434 673456 : r->location = location;
435 :
436 673456 : 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 243572 : makeTypeName(char *typnam)
447 : {
448 243572 : 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 478724 : makeTypeNameFromNameList(List *names)
459 : {
460 478724 : TypeName *n = makeNode(TypeName);
461 :
462 478724 : n->names = names;
463 478724 : n->typmods = NIL;
464 478724 : n->typemod = -1;
465 478724 : n->location = -1;
466 478724 : 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 151020 : makeTypeNameFromOid(Oid typeOid, int32 typmod)
475 : {
476 151020 : TypeName *n = makeNode(TypeName);
477 :
478 151020 : n->typeOid = typeOid;
479 151020 : n->typemod = typmod;
480 151020 : n->location = -1;
481 151020 : 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 149840 : makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
493 : {
494 149840 : ColumnDef *n = makeNode(ColumnDef);
495 :
496 149840 : n->colname = pstrdup(colname);
497 149840 : n->typeName = makeTypeNameFromOid(typeOid, typmod);
498 149840 : n->inhcount = 0;
499 149840 : n->is_local = true;
500 149840 : n->is_not_null = false;
501 149840 : n->is_from_type = false;
502 149840 : n->storage = 0;
503 149840 : n->raw_default = NULL;
504 149840 : n->cooked_default = NULL;
505 149840 : n->collClause = NULL;
506 149840 : n->collOid = collOid;
507 149840 : n->constraints = NIL;
508 149840 : n->fdwoptions = NIL;
509 149840 : n->location = -1;
510 :
511 149840 : 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 148698 : makeFuncExpr(Oid funcid, Oid rettype, List *args,
522 : Oid funccollid, Oid inputcollid, CoercionForm fformat)
523 : {
524 : FuncExpr *funcexpr;
525 :
526 148698 : funcexpr = makeNode(FuncExpr);
527 148698 : funcexpr->funcid = funcid;
528 148698 : funcexpr->funcresulttype = rettype;
529 148698 : funcexpr->funcretset = false; /* only allowed case here */
530 148698 : funcexpr->funcvariadic = false; /* only allowed case here */
531 148698 : funcexpr->funcformat = fformat;
532 148698 : funcexpr->funccollid = funccollid;
533 148698 : funcexpr->inputcollid = inputcollid;
534 148698 : funcexpr->args = args;
535 148698 : funcexpr->location = -1;
536 :
537 148698 : return funcexpr;
538 : }
539 :
540 : /*
541 : * makeDefElem -
542 : * build a DefElem node
543 : *
544 : * This is sufficient for the "typical" case with an unqualified option name
545 : * and no special action.
546 : */
547 : DefElem *
548 207804 : makeDefElem(char *name, Node *arg, int location)
549 : {
550 207804 : DefElem *res = makeNode(DefElem);
551 :
552 207804 : res->defnamespace = NULL;
553 207804 : res->defname = name;
554 207804 : res->arg = arg;
555 207804 : res->defaction = DEFELEM_UNSPEC;
556 207804 : res->location = location;
557 :
558 207804 : return res;
559 : }
560 :
561 : /*
562 : * makeDefElemExtended -
563 : * build a DefElem node with all fields available to be specified
564 : */
565 : DefElem *
566 194 : makeDefElemExtended(char *nameSpace, char *name, Node *arg,
567 : DefElemAction defaction, int location)
568 : {
569 194 : DefElem *res = makeNode(DefElem);
570 :
571 194 : res->defnamespace = nameSpace;
572 194 : res->defname = name;
573 194 : res->arg = arg;
574 194 : res->defaction = defaction;
575 194 : res->location = location;
576 :
577 194 : return res;
578 : }
579 :
580 : /*
581 : * makeFuncCall -
582 : *
583 : * Initialize a FuncCall struct with the information every caller must
584 : * supply. Any non-default parameters have to be inserted by the caller.
585 : */
586 : FuncCall *
587 344872 : makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
588 : {
589 344872 : FuncCall *n = makeNode(FuncCall);
590 :
591 344872 : n->funcname = name;
592 344872 : n->args = args;
593 344872 : n->agg_order = NIL;
594 344872 : n->agg_filter = NULL;
595 344872 : n->over = NULL;
596 344872 : n->agg_within_group = false;
597 344872 : n->agg_star = false;
598 344872 : n->agg_distinct = false;
599 344872 : n->func_variadic = false;
600 344872 : n->funcformat = funcformat;
601 344872 : n->location = location;
602 344872 : return n;
603 : }
604 :
605 : /*
606 : * make_opclause
607 : * Creates an operator clause given its operator info, left operand
608 : * and right operand (pass NULL to create single-operand clause),
609 : * and collation info.
610 : */
611 : Expr *
612 134294 : make_opclause(Oid opno, Oid opresulttype, bool opretset,
613 : Expr *leftop, Expr *rightop,
614 : Oid opcollid, Oid inputcollid)
615 : {
616 134294 : OpExpr *expr = makeNode(OpExpr);
617 :
618 134294 : expr->opno = opno;
619 134294 : expr->opfuncid = InvalidOid;
620 134294 : expr->opresulttype = opresulttype;
621 134294 : expr->opretset = opretset;
622 134294 : expr->opcollid = opcollid;
623 134294 : expr->inputcollid = inputcollid;
624 134294 : if (rightop)
625 134294 : expr->args = list_make2(leftop, rightop);
626 : else
627 0 : expr->args = list_make1(leftop);
628 134294 : expr->location = -1;
629 134294 : return (Expr *) expr;
630 : }
631 :
632 : /*
633 : * make_andclause
634 : *
635 : * Creates an 'and' clause given a list of its subclauses.
636 : */
637 : Expr *
638 264350 : make_andclause(List *andclauses)
639 : {
640 264350 : BoolExpr *expr = makeNode(BoolExpr);
641 :
642 264350 : expr->boolop = AND_EXPR;
643 264350 : expr->args = andclauses;
644 264350 : expr->location = -1;
645 264350 : return (Expr *) expr;
646 : }
647 :
648 : /*
649 : * make_orclause
650 : *
651 : * Creates an 'or' clause given a list of its subclauses.
652 : */
653 : Expr *
654 34080 : make_orclause(List *orclauses)
655 : {
656 34080 : BoolExpr *expr = makeNode(BoolExpr);
657 :
658 34080 : expr->boolop = OR_EXPR;
659 34080 : expr->args = orclauses;
660 34080 : expr->location = -1;
661 34080 : return (Expr *) expr;
662 : }
663 :
664 : /*
665 : * make_notclause
666 : *
667 : * Create a 'not' clause given the expression to be negated.
668 : */
669 : Expr *
670 9900 : make_notclause(Expr *notclause)
671 : {
672 9900 : BoolExpr *expr = makeNode(BoolExpr);
673 :
674 9900 : expr->boolop = NOT_EXPR;
675 9900 : expr->args = list_make1(notclause);
676 9900 : expr->location = -1;
677 9900 : return (Expr *) expr;
678 : }
679 :
680 : /*
681 : * make_and_qual
682 : *
683 : * Variant of make_andclause for ANDing two qual conditions together.
684 : * Qual conditions have the property that a NULL nodetree is interpreted
685 : * as 'true'.
686 : *
687 : * NB: this makes no attempt to preserve AND/OR flatness; so it should not
688 : * be used on a qual that has already been run through prepqual.c.
689 : */
690 : Node *
691 2788 : make_and_qual(Node *qual1, Node *qual2)
692 : {
693 2788 : if (qual1 == NULL)
694 1228 : return qual2;
695 1560 : if (qual2 == NULL)
696 0 : return qual1;
697 1560 : return (Node *) make_andclause(list_make2(qual1, qual2));
698 : }
699 :
700 : /*
701 : * The planner and executor usually represent qualification expressions
702 : * as lists of boolean expressions with implicit AND semantics.
703 : *
704 : * These functions convert between an AND-semantics expression list and the
705 : * ordinary representation of a boolean expression.
706 : *
707 : * Note that an empty list is considered equivalent to TRUE.
708 : */
709 : Expr *
710 50406 : make_ands_explicit(List *andclauses)
711 : {
712 50406 : if (andclauses == NIL)
713 0 : return (Expr *) makeBoolConst(true, false);
714 50406 : else if (list_length(andclauses) == 1)
715 36796 : return (Expr *) linitial(andclauses);
716 : else
717 13610 : return make_andclause(andclauses);
718 : }
719 :
720 : List *
721 369536 : make_ands_implicit(Expr *clause)
722 : {
723 : /*
724 : * NB: because the parser sets the qual field to NULL in a query that has
725 : * no WHERE clause, we must consider a NULL input clause as TRUE, even
726 : * though one might more reasonably think it FALSE.
727 : */
728 369536 : if (clause == NULL)
729 59774 : return NIL; /* NULL -> NIL list == TRUE */
730 309762 : else if (is_andclause(clause))
731 100834 : return ((BoolExpr *) clause)->args;
732 208928 : else if (IsA(clause, Const) &&
733 5400 : !((Const *) clause)->constisnull &&
734 2628 : DatumGetBool(((Const *) clause)->constvalue))
735 1612 : return NIL; /* constant TRUE input -> NIL list */
736 : else
737 207316 : return list_make1(clause);
738 : }
739 :
740 : /*
741 : * makeIndexInfo
742 : * create an IndexInfo node
743 : */
744 : IndexInfo *
745 2889300 : makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
746 : List *predicates, bool unique, bool nulls_not_distinct,
747 : bool isready, bool concurrent, bool summarizing)
748 : {
749 2889300 : IndexInfo *n = makeNode(IndexInfo);
750 :
751 2889300 : n->ii_NumIndexAttrs = numattrs;
752 2889300 : n->ii_NumIndexKeyAttrs = numkeyattrs;
753 : Assert(n->ii_NumIndexKeyAttrs != 0);
754 : Assert(n->ii_NumIndexKeyAttrs <= n->ii_NumIndexAttrs);
755 2889300 : n->ii_Unique = unique;
756 2889300 : n->ii_NullsNotDistinct = nulls_not_distinct;
757 2889300 : n->ii_ReadyForInserts = isready;
758 2889300 : n->ii_CheckedUnchanged = false;
759 2889300 : n->ii_IndexUnchanged = false;
760 2889300 : n->ii_Concurrent = concurrent;
761 2889300 : n->ii_Summarizing = summarizing;
762 :
763 : /* summarizing indexes cannot contain non-key attributes */
764 : Assert(!summarizing || (numkeyattrs == numattrs));
765 :
766 : /* expressions */
767 2889300 : n->ii_Expressions = expressions;
768 2889300 : n->ii_ExpressionsState = NIL;
769 :
770 : /* predicates */
771 2889300 : n->ii_Predicate = predicates;
772 2889300 : n->ii_PredicateState = NULL;
773 :
774 : /* exclusion constraints */
775 2889300 : n->ii_ExclusionOps = NULL;
776 2889300 : n->ii_ExclusionProcs = NULL;
777 2889300 : n->ii_ExclusionStrats = NULL;
778 :
779 : /* speculative inserts */
780 2889300 : n->ii_UniqueOps = NULL;
781 2889300 : n->ii_UniqueProcs = NULL;
782 2889300 : n->ii_UniqueStrats = NULL;
783 :
784 : /* initialize index-build state to default */
785 2889300 : n->ii_BrokenHotChain = false;
786 2889300 : n->ii_ParallelWorkers = 0;
787 :
788 : /* set up for possible use by index AM */
789 2889300 : n->ii_Am = amoid;
790 2889300 : n->ii_AmCache = NULL;
791 2889300 : n->ii_Context = CurrentMemoryContext;
792 :
793 2889300 : return n;
794 : }
795 :
796 : /*
797 : * makeGroupingSet
798 : *
799 : */
800 : GroupingSet *
801 4762 : makeGroupingSet(GroupingSetKind kind, List *content, int location)
802 : {
803 4762 : GroupingSet *n = makeNode(GroupingSet);
804 :
805 4762 : n->kind = kind;
806 4762 : n->content = content;
807 4762 : n->location = location;
808 4762 : return n;
809 : }
810 :
811 : /*
812 : * makeVacuumRelation -
813 : * create a VacuumRelation node
814 : */
815 : VacuumRelation *
816 34392 : makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
817 : {
818 34392 : VacuumRelation *v = makeNode(VacuumRelation);
819 :
820 34392 : v->relation = relation;
821 34392 : v->oid = oid;
822 34392 : v->va_cols = va_cols;
823 34392 : return v;
824 : }
825 :
826 : /*
827 : * makeJsonFormat -
828 : * creates a JsonFormat node
829 : */
830 : JsonFormat *
831 6144 : makeJsonFormat(JsonFormatType type, JsonEncoding encoding, int location)
832 : {
833 6144 : JsonFormat *jf = makeNode(JsonFormat);
834 :
835 6144 : jf->format_type = type;
836 6144 : jf->encoding = encoding;
837 6144 : jf->location = location;
838 :
839 6144 : return jf;
840 : }
841 :
842 : /*
843 : * makeJsonValueExpr -
844 : * creates a JsonValueExpr node
845 : */
846 : JsonValueExpr *
847 3120 : makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr,
848 : JsonFormat *format)
849 : {
850 3120 : JsonValueExpr *jve = makeNode(JsonValueExpr);
851 :
852 3120 : jve->raw_expr = raw_expr;
853 3120 : jve->formatted_expr = formatted_expr;
854 3120 : jve->format = format;
855 :
856 3120 : return jve;
857 : }
858 :
859 : /*
860 : * makeJsonBehavior -
861 : * creates a JsonBehavior node
862 : */
863 : JsonBehavior *
864 1602 : makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
865 : {
866 1602 : JsonBehavior *behavior = makeNode(JsonBehavior);
867 :
868 1602 : behavior->btype = btype;
869 1602 : behavior->expr = expr;
870 1602 : behavior->location = location;
871 :
872 1602 : return behavior;
873 : }
874 :
875 : /*
876 : * makeJsonKeyValue -
877 : * creates a JsonKeyValue node
878 : */
879 : Node *
880 676 : makeJsonKeyValue(Node *key, Node *value)
881 : {
882 676 : JsonKeyValue *n = makeNode(JsonKeyValue);
883 :
884 676 : n->key = (Expr *) key;
885 676 : n->value = castNode(JsonValueExpr, value);
886 :
887 676 : return (Node *) n;
888 : }
889 :
890 : /*
891 : * makeJsonIsPredicate -
892 : * creates a JsonIsPredicate node
893 : */
894 : Node *
895 694 : makeJsonIsPredicate(Node *expr, JsonFormat *format, JsonValueType item_type,
896 : bool unique_keys, int location)
897 : {
898 694 : JsonIsPredicate *n = makeNode(JsonIsPredicate);
899 :
900 694 : n->expr = expr;
901 694 : n->format = format;
902 694 : n->item_type = item_type;
903 694 : n->unique_keys = unique_keys;
904 694 : n->location = location;
905 :
906 694 : return (Node *) n;
907 : }
|