PostgreSQL Source Code  git master
makefuncs.c File Reference
#include "postgres.h"
#include "catalog/pg_class.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "utils/lsyscache.h"
Include dependency graph for makefuncs.c:

Go to the source code of this file.

Functions

A_ExprmakeA_Expr (A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr, int location)
 
A_ExprmakeSimpleA_Expr (A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
 
VarmakeVar (Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
 
VarmakeVarFromTargetEntry (Index varno, TargetEntry *tle)
 
VarmakeWholeRowVar (RangeTblEntry *rte, Index varno, Index varlevelsup, bool allowScalar)
 
TargetEntrymakeTargetEntry (Expr *expr, AttrNumber resno, char *resname, bool resjunk)
 
TargetEntryflatCopyTargetEntry (TargetEntry *src_tle)
 
FromExprmakeFromExpr (List *fromlist, Node *quals)
 
ConstmakeConst (Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
 
ConstmakeNullConst (Oid consttype, int32 consttypmod, Oid constcollid)
 
NodemakeBoolConst (bool value, bool isnull)
 
ExprmakeBoolExpr (BoolExprType boolop, List *args, int location)
 
AliasmakeAlias (const char *aliasname, List *colnames)
 
RelabelTypemakeRelabelType (Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
 
RangeVarmakeRangeVar (char *schemaname, char *relname, int location)
 
TypeNamemakeTypeName (char *typnam)
 
TypeNamemakeTypeNameFromNameList (List *names)
 
TypeNamemakeTypeNameFromOid (Oid typeOid, int32 typmod)
 
ColumnDefmakeColumnDef (const char *colname, Oid typeOid, int32 typmod, Oid collOid)
 
FuncExprmakeFuncExpr (Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
 
DefElemmakeDefElem (char *name, Node *arg, int location)
 
DefElemmakeDefElemExtended (char *nameSpace, char *name, Node *arg, DefElemAction defaction, int location)
 
FuncCallmakeFuncCall (List *name, List *args, int location)
 
Exprmake_opclause (Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
 
Exprmake_andclause (List *andclauses)
 
Exprmake_orclause (List *orclauses)
 
Exprmake_notclause (Expr *notclause)
 
Nodemake_and_qual (Node *qual1, Node *qual2)
 
Exprmake_ands_explicit (List *andclauses)
 
Listmake_ands_implicit (Expr *clause)
 
IndexInfomakeIndexInfo (int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool isready, bool concurrent)
 
GroupingSetmakeGroupingSet (GroupingSetKind kind, List *content, int location)
 
VacuumRelationmakeVacuumRelation (RangeVar *relation, Oid oid, List *va_cols)
 

Function Documentation

◆ flatCopyTargetEntry()

TargetEntry* flatCopyTargetEntry ( TargetEntry src_tle)

Definition at line 271 of file makefuncs.c.

References Assert, IsA, and makeNode.

Referenced by expand_targetlist(), process_matched_tle(), rewriteTargetListIU(), set_dummy_tlist_references(), and set_upper_references().

272 {
274 
275  Assert(IsA(src_tle, TargetEntry));
276  memcpy(tle, src_tle, sizeof(TargetEntry));
277  return tle;
278 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:738

◆ make_and_qual()

Node* make_and_qual ( Node qual1,
Node qual2 
)

Definition at line 688 of file makefuncs.c.

References list_make2, and make_andclause().

Referenced by AddQual(), and subquery_push_qual().

689 {
690  if (qual1 == NULL)
691  return qual2;
692  if (qual2 == NULL)
693  return qual1;
694  return (Node *) make_andclause(list_make2(qual1, qual2));
695 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
Definition: nodes.h:529
Expr * make_andclause(List *andclauses)
Definition: makefuncs.c:635

◆ make_andclause()

Expr* make_andclause ( List andclauses)

Definition at line 635 of file makefuncs.c.

References AND_EXPR, BoolExpr::args, BoolExpr::boolop, BoolExpr::location, and makeNode.

Referenced by eval_const_expressions_mutator(), find_duplicate_ors(), make_and_qual(), make_ands_explicit(), make_sub_restrictinfos(), negate_clause(), process_duplicate_ors(), process_sublinks_mutator(), and pull_up_sublinks_qual_recurse().

636 {
637  BoolExpr *expr = makeNode(BoolExpr);
638 
639  expr->boolop = AND_EXPR;
640  expr->args = andclauses;
641  expr->location = -1;
642  return (Expr *) expr;
643 }
int location
Definition: primnodes.h:584
BoolExprType boolop
Definition: primnodes.h:582
#define makeNode(_type_)
Definition: nodes.h:577
List * args
Definition: primnodes.h:583

◆ make_ands_explicit()

Expr* make_ands_explicit ( List andclauses)

Definition at line 707 of file makefuncs.c.

References linitial, list_length(), make_andclause(), makeBoolConst(), and NIL.

Referenced by ATExecAttachPartition(), check_default_partition_contents(), convert_EXISTS_to_ANY(), create_bitmap_subplan(), ExecInitCheck(), extract_or_clause(), get_proposed_default_constraint(), get_qual_for_list(), show_qual(), and UpdateIndexRelation().

708 {
709  if (andclauses == NIL)
710  return (Expr *) makeBoolConst(true, false);
711  else if (list_length(andclauses) == 1)
712  return (Expr *) linitial(andclauses);
713  else
714  return make_andclause(andclauses);
715 }
#define NIL
Definition: pg_list.h:65
#define linitial(l)
Definition: pg_list.h:195
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:357
Expr * make_andclause(List *andclauses)
Definition: makefuncs.c:635
static int list_length(const List *l)
Definition: pg_list.h:169

◆ make_ands_implicit()

List* make_ands_implicit ( Expr clause)

Definition at line 718 of file makefuncs.c.

References DatumGetBool, is_andclause(), IsA, list_make1, and NIL.

Referenced by apply_child_basequals(), ConstraintImpliedByRelConstraint(), convert_EXISTS_to_ANY(), cost_subplan(), DefineIndex(), DoCopy(), get_proposed_default_constraint(), get_relation_constraints(), index_concurrently_create_copy(), preprocess_expression(), RelationGetIndexPredicate(), test_predtest(), and TriggerEnabled().

719 {
720  /*
721  * NB: because the parser sets the qual field to NULL in a query that has
722  * no WHERE clause, we must consider a NULL input clause as TRUE, even
723  * though one might more reasonably think it FALSE.
724  */
725  if (clause == NULL)
726  return NIL; /* NULL -> NIL list == TRUE */
727  else if (is_andclause(clause))
728  return ((BoolExpr *) clause)->args;
729  else if (IsA(clause, Const) &&
730  !((Const *) clause)->constisnull &&
731  DatumGetBool(((Const *) clause)->constvalue))
732  return NIL; /* constant TRUE input -> NIL list */
733  else
734  return list_make1(clause);
735 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:94
#define list_make1(x1)
Definition: pg_list.h:227
#define DatumGetBool(X)
Definition: postgres.h:393

◆ make_notclause()

Expr* make_notclause ( Expr notclause)

Definition at line 667 of file makefuncs.c.

References BoolExpr::args, BoolExpr::boolop, list_make1, BoolExpr::location, makeNode, and NOT_EXPR.

Referenced by negate_clause().

668 {
669  BoolExpr *expr = makeNode(BoolExpr);
670 
671  expr->boolop = NOT_EXPR;
672  expr->args = list_make1(notclause);
673  expr->location = -1;
674  return (Expr *) expr;
675 }
int location
Definition: primnodes.h:584
#define list_make1(x1)
Definition: pg_list.h:227
BoolExprType boolop
Definition: primnodes.h:582
#define makeNode(_type_)
Definition: nodes.h:577
List * args
Definition: primnodes.h:583

◆ make_opclause()

Expr* make_opclause ( Oid  opno,
Oid  opresulttype,
bool  opretset,
Expr leftop,
Expr rightop,
Oid  opcollid,
Oid  inputcollid 
)

Definition at line 609 of file makefuncs.c.

References OpExpr::args, OpExpr::inputcollid, InvalidOid, list_make1, list_make2, OpExpr::location, makeNode, OpExpr::opcollid, OpExpr::opfuncid, OpExpr::opno, OpExpr::opresulttype, and OpExpr::opretset.

Referenced by build_implied_join_equality(), convert_EXISTS_to_ANY(), expand_indexqual_rowcompare(), make_partition_op_expr(), match_boolean_index_clause(), match_clause_to_partition_key(), match_network_subset(), match_pattern_prefix(), operator_predicate_proof(), and process_implied_equality().

612 {
613  OpExpr *expr = makeNode(OpExpr);
614 
615  expr->opno = opno;
616  expr->opfuncid = InvalidOid;
617  expr->opresulttype = opresulttype;
618  expr->opretset = opretset;
619  expr->opcollid = opcollid;
620  expr->inputcollid = inputcollid;
621  if (rightop)
622  expr->args = list_make2(leftop, rightop);
623  else
624  expr->args = list_make1(leftop);
625  expr->location = -1;
626  return (Expr *) expr;
627 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
#define list_make1(x1)
Definition: pg_list.h:227
Oid opresulttype
Definition: primnodes.h:518
int location
Definition: primnodes.h:523
Oid opcollid
Definition: primnodes.h:520
Oid opfuncid
Definition: primnodes.h:517
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:577
Oid inputcollid
Definition: primnodes.h:521
Oid opno
Definition: primnodes.h:516
List * args
Definition: primnodes.h:522
bool opretset
Definition: primnodes.h:519

◆ make_orclause()

Expr* make_orclause ( List orclauses)

Definition at line 651 of file makefuncs.c.

References BoolExpr::args, BoolExpr::boolop, BoolExpr::location, makeNode, and OR_EXPR.

Referenced by create_bitmap_subplan(), create_tidscan_plan(), eval_const_expressions_mutator(), ExplainNode(), extract_or_clause(), make_sub_restrictinfos(), negate_clause(), process_duplicate_ors(), and process_sublinks_mutator().

652 {
653  BoolExpr *expr = makeNode(BoolExpr);
654 
655  expr->boolop = OR_EXPR;
656  expr->args = orclauses;
657  expr->location = -1;
658  return (Expr *) expr;
659 }
int location
Definition: primnodes.h:584
BoolExprType boolop
Definition: primnodes.h:582
#define makeNode(_type_)
Definition: nodes.h:577
List * args
Definition: primnodes.h:583

◆ makeA_Expr()

A_Expr* makeA_Expr ( A_Expr_Kind  kind,
List name,
Node lexpr,
Node rexpr,
int  location 
)

Definition at line 30 of file makefuncs.c.

References A_Expr::kind, A_Expr::lexpr, A_Expr::location, makeNode, A_Expr::name, name, and A_Expr::rexpr.

Referenced by transformAExprBetween().

32 {
33  A_Expr *a = makeNode(A_Expr);
34 
35  a->kind = kind;
36  a->name = name;
37  a->lexpr = lexpr;
38  a->rexpr = rexpr;
39  a->location = location;
40  return a;
41 }
A_Expr_Kind kind
Definition: parsenodes.h:276
Node * rexpr
Definition: parsenodes.h:279
int location
Definition: parsenodes.h:280
Node * lexpr
Definition: parsenodes.h:278
#define makeNode(_type_)
Definition: nodes.h:577
List * name
Definition: parsenodes.h:277
const char * name
Definition: encode.c:561

◆ makeAlias()

◆ makeBoolConst()

Node* makeBoolConst ( bool  value,
bool  isnull 
)

Definition at line 357 of file makefuncs.c.

References BoolGetDatum, InvalidOid, and makeConst().

Referenced by create_append_plan(), eval_const_expressions_mutator(), find_duplicate_ors(), get_qual_for_range(), make_ands_explicit(), make_row_distinct_op(), match_boolean_index_clause(), match_boolean_partition_clause(), negate_clause(), process_duplicate_ors(), and transformAExprOf().

358 {
359  /* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
360  return (Node *) makeConst(BOOLOID, -1, InvalidOid, 1,
361  BoolGetDatum(value), isnull, true);
362 }
Definition: nodes.h:529
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:299
#define BoolGetDatum(X)
Definition: postgres.h:402
#define InvalidOid
Definition: postgres_ext.h:36
static struct @143 value

◆ makeBoolExpr()

◆ makeColumnDef()

ColumnDef* makeColumnDef ( const char *  colname,
Oid  typeOid,
int32  typmod,
Oid  collOid 
)

Definition at line 490 of file makefuncs.c.

References ColumnDef::collClause, ColumnDef::collOid, ColumnDef::colname, ColumnDef::constraints, ColumnDef::cooked_default, ColumnDef::fdwoptions, ColumnDef::inhcount, ColumnDef::is_from_type, ColumnDef::is_local, ColumnDef::is_not_null, ColumnDef::location, makeNode, makeTypeNameFromOid(), NIL, pstrdup(), ColumnDef::raw_default, ColumnDef::storage, and ColumnDef::typeName.

Referenced by create_ctas_nodata(), DefineVirtualRelation(), and intorel_startup().

491 {
493 
494  n->colname = pstrdup(colname);
495  n->typeName = makeTypeNameFromOid(typeOid, typmod);
496  n->inhcount = 0;
497  n->is_local = true;
498  n->is_not_null = false;
499  n->is_from_type = false;
500  n->storage = 0;
501  n->raw_default = NULL;
502  n->cooked_default = NULL;
503  n->collClause = NULL;
504  n->collOid = collOid;
505  n->constraints = NIL;
506  n->fdwoptions = NIL;
507  n->location = -1;
508 
509  return n;
510 }
#define NIL
Definition: pg_list.h:65
char storage
Definition: parsenodes.h:653
bool is_local
Definition: parsenodes.h:650
List * constraints
Definition: parsenodes.h:662
char * pstrdup(const char *in)
Definition: mcxt.c:1186
bool is_not_null
Definition: parsenodes.h:651
Node * cooked_default
Definition: parsenodes.h:655
Oid collOid
Definition: parsenodes.h:661
List * fdwoptions
Definition: parsenodes.h:663
int location
Definition: parsenodes.h:664
Node * raw_default
Definition: parsenodes.h:654
TypeName * makeTypeNameFromOid(Oid typeOid, int32 typmod)
Definition: makefuncs.c:472
bool is_from_type
Definition: parsenodes.h:652
#define makeNode(_type_)
Definition: nodes.h:577
TypeName * typeName
Definition: parsenodes.h:648
CollateClause * collClause
Definition: parsenodes.h:660
int inhcount
Definition: parsenodes.h:649
char * colname
Definition: parsenodes.h:647

◆ makeConst()

Const* makeConst ( Oid  consttype,
int32  consttypmod,
Oid  constcollid,
int  constlen,
Datum  constvalue,
bool  constisnull,
bool  constbyval 
)

Definition at line 299 of file makefuncs.c.

References Const::constbyval, Const::constcollid, Const::constisnull, Const::constlen, Const::consttype, Const::consttypmod, Const::constvalue, Const::location, makeNode, PG_DETOAST_DATUM, and PointerGetDatum.

Referenced by add_security_quals(), add_with_check_options(), adjust_partition_tlist(), build_coercion_expression(), build_minmax_path(), check_sql_fn_retval(), eval_const_expressions_mutator(), evaluate_expr(), expand_targetlist(), generate_setop_tlist(), get_qual_for_hash(), get_qual_for_list(), get_typdefault(), make_const(), makeBoolConst(), makeNullConst(), match_clause_to_partition_key(), match_network_subset(), pattern_fixed_prefix(), RelationGetDummyIndexExpressions(), rewriteTargetListIU(), rewriteValuesRTE(), scalararraysel(), set_fn_opclass_options(), string_to_bytea_const(), string_to_const(), and transformContainerSubscripts().

306 {
307  Const *cnst = makeNode(Const);
308 
309  /*
310  * If it's a varlena value, force it to be in non-expanded (non-toasted)
311  * format; this avoids any possible dependency on external values and
312  * improves consistency of representation, which is important for equal().
313  */
314  if (!constisnull && constlen == -1)
315  constvalue = PointerGetDatum(PG_DETOAST_DATUM(constvalue));
316 
317  cnst->consttype = consttype;
318  cnst->consttypmod = consttypmod;
319  cnst->constcollid = constcollid;
320  cnst->constlen = constlen;
321  cnst->constvalue = constvalue;
322  cnst->constisnull = constisnull;
323  cnst->constbyval = constbyval;
324  cnst->location = -1; /* "unknown" */
325 
326  return cnst;
327 }
Datum constvalue
Definition: primnodes.h:214
bool constbyval
Definition: primnodes.h:217
#define PointerGetDatum(X)
Definition: postgres.h:556
int constlen
Definition: primnodes.h:213
Oid consttype
Definition: primnodes.h:210
Oid constcollid
Definition: primnodes.h:212
int location
Definition: primnodes.h:221
#define makeNode(_type_)
Definition: nodes.h:577
int32 consttypmod
Definition: primnodes.h:211
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
bool constisnull
Definition: primnodes.h:215

◆ makeDefElem()

DefElem* makeDefElem ( char *  name,
Node arg,
int  location 
)

Definition at line 546 of file makefuncs.c.

References arg, DefElem::arg, DefElem::defaction, DEFELEM_UNSPEC, DefElem::defname, DefElem::defnamespace, DefElem::location, makeNode, and name.

Referenced by buildDefItem(), DefineView(), fileGetForeignPaths(), generateSerialExtraStmts(), get_file_fdw_attribute_options(), pg_logical_slot_get_changes_guts(), sequence_options(), transformAlterTableStmt(), and untransformRelOptions().

547 {
548  DefElem *res = makeNode(DefElem);
549 
550  res->defnamespace = NULL;
551  res->defname = name;
552  res->arg = arg;
553  res->defaction = DEFELEM_UNSPEC;
554  res->location = location;
555 
556  return res;
557 }
char * defnamespace
Definition: parsenodes.h:731
DefElemAction defaction
Definition: parsenodes.h:734
int location
Definition: parsenodes.h:735
Node * arg
Definition: parsenodes.h:733
#define makeNode(_type_)
Definition: nodes.h:577
const char * name
Definition: encode.c:561
void * arg
char * defname
Definition: parsenodes.h:732

◆ makeDefElemExtended()

DefElem* makeDefElemExtended ( char *  nameSpace,
char *  name,
Node arg,
DefElemAction  defaction,
int  location 
)

Definition at line 564 of file makefuncs.c.

References arg, DefElem::arg, DefElem::defaction, DefElem::defname, DefElem::defnamespace, DefElem::location, makeNode, and name.

566 {
567  DefElem *res = makeNode(DefElem);
568 
569  res->defnamespace = nameSpace;
570  res->defname = name;
571  res->arg = arg;
572  res->defaction = defaction;
573  res->location = location;
574 
575  return res;
576 }
char * defnamespace
Definition: parsenodes.h:731
DefElemAction defaction
Definition: parsenodes.h:734
int location
Definition: parsenodes.h:735
Node * arg
Definition: parsenodes.h:733
#define makeNode(_type_)
Definition: nodes.h:577
const char * name
Definition: encode.c:561
void * arg
char * defname
Definition: parsenodes.h:732

◆ makeFromExpr()

FromExpr* makeFromExpr ( List fromlist,
Node quals 
)

◆ makeFuncCall()

FuncCall* makeFuncCall ( List name,
List args,
int  location 
)

Definition at line 585 of file makefuncs.c.

References FuncCall::agg_distinct, FuncCall::agg_filter, FuncCall::agg_order, FuncCall::agg_star, FuncCall::agg_within_group, generate_unaccent_rules::args, FuncCall::args, FuncCall::func_variadic, FuncCall::funcname, FuncCall::location, makeNode, name, NIL, and FuncCall::over.

Referenced by test_rls_hooks_permissive(), test_rls_hooks_restrictive(), transformColumnDefinition(), and transformRangeFunction().

586 {
587  FuncCall *n = makeNode(FuncCall);
588 
589  n->funcname = name;
590  n->args = args;
591  n->agg_order = NIL;
592  n->agg_filter = NULL;
593  n->agg_within_group = false;
594  n->agg_star = false;
595  n->agg_distinct = false;
596  n->func_variadic = false;
597  n->over = NULL;
598  n->location = location;
599  return n;
600 }
#define NIL
Definition: pg_list.h:65
Node * agg_filter
Definition: parsenodes.h:354
int location
Definition: parsenodes.h:360
List * agg_order
Definition: parsenodes.h:353
struct WindowDef * over
Definition: parsenodes.h:359
bool func_variadic
Definition: parsenodes.h:358
#define makeNode(_type_)
Definition: nodes.h:577
List * args
Definition: parsenodes.h:352
const char * name
Definition: encode.c:561
List * funcname
Definition: parsenodes.h:351
bool agg_within_group
Definition: parsenodes.h:355
bool agg_distinct
Definition: parsenodes.h:357
bool agg_star
Definition: parsenodes.h:356

◆ makeFuncExpr()

FuncExpr* makeFuncExpr ( Oid  funcid,
Oid  rettype,
List args,
Oid  funccollid,
Oid  inputcollid,
CoercionForm  fformat 
)

Definition at line 519 of file makefuncs.c.

References generate_unaccent_rules::args, FuncExpr::args, FuncExpr::funccollid, FuncExpr::funcformat, FuncExpr::funcid, FuncExpr::funcresulttype, FuncExpr::funcretset, FuncExpr::funcvariadic, FuncExpr::inputcollid, FuncExpr::location, and makeNode.

Referenced by build_aggregate_combinefn_expr(), build_aggregate_deserialfn_expr(), build_aggregate_finalfn_expr(), build_aggregate_serialfn_expr(), build_aggregate_transfn_expr(), build_coercion_expression(), and get_qual_for_hash().

521 {
522  FuncExpr *funcexpr;
523 
524  funcexpr = makeNode(FuncExpr);
525  funcexpr->funcid = funcid;
526  funcexpr->funcresulttype = rettype;
527  funcexpr->funcretset = false; /* only allowed case here */
528  funcexpr->funcvariadic = false; /* only allowed case here */
529  funcexpr->funcformat = fformat;
530  funcexpr->funccollid = funccollid;
531  funcexpr->inputcollid = inputcollid;
532  funcexpr->args = args;
533  funcexpr->location = -1;
534 
535  return funcexpr;
536 }
Oid funcresulttype
Definition: primnodes.h:470
List * args
Definition: primnodes.h:477
Oid funccollid
Definition: primnodes.h:475
bool funcretset
Definition: primnodes.h:471
CoercionForm funcformat
Definition: primnodes.h:474
Oid funcid
Definition: primnodes.h:469
#define makeNode(_type_)
Definition: nodes.h:577
Oid inputcollid
Definition: primnodes.h:476
int location
Definition: primnodes.h:478
bool funcvariadic
Definition: primnodes.h:472

◆ makeGroupingSet()

GroupingSet* makeGroupingSet ( GroupingSetKind  kind,
List content,
int  location 
)

Definition at line 793 of file makefuncs.c.

References GroupingSet::content, GroupingSet::kind, GroupingSet::location, and makeNode.

Referenced by flatten_grouping_sets(), transformGroupClause(), and transformGroupingSet().

794 {
796 
797  n->kind = kind;
798  n->content = content;
799  n->location = location;
800  return n;
801 }
List * content
Definition: parsenodes.h:1327
GroupingSetKind kind
Definition: parsenodes.h:1326
#define makeNode(_type_)
Definition: nodes.h:577

◆ makeIndexInfo()

IndexInfo* makeIndexInfo ( int  numattrs,
int  numkeyattrs,
Oid  amoid,
List expressions,
List predicates,
bool  unique,
bool  isready,
bool  concurrent 
)

Definition at line 742 of file makefuncs.c.

References Assert, CurrentMemoryContext, IndexInfo::ii_Am, IndexInfo::ii_AmCache, IndexInfo::ii_BrokenHotChain, IndexInfo::ii_Concurrent, IndexInfo::ii_Context, IndexInfo::ii_ExclusionOps, IndexInfo::ii_ExclusionProcs, IndexInfo::ii_ExclusionStrats, IndexInfo::ii_Expressions, IndexInfo::ii_ExpressionsState, IndexInfo::ii_NumIndexAttrs, IndexInfo::ii_NumIndexKeyAttrs, IndexInfo::ii_OpclassOptions, IndexInfo::ii_ParallelWorkers, IndexInfo::ii_Predicate, IndexInfo::ii_PredicateState, IndexInfo::ii_ReadyForInserts, IndexInfo::ii_Unique, IndexInfo::ii_UniqueOps, IndexInfo::ii_UniqueProcs, IndexInfo::ii_UniqueStrats, makeNode, and NIL.

Referenced by BuildDummyIndexInfo(), BuildIndexInfo(), CheckIndexCompatible(), DefineIndex(), and index_concurrently_create_copy().

744 {
746 
747  n->ii_NumIndexAttrs = numattrs;
748  n->ii_NumIndexKeyAttrs = numkeyattrs;
749  Assert(n->ii_NumIndexKeyAttrs != 0);
751  n->ii_Unique = unique;
752  n->ii_ReadyForInserts = isready;
753  n->ii_Concurrent = concurrent;
754 
755  /* expressions */
756  n->ii_Expressions = expressions;
758 
759  /* predicates */
760  n->ii_Predicate = predicates;
761  n->ii_PredicateState = NULL;
762 
763  /* exclusion constraints */
764  n->ii_ExclusionOps = NULL;
765  n->ii_ExclusionProcs = NULL;
766  n->ii_ExclusionStrats = NULL;
767 
768  /* opclass options */
769  n->ii_OpclassOptions = NULL;
770 
771  /* speculative inserts */
772  n->ii_UniqueOps = NULL;
773  n->ii_UniqueProcs = NULL;
774  n->ii_UniqueStrats = NULL;
775 
776  /* initialize index-build state to default */
777  n->ii_BrokenHotChain = false;
778  n->ii_ParallelWorkers = 0;
779 
780  /* set up for possible use by index AM */
781  n->ii_Am = amoid;
782  n->ii_AmCache = NULL;
784 
785  return n;
786 }
#define NIL
Definition: pg_list.h:65
MemoryContext ii_Context
Definition: execnodes.h:179
uint16 * ii_UniqueStrats
Definition: execnodes.h:170
List * ii_Predicate
Definition: execnodes.h:163
ExprState * ii_PredicateState
Definition: execnodes.h:164
Oid * ii_ExclusionProcs
Definition: execnodes.h:166
Oid * ii_UniqueOps
Definition: execnodes.h:168
List * ii_ExpressionsState
Definition: execnodes.h:162
int ii_NumIndexKeyAttrs
Definition: execnodes.h:159
Oid * ii_UniqueProcs
Definition: execnodes.h:169
bool ii_BrokenHotChain
Definition: execnodes.h:175
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
bool ii_ReadyForInserts
Definition: execnodes.h:173
void * ii_AmCache
Definition: execnodes.h:178
int ii_NumIndexAttrs
Definition: execnodes.h:158
bool ii_Unique
Definition: execnodes.h:172
#define makeNode(_type_)
Definition: nodes.h:577
List * ii_Expressions
Definition: execnodes.h:161
#define Assert(condition)
Definition: c.h:738
int ii_ParallelWorkers
Definition: execnodes.h:176
bool ii_Concurrent
Definition: execnodes.h:174
Oid * ii_ExclusionOps
Definition: execnodes.h:165
uint16 * ii_ExclusionStrats
Definition: execnodes.h:167
Datum * ii_OpclassOptions
Definition: execnodes.h:171
Oid ii_Am
Definition: execnodes.h:177

◆ makeNullConst()

Const* makeNullConst ( Oid  consttype,
int32  consttypmod,
Oid  constcollid 
)

Definition at line 337 of file makefuncs.c.

References get_typlenbyval(), and makeConst().

Referenced by ATExecAddColumn(), build_subplan(), BuildOnConflictExcludedTargetlist(), coerce_record_to_complex(), eval_const_expressions_mutator(), evaluate_function(), ExecInitExprRec(), expandRTE(), expandTupleDesc(), remove_unused_subquery_outputs(), ReplaceVarsFromTargetList_callback(), and transformAssignedExpr().

338 {
339  int16 typLen;
340  bool typByVal;
341 
342  get_typlenbyval(consttype, &typLen, &typByVal);
343  return makeConst(consttype,
344  consttypmod,
345  constcollid,
346  (int) typLen,
347  (Datum) 0,
348  true,
349  typByVal);
350 }
signed short int16
Definition: c.h:354
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:299
uintptr_t Datum
Definition: postgres.h:367
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2139

◆ makeRangeVar()

RangeVar* makeRangeVar ( char *  schemaname,
char *  relname,
int  location 
)

Definition at line 422 of file makefuncs.c.

References RangeVar::alias, RangeVar::catalogname, RangeVar::inh, RangeVar::location, makeNode, relname, RangeVar::relname, RangeVar::relpersistence, and RangeVar::schemaname.

Referenced by AlterTableNamespace(), ATParseTransformCmd(), autovacuum_do_vac_analyze(), boot_openrel(), BootstrapToastTable(), DoCopy(), ExpandColumnRefStar(), fetch_table_list(), generateSerialExtraStmts(), logicalrep_rel_open(), LookupTypeNameExtended(), makeRangeVarFromNameList(), plpgsql_parse_cwordrowtype(), plpgsql_parse_cwordtype(), transformAlterTableStmt(), and transformColumnRef().

423 {
424  RangeVar *r = makeNode(RangeVar);
425 
426  r->catalogname = NULL;
427  r->schemaname = schemaname;
428  r->relname = relname;
429  r->inh = true;
430  r->relpersistence = RELPERSISTENCE_PERMANENT;
431  r->alias = NULL;
432  r->location = location;
433 
434  return r;
435 }
NameData relname
Definition: pg_class.h:38
char * schemaname
Definition: primnodes.h:67
int location
Definition: primnodes.h:73
char * relname
Definition: primnodes.h:68
bool inh
Definition: primnodes.h:69
#define makeNode(_type_)
Definition: nodes.h:577
char relpersistence
Definition: primnodes.h:71
Alias * alias
Definition: primnodes.h:72
char * catalogname
Definition: primnodes.h:66

◆ makeRelabelType()

RelabelType* makeRelabelType ( Expr arg,
Oid  rtype,
int32  rtypmod,
Oid  rcollid,
CoercionForm  rformat 
)

Definition at line 402 of file makefuncs.c.

References arg, RelabelType::arg, RelabelType::location, makeNode, RelabelType::relabelformat, RelabelType::resultcollid, RelabelType::resulttype, and RelabelType::resulttypmod.

Referenced by assign_hypothetical_collations(), buildMergedJoinVar(), canonicalize_ec_expression(), coerce_type(), generate_setop_tlist(), make_partition_op_expr(), and relabel_to_typmod().

404 {
406 
407  r->arg = arg;
408  r->resulttype = rtype;
409  r->resulttypmod = rtypmod;
410  r->resultcollid = rcollid;
411  r->relabelformat = rformat;
412  r->location = -1;
413 
414  return r;
415 }
Expr * arg
Definition: primnodes.h:814
Oid resulttype
Definition: primnodes.h:815
Oid resultcollid
Definition: primnodes.h:817
#define makeNode(_type_)
Definition: nodes.h:577
void * arg
int32 resulttypmod
Definition: primnodes.h:816
CoercionForm relabelformat
Definition: primnodes.h:818
int location
Definition: primnodes.h:819

◆ makeSimpleA_Expr()

A_Expr* makeSimpleA_Expr ( A_Expr_Kind  kind,
char *  name,
Node lexpr,
Node rexpr,
int  location 
)

Definition at line 48 of file makefuncs.c.

References A_Expr::kind, A_Expr::lexpr, list_make1, A_Expr::location, makeNode, makeString(), A_Expr::name, and A_Expr::rexpr.

Referenced by test_rls_hooks_permissive(), test_rls_hooks_restrictive(), transformAExprBetween(), transformCaseExpr(), and transformJoinUsingClause().

50 {
51  A_Expr *a = makeNode(A_Expr);
52 
53  a->kind = kind;
54  a->name = list_make1(makeString((char *) name));
55  a->lexpr = lexpr;
56  a->rexpr = rexpr;
57  a->location = location;
58  return a;
59 }
Value * makeString(char *str)
Definition: value.c:53
A_Expr_Kind kind
Definition: parsenodes.h:276
#define list_make1(x1)
Definition: pg_list.h:227
Node * rexpr
Definition: parsenodes.h:279
int location
Definition: parsenodes.h:280
Node * lexpr
Definition: parsenodes.h:278
#define makeNode(_type_)
Definition: nodes.h:577
List * name
Definition: parsenodes.h:277
const char * name
Definition: encode.c:561

◆ makeTargetEntry()

TargetEntry* makeTargetEntry ( Expr expr,
AttrNumber  resno,
char *  resname,
bool  resjunk 
)

Definition at line 238 of file makefuncs.c.

References TargetEntry::expr, InvalidOid, makeNode, TargetEntry::resjunk, TargetEntry::resname, TargetEntry::resno, TargetEntry::resorigcol, TargetEntry::resorigtbl, and TargetEntry::ressortgroupref.

Referenced by add_to_flat_tlist(), adjust_partition_tlist(), ApplyRetrieveRule(), build_index_tlist(), build_minmax_path(), build_path_tlist(), build_physical_tlist(), build_remote_returning(), BuildOnConflictExcludedTargetlist(), check_sql_fn_retval(), coerce_fn_result_column(), convert_combining_aggrefs(), convert_EXISTS_to_ANY(), create_unique_plan(), determineRecursiveColTypes(), ExecInitSubPlan(), expand_inherited_rtentry(), expand_targetlist(), expandNSItemAttrs(), ExpandRowReference(), foreign_grouping_ok(), generate_append_tlist(), generate_setop_tlist(), make_tlist_from_pathtarget(), postgresAddForeignUpdateTargets(), prepare_sort_from_pathkeys(), preprocess_targetlist(), pull_up_constant_function(), pull_up_simple_values(), rebuild_fdw_scan_tlist(), rewriteTargetListIU(), rewriteTargetListUD(), transformAggregateCall(), transformInsertStmt(), transformMultiAssignRef(), transformSetOperationStmt(), transformSetOperationTree(), and transformTargetEntry().

242 {
244 
245  tle->expr = expr;
246  tle->resno = resno;
247  tle->resname = resname;
248 
249  /*
250  * We always set these fields to 0. If the caller wants to change them he
251  * must do so explicitly. Few callers do that, so omitting these
252  * arguments reduces the chance of error.
253  */
254  tle->ressortgroupref = 0;
255  tle->resorigtbl = InvalidOid;
256  tle->resorigcol = 0;
257 
258  tle->resjunk = resjunk;
259 
260  return tle;
261 }
Oid resorigtbl
Definition: primnodes.h:1412
char * resname
Definition: primnodes.h:1409
bool resjunk
Definition: primnodes.h:1414
AttrNumber resno
Definition: primnodes.h:1408
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:577
Expr * expr
Definition: primnodes.h:1407
AttrNumber resorigcol
Definition: primnodes.h:1413
Index ressortgroupref
Definition: primnodes.h:1410

◆ makeTypeName()

TypeName* makeTypeName ( char *  typnam)

Definition at line 444 of file makefuncs.c.

References list_make1, makeString(), and makeTypeNameFromNameList().

Referenced by plpgsql_parse_wordrowtype(), and plpgsql_parse_wordtype().

445 {
447 }
Value * makeString(char *str)
Definition: value.c:53
#define list_make1(x1)
Definition: pg_list.h:227
TypeName * makeTypeNameFromNameList(List *names)
Definition: makefuncs.c:456

◆ makeTypeNameFromNameList()

◆ makeTypeNameFromOid()

TypeName* makeTypeNameFromOid ( Oid  typeOid,
int32  typmod 
)

Definition at line 472 of file makefuncs.c.

References TypeName::location, makeNode, TypeName::typemod, and TypeName::typeOid.

Referenced by DefineSequence(), generateSerialExtraStmts(), makeColumnDef(), MergeAttributes(), transformAlterTableStmt(), transformOfType(), and transformTableLikeClause().

473 {
474  TypeName *n = makeNode(TypeName);
475 
476  n->typeOid = typeOid;
477  n->typemod = typmod;
478  n->location = -1;
479  return n;
480 }
Oid typeOid
Definition: parsenodes.h:211
#define makeNode(_type_)
Definition: nodes.h:577
int location
Definition: parsenodes.h:217
int32 typemod
Definition: parsenodes.h:215

◆ makeVacuumRelation()

VacuumRelation* makeVacuumRelation ( RangeVar relation,
Oid  oid,
List va_cols 
)

Definition at line 808 of file makefuncs.c.

References makeNode, VacuumRelation::oid, VacuumRelation::relation, and VacuumRelation::va_cols.

Referenced by autovacuum_do_vac_analyze(), expand_vacuum_rel(), and get_all_vacuum_rels().

809 {
811 
812  v->relation = relation;
813  v->oid = oid;
814  v->va_cols = va_cols;
815  return v;
816 }
RangeVar * relation
Definition: parsenodes.h:3240
#define makeNode(_type_)
Definition: nodes.h:577

◆ makeVar()

Var* makeVar ( Index  varno,
AttrNumber  varattno,
Oid  vartype,
int32  vartypmod,
Oid  varcollid,
Index  varlevelsup 
)

Definition at line 66 of file makefuncs.c.

References Var::location, makeNode, Var::varattno, Var::varattnosyn, Var::varcollid, Var::varlevelsup, Var::varno, Var::varnosyn, Var::vartype, and Var::vartypmod.

Referenced by ATPrepAlterColumnType(), build_index_tlist(), build_physical_tlist(), build_remote_returning(), BuildOnConflictExcludedTargetlist(), buildVarFromNSColumn(), eval_const_expressions_mutator(), expand_inherited_rtentry(), expand_targetlist(), expandNSItemVars(), expandRTE(), expandTupleDesc(), fix_indexqual_operand(), generate_append_tlist(), generate_setop_tlist(), get_qual_for_hash(), get_qual_for_list(), get_range_key_properties(), get_range_nulltest(), get_relation_constraints(), make_inh_translation_list(), makeVarFromTargetEntry(), makeWholeRowVar(), NotNullImpliedByRelConstraints(), PartConstraintImpliedByRelConstraint(), postgresAddForeignUpdateTargets(), preprocess_targetlist(), rewriteTargetListIU(), rewriteTargetListUD(), scanNSItemForColumn(), set_baserel_partition_key_exprs(), set_dummy_tlist_references(), transformAssignedExpr(), and transformSetOperationStmt().

72 {
73  Var *var = makeNode(Var);
74 
75  var->varno = varno;
76  var->varattno = varattno;
77  var->vartype = vartype;
78  var->vartypmod = vartypmod;
79  var->varcollid = varcollid;
80  var->varlevelsup = varlevelsup;
81 
82  /*
83  * Only a few callers need to make Var nodes with varnosyn/varattnosyn
84  * different from varno/varattno. We don't provide separate arguments for
85  * them, but just initialize them to the given varno/varattno. This
86  * reduces code clutter and chance of error for most callers.
87  */
88  var->varnosyn = varno;
89  var->varattnosyn = varattno;
90 
91  /* Likewise, we just set location to "unknown" here */
92  var->location = -1;
93 
94  return var;
95 }
Index varlevelsup
Definition: primnodes.h:191
AttrNumber varattno
Definition: primnodes.h:186
Definition: primnodes.h:181
Oid vartype
Definition: primnodes.h:188
int location
Definition: primnodes.h:196
Index varnosyn
Definition: primnodes.h:194
Index varno
Definition: primnodes.h:184
AttrNumber varattnosyn
Definition: primnodes.h:195
#define makeNode(_type_)
Definition: nodes.h:577
Oid varcollid
Definition: primnodes.h:190
int32 vartypmod
Definition: primnodes.h:189

◆ makeVarFromTargetEntry()

Var* makeVarFromTargetEntry ( Index  varno,
TargetEntry tle 
)

Definition at line 103 of file makefuncs.c.

References TargetEntry::expr, exprCollation(), exprType(), exprTypmod(), makeVar(), and TargetEntry::resno.

Referenced by build_physical_tlist(), coerce_fn_result_column(), generate_subquery_vars(), make_setop_translation_list(), search_indexed_tlist_for_non_var(), search_indexed_tlist_for_sortgroupref(), and transformInsertStmt().

105 {
106  return makeVar(varno,
107  tle->resno,
108  exprType((Node *) tle->expr),
109  exprTypmod((Node *) tle->expr),
110  exprCollation((Node *) tle->expr),
111  0);
112 }
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
Definition: nodes.h:529
AttrNumber resno
Definition: primnodes.h:1408
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Expr * expr
Definition: primnodes.h:1407
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719

◆ makeWholeRowVar()

Var* makeWholeRowVar ( RangeTblEntry rte,
Index  varno,
Index  varlevelsup,
bool  allowScalar 
)

Definition at line 133 of file makefuncs.c.

References ereport, errcode(), errmsg(), ERROR, exprCollation(), exprType(), RangeTblEntry::funcordinality, RangeTblEntry::functions, get_rel_name(), get_rel_type_id(), InvalidAttrNumber, InvalidOid, linitial, list_length(), makeVar(), OidIsValid, RangeTblEntry::relid, RTE_FUNCTION, RTE_RELATION, RangeTblEntry::rtekind, and type_is_rowtype().

Referenced by ApplyRetrieveRule(), expand_inherited_rtentry(), preprocess_targetlist(), rewriteTargetListUD(), and transformWholeRowRef().

137 {
138  Var *result;
139  Oid toid;
140  Node *fexpr;
141 
142  switch (rte->rtekind)
143  {
144  case RTE_RELATION:
145  /* relation: the rowtype is a named composite type */
146  toid = get_rel_type_id(rte->relid);
147  if (!OidIsValid(toid))
148  ereport(ERROR,
149  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
150  errmsg("relation \"%s\" does not have a composite type",
151  get_rel_name(rte->relid))));
152  result = makeVar(varno,
154  toid,
155  -1,
156  InvalidOid,
157  varlevelsup);
158  break;
159 
160  case RTE_FUNCTION:
161 
162  /*
163  * If there's more than one function, or ordinality is requested,
164  * force a RECORD result, since there's certainly more than one
165  * column involved and it can't be a known named type.
166  */
167  if (rte->funcordinality || list_length(rte->functions) != 1)
168  {
169  /* always produces an anonymous RECORD result */
170  result = makeVar(varno,
172  RECORDOID,
173  -1,
174  InvalidOid,
175  varlevelsup);
176  break;
177  }
178 
179  fexpr = ((RangeTblFunction *) linitial(rte->functions))->funcexpr;
180  toid = exprType(fexpr);
181  if (type_is_rowtype(toid))
182  {
183  /* func returns composite; same as relation case */
184  result = makeVar(varno,
186  toid,
187  -1,
188  InvalidOid,
189  varlevelsup);
190  }
191  else if (allowScalar)
192  {
193  /* func returns scalar; just return its output as-is */
194  result = makeVar(varno,
195  1,
196  toid,
197  -1,
198  exprCollation(fexpr),
199  varlevelsup);
200  }
201  else
202  {
203  /* func returns scalar, but we want a composite result */
204  result = makeVar(varno,
206  RECORDOID,
207  -1,
208  InvalidOid,
209  varlevelsup);
210  }
211  break;
212 
213  default:
214 
215  /*
216  * RTE is a join, subselect, tablefunc, or VALUES. We represent
217  * this as a whole-row Var of RECORD type. (Note that in most
218  * cases the Var will be expanded to a RowExpr during planning,
219  * but that is not our concern here.)
220  */
221  result = makeVar(varno,
223  RECORDOID,
224  -1,
225  InvalidOid,
226  varlevelsup);
227  break;
228  }
229 
230  return result;
231 }
Definition: nodes.h:529
int errcode(int sqlerrcode)
Definition: elog.c:610
bool funcordinality
Definition: parsenodes.h:1064
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:181
#define OidIsValid(objectId)
Definition: c.h:644
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2543
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:1891
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
List * functions
Definition: parsenodes.h:1063
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:169
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719
#define InvalidAttrNumber
Definition: attnum.h:23
RTEKind rtekind
Definition: parsenodes.h:976
int errmsg(const char *fmt,...)
Definition: elog.c:824
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1840