PostgreSQL Source Code  git master
analyze.h File Reference
Include dependency graph for analyze.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* post_parse_analyze_hook_type) (ParseState *pstate, Query *query)
 

Functions

Queryparse_analyze (RawStmt *parseTree, const char *sourceText, Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
 
Queryparse_analyze_varparams (RawStmt *parseTree, const char *sourceText, Oid **paramTypes, int *numParams)
 
Queryparse_sub_analyze (Node *parseTree, ParseState *parentParseState, CommonTableExpr *parentCTE, bool locked_from_parent, bool resolve_unknowns)
 
QuerytransformTopLevelStmt (ParseState *pstate, RawStmt *parseTree)
 
QuerytransformStmt (ParseState *pstate, Node *parseTree)
 
bool analyze_requires_snapshot (RawStmt *parseTree)
 
const char * LCS_asString (LockClauseStrength strength)
 
void CheckSelectLocking (Query *qry, LockClauseStrength strength)
 
void applyLockingClause (Query *qry, Index rtindex, LockClauseStrength strength, LockWaitPolicy waitPolicy, bool pushedDown)
 
ListBuildOnConflictExcludedTargetlist (Relation targetrel, Index exclRelIndex)
 
void fill_extraUpdatedCols (RangeTblEntry *target_rte, TupleDesc tupdesc)
 

Variables

PGDLLIMPORT post_parse_analyze_hook_type post_parse_analyze_hook
 

Typedef Documentation

◆ post_parse_analyze_hook_type

typedef void(* post_parse_analyze_hook_type) (ParseState *pstate, Query *query)

Definition at line 20 of file analyze.h.

Function Documentation

◆ analyze_requires_snapshot()

bool analyze_requires_snapshot ( RawStmt parseTree)

Definition at line 357 of file analyze.c.

References nodeTag, RawStmt::stmt, T_CreateTableAsStmt, T_DeclareCursorStmt, T_DeleteStmt, T_ExplainStmt, T_InsertStmt, T_SelectStmt, and T_UpdateStmt.

Referenced by BuildCachedPlan(), exec_bind_message(), exec_parse_message(), and exec_simple_query().

358 {
359  bool result;
360 
361  switch (nodeTag(parseTree->stmt))
362  {
363  /*
364  * Optimizable statements
365  */
366  case T_InsertStmt:
367  case T_DeleteStmt:
368  case T_UpdateStmt:
369  case T_SelectStmt:
370  result = true;
371  break;
372 
373  /*
374  * Special cases
375  */
376  case T_DeclareCursorStmt:
377  case T_ExplainStmt:
378  case T_CreateTableAsStmt:
379  /* yes, because we must analyze the contained statement */
380  result = true;
381  break;
382 
383  default:
384  /* other utility statements don't have any real parse analysis */
385  result = false;
386  break;
387  }
388 
389  return result;
390 }
Node * stmt
Definition: parsenodes.h:1509
#define nodeTag(nodeptr)
Definition: nodes.h:534

◆ applyLockingClause()

void applyLockingClause ( Query qry,
Index  rtindex,
LockClauseStrength  strength,
LockWaitPolicy  waitPolicy,
bool  pushedDown 
)

Definition at line 2944 of file analyze.c.

References Assert, get_parse_rowmark(), Query::hasForUpdate, lappend(), LCS_NONE, makeNode, Max, RowMarkClause::pushedDown, raw_expression_tree_walker(), Query::rowMarks, RowMarkClause::rti, RowMarkClause::strength, and RowMarkClause::waitPolicy.

Referenced by markQueryForLocking(), and transformLockingClause().

2947 {
2948  RowMarkClause *rc;
2949 
2950  Assert(strength != LCS_NONE); /* else caller error */
2951 
2952  /* If it's an explicit clause, make sure hasForUpdate gets set */
2953  if (!pushedDown)
2954  qry->hasForUpdate = true;
2955 
2956  /* Check for pre-existing entry for same rtindex */
2957  if ((rc = get_parse_rowmark(qry, rtindex)) != NULL)
2958  {
2959  /*
2960  * If the same RTE is specified with more than one locking strength,
2961  * use the strongest. (Reasonable, since you can't take both a shared
2962  * and exclusive lock at the same time; it'll end up being exclusive
2963  * anyway.)
2964  *
2965  * Similarly, if the same RTE is specified with more than one lock
2966  * wait policy, consider that NOWAIT wins over SKIP LOCKED, which in
2967  * turn wins over waiting for the lock (the default). This is a bit
2968  * more debatable but raising an error doesn't seem helpful. (Consider
2969  * for instance SELECT FOR UPDATE NOWAIT from a view that internally
2970  * contains a plain FOR UPDATE spec.) Having NOWAIT win over SKIP
2971  * LOCKED is reasonable since the former throws an error in case of
2972  * coming across a locked tuple, which may be undesirable in some
2973  * cases but it seems better than silently returning inconsistent
2974  * results.
2975  *
2976  * And of course pushedDown becomes false if any clause is explicit.
2977  */
2978  rc->strength = Max(rc->strength, strength);
2979  rc->waitPolicy = Max(rc->waitPolicy, waitPolicy);
2980  rc->pushedDown &= pushedDown;
2981  return;
2982  }
2983 
2984  /* Make a new RowMarkClause */
2985  rc = makeNode(RowMarkClause);
2986  rc->rti = rtindex;
2987  rc->strength = strength;
2988  rc->waitPolicy = waitPolicy;
2989  rc->pushedDown = pushedDown;
2990  qry->rowMarks = lappend(qry->rowMarks, rc);
2991 }
RowMarkClause * get_parse_rowmark(Query *qry, Index rtindex)
List * rowMarks
Definition: parsenodes.h:164
LockClauseStrength strength
Definition: parsenodes.h:1384
List * lappend(List *list, void *datum)
Definition: list.c:321
#define Max(x, y)
Definition: c.h:921
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
LockWaitPolicy waitPolicy
Definition: parsenodes.h:1385
bool hasForUpdate
Definition: parsenodes.h:132

◆ BuildOnConflictExcludedTargetlist()

List* BuildOnConflictExcludedTargetlist ( Relation  targetrel,
Index  exclRelIndex 
)

Definition at line 1078 of file analyze.c.

References InvalidAttrNumber, InvalidOid, lappend(), makeNullConst(), makeTargetEntry(), makeVar(), name, NameStr, NIL, pstrdup(), RelationData::rd_att, RelationData::rd_rel, RelationGetNumberOfAttributes, and TupleDescAttr.

Referenced by rewriteTargetView(), and transformOnConflictClause().

1080 {
1081  List *result = NIL;
1082  int attno;
1083  Var *var;
1084  TargetEntry *te;
1085 
1086  /*
1087  * Note that resnos of the tlist must correspond to attnos of the
1088  * underlying relation, hence we need entries for dropped columns too.
1089  */
1090  for (attno = 0; attno < RelationGetNumberOfAttributes(targetrel); attno++)
1091  {
1092  Form_pg_attribute attr = TupleDescAttr(targetrel->rd_att, attno);
1093  char *name;
1094 
1095  if (attr->attisdropped)
1096  {
1097  /*
1098  * can't use atttypid here, but it doesn't really matter what type
1099  * the Const claims to be.
1100  */
1101  var = (Var *) makeNullConst(INT4OID, -1, InvalidOid);
1102  name = NULL;
1103  }
1104  else
1105  {
1106  var = makeVar(exclRelIndex, attno + 1,
1107  attr->atttypid, attr->atttypmod,
1108  attr->attcollation,
1109  0);
1110  name = pstrdup(NameStr(attr->attname));
1111  }
1112 
1113  te = makeTargetEntry((Expr *) var,
1114  attno + 1,
1115  name,
1116  false);
1117 
1118  result = lappend(result, te);
1119  }
1120 
1121  /*
1122  * Add a whole-row-Var entry to support references to "EXCLUDED.*". Like
1123  * the other entries in the EXCLUDED tlist, its resno must match the Var's
1124  * varattno, else the wrong things happen while resolving references in
1125  * setrefs.c. This is against normal conventions for targetlists, but
1126  * it's okay since we don't use this as a real tlist.
1127  */
1128  var = makeVar(exclRelIndex, InvalidAttrNumber,
1129  targetrel->rd_rel->reltype,
1130  -1, InvalidOid, 0);
1131  te = makeTargetEntry((Expr *) var, InvalidAttrNumber, NULL, true);
1132  result = lappend(result, te);
1133 
1134  return result;
1135 }
#define NIL
Definition: pg_list.h:65
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:462
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
char * pstrdup(const char *in)
Definition: mcxt.c:1187
Form_pg_class rd_rel
Definition: rel.h:109
Definition: primnodes.h:181
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Definition: makefuncs.c:337
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:238
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
List * lappend(List *list, void *datum)
Definition: list.c:321
TupleDesc rd_att
Definition: rel.h:110
#define InvalidOid
Definition: postgres_ext.h:36
const char * name
Definition: encode.c:561
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:622
Definition: pg_list.h:50

◆ CheckSelectLocking()

void CheckSelectLocking ( Query qry,
LockClauseStrength  strength 
)

Definition at line 2706 of file analyze.c.

References Assert, Query::distinctClause, ereport, errcode(), errmsg(), ERROR, Query::groupClause, Query::hasAggs, Query::hasTargetSRFs, Query::hasWindowFuncs, Query::havingQual, LCS_asString(), LCS_NONE, NIL, and Query::setOperations.

Referenced by preprocess_rowmarks(), and transformLockingClause().

2707 {
2708  Assert(strength != LCS_NONE); /* else caller error */
2709 
2710  if (qry->setOperations)
2711  ereport(ERROR,
2712  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2713  /*------
2714  translator: %s is a SQL row locking clause such as FOR UPDATE */
2715  errmsg("%s is not allowed with UNION/INTERSECT/EXCEPT",
2716  LCS_asString(strength))));
2717  if (qry->distinctClause != NIL)
2718  ereport(ERROR,
2719  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2720  /*------
2721  translator: %s is a SQL row locking clause such as FOR UPDATE */
2722  errmsg("%s is not allowed with DISTINCT clause",
2723  LCS_asString(strength))));
2724  if (qry->groupClause != NIL)
2725  ereport(ERROR,
2726  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2727  /*------
2728  translator: %s is a SQL row locking clause such as FOR UPDATE */
2729  errmsg("%s is not allowed with GROUP BY clause",
2730  LCS_asString(strength))));
2731  if (qry->havingQual != NULL)
2732  ereport(ERROR,
2733  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2734  /*------
2735  translator: %s is a SQL row locking clause such as FOR UPDATE */
2736  errmsg("%s is not allowed with HAVING clause",
2737  LCS_asString(strength))));
2738  if (qry->hasAggs)
2739  ereport(ERROR,
2740  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2741  /*------
2742  translator: %s is a SQL row locking clause such as FOR UPDATE */
2743  errmsg("%s is not allowed with aggregate functions",
2744  LCS_asString(strength))));
2745  if (qry->hasWindowFuncs)
2746  ereport(ERROR,
2747  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2748  /*------
2749  translator: %s is a SQL row locking clause such as FOR UPDATE */
2750  errmsg("%s is not allowed with window functions",
2751  LCS_asString(strength))));
2752  if (qry->hasTargetSRFs)
2753  ereport(ERROR,
2754  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2755  /*------
2756  translator: %s is a SQL row locking clause such as FOR UPDATE */
2757  errmsg("%s is not allowed with set-returning functions in the target list",
2758  LCS_asString(strength))));
2759 }
#define NIL
Definition: pg_list.h:65
const char * LCS_asString(LockClauseStrength strength)
Definition: analyze.c:2681
bool hasAggs
Definition: parsenodes.h:125
int errcode(int sqlerrcode)
Definition: elog.c:610
List * distinctClause
Definition: parsenodes.h:156
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
bool hasTargetSRFs
Definition: parsenodes.h:127
#define Assert(condition)
Definition: c.h:745
bool hasWindowFuncs
Definition: parsenodes.h:126
Node * setOperations
Definition: parsenodes.h:166
List * groupClause
Definition: parsenodes.h:148
int errmsg(const char *fmt,...)
Definition: elog.c:824
Node * havingQual
Definition: parsenodes.h:152

◆ fill_extraUpdatedCols()

void fill_extraUpdatedCols ( RangeTblEntry target_rte,
TupleDesc  tupdesc 
)

Definition at line 2368 of file analyze.c.

References AttrDefault::adbin, AttrDefault::adnum, bms_add_member(), bms_overlap(), TupleDescData::constr, TupleConstr::defval, RangeTblEntry::extraUpdatedCols, FirstLowInvalidHeapAttributeNumber, TupleConstr::has_generated_stored, i, TupleConstr::num_defval, pull_varattnos(), stringToNode(), TupleDescAttr, and RangeTblEntry::updatedCols.

Referenced by apply_handle_update(), and transformUpdateTargetList().

2369 {
2370  if (tupdesc->constr &&
2371  tupdesc->constr->has_generated_stored)
2372  {
2373  for (int i = 0; i < tupdesc->constr->num_defval; i++)
2374  {
2375  AttrDefault defval = tupdesc->constr->defval[i];
2376  Node *expr;
2377  Bitmapset *attrs_used = NULL;
2378 
2379  /* skip if not generated column */
2380  if (!TupleDescAttr(tupdesc, defval.adnum - 1)->attgenerated)
2381  continue;
2382 
2383  expr = stringToNode(defval.adbin);
2384  pull_varattnos(expr, 1, &attrs_used);
2385 
2386  if (bms_overlap(target_rte->updatedCols, attrs_used))
2387  target_rte->extraUpdatedCols = bms_add_member(target_rte->extraUpdatedCols,
2389  }
2390  }
2391 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Definition: nodes.h:529
void * stringToNode(const char *str)
Definition: read.c:89
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:219
AttrDefault * defval
Definition: tupdesc.h:39
bool has_generated_stored
Definition: tupdesc.h:45
Bitmapset * extraUpdatedCols
Definition: parsenodes.h:1125
TupleConstr * constr
Definition: tupdesc.h:85
Bitmapset * updatedCols
Definition: parsenodes.h:1124
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
uint16 num_defval
Definition: tupdesc.h:42
int i
AttrNumber adnum
Definition: tupdesc.h:24
char * adbin
Definition: tupdesc.h:25

◆ LCS_asString()

const char* LCS_asString ( LockClauseStrength  strength)

Definition at line 2681 of file analyze.c.

References Assert, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, and LCS_NONE.

Referenced by CheckSelectLocking(), grouping_planner(), make_outerjoininfo(), transformDeclareCursorStmt(), transformLockingClause(), transformSetOperationStmt(), transformSetOperationTree(), and transformValuesClause().

2682 {
2683  switch (strength)
2684  {
2685  case LCS_NONE:
2686  Assert(false);
2687  break;
2688  case LCS_FORKEYSHARE:
2689  return "FOR KEY SHARE";
2690  case LCS_FORSHARE:
2691  return "FOR SHARE";
2692  case LCS_FORNOKEYUPDATE:
2693  return "FOR NO KEY UPDATE";
2694  case LCS_FORUPDATE:
2695  return "FOR UPDATE";
2696  }
2697  return "FOR some"; /* shouldn't happen */
2698 }
#define Assert(condition)
Definition: c.h:745

◆ parse_analyze()

Query* parse_analyze ( RawStmt parseTree,
const char *  sourceText,
Oid paramTypes,
int  numParams,
QueryEnvironment queryEnv 
)

Definition at line 100 of file analyze.c.

References Assert, free_parsestate(), make_parsestate(), ParseState::p_queryEnv, ParseState::p_sourcetext, parse_fixed_parameters(), post_parse_analyze_hook, and transformTopLevelStmt().

Referenced by DefineView(), and pg_analyze_and_rewrite().

103 {
104  ParseState *pstate = make_parsestate(NULL);
105  Query *query;
106 
107  Assert(sourceText != NULL); /* required as of 8.4 */
108 
109  pstate->p_sourcetext = sourceText;
110 
111  if (numParams > 0)
112  parse_fixed_parameters(pstate, paramTypes, numParams);
113 
114  pstate->p_queryEnv = queryEnv;
115 
116  query = transformTopLevelStmt(pstate, parseTree);
117 
119  (*post_parse_analyze_hook) (pstate, query);
120 
121  free_parsestate(pstate);
122 
123  return query;
124 }
QueryEnvironment * p_queryEnv
Definition: parse_node.h:203
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:43
const char * p_sourcetext
Definition: parse_node.h:179
#define Assert(condition)
Definition: c.h:745
void parse_fixed_parameters(ParseState *pstate, Oid *paramTypes, int numParams)
Definition: parse_param.c:67
Query * transformTopLevelStmt(ParseState *pstate, RawStmt *parseTree)
Definition: analyze.c:191
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:76
post_parse_analyze_hook_type post_parse_analyze_hook
Definition: analyze.c:51

◆ parse_analyze_varparams()

Query* parse_analyze_varparams ( RawStmt parseTree,
const char *  sourceText,
Oid **  paramTypes,
int *  numParams 
)

Definition at line 134 of file analyze.c.

References Assert, check_variable_parameters(), free_parsestate(), make_parsestate(), ParseState::p_sourcetext, parse_variable_parameters(), post_parse_analyze_hook, and transformTopLevelStmt().

Referenced by exec_parse_message(), and PrepareQuery().

136 {
137  ParseState *pstate = make_parsestate(NULL);
138  Query *query;
139 
140  Assert(sourceText != NULL); /* required as of 8.4 */
141 
142  pstate->p_sourcetext = sourceText;
143 
144  parse_variable_parameters(pstate, paramTypes, numParams);
145 
146  query = transformTopLevelStmt(pstate, parseTree);
147 
148  /* make sure all is well with parameter types */
149  check_variable_parameters(pstate, query);
150 
152  (*post_parse_analyze_hook) (pstate, query);
153 
154  free_parsestate(pstate);
155 
156  return query;
157 }
void parse_variable_parameters(ParseState *pstate, Oid **paramTypes, int *numParams)
Definition: parse_param.c:83
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:43
const char * p_sourcetext
Definition: parse_node.h:179
#define Assert(condition)
Definition: c.h:745
Query * transformTopLevelStmt(ParseState *pstate, RawStmt *parseTree)
Definition: analyze.c:191
void check_variable_parameters(ParseState *pstate, Query *query)
Definition: parse_param.c:263
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:76
post_parse_analyze_hook_type post_parse_analyze_hook
Definition: analyze.c:51

◆ parse_sub_analyze()

Query* parse_sub_analyze ( Node parseTree,
ParseState parentParseState,
CommonTableExpr parentCTE,
bool  locked_from_parent,
bool  resolve_unknowns 
)

Definition at line 164 of file analyze.c.

References free_parsestate(), make_parsestate(), ParseState::p_locked_from_parent, ParseState::p_parent_cte, ParseState::p_resolve_unknowns, and transformStmt().

Referenced by analyzeCTE(), transformRangeSubselect(), transformSetOperationTree(), and transformSubLink().

168 {
169  ParseState *pstate = make_parsestate(parentParseState);
170  Query *query;
171 
172  pstate->p_parent_cte = parentCTE;
173  pstate->p_locked_from_parent = locked_from_parent;
174  pstate->p_resolve_unknowns = resolve_unknowns;
175 
176  query = transformStmt(pstate, parseTree);
177 
178  free_parsestate(pstate);
179 
180  return query;
181 }
CommonTableExpr * p_parent_cte
Definition: parse_node.h:189
bool p_locked_from_parent
Definition: parse_node.h:198
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:43
bool p_resolve_unknowns
Definition: parse_node.h:200
Query * transformStmt(ParseState *pstate, Node *parseTree)
Definition: analyze.c:254
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:76

◆ transformStmt()

Query* transformStmt ( ParseState pstate,
Node parseTree 
)

Definition at line 254 of file analyze.c.

References Query::canSetTag, CMD_UTILITY, Query::commandType, makeNode, nodeTag, SelectStmt::op, QSRC_ORIGINAL, Query::querySource, SETOP_NONE, T_CallStmt, T_CreateTableAsStmt, T_DeclareCursorStmt, T_DeleteStmt, T_ExplainStmt, T_InsertStmt, T_SelectStmt, T_UpdateStmt, transformCallStmt(), transformCreateTableAsStmt(), transformDeclareCursorStmt(), transformDeleteStmt(), transformExplainStmt(), transformInsertStmt(), transformSelectStmt(), transformSetOperationStmt(), transformUpdateStmt(), transformValuesClause(), Query::utilityStmt, and SelectStmt::valuesLists.

Referenced by parse_sub_analyze(), transformCreateTableAsStmt(), transformDeclareCursorStmt(), transformInsertStmt(), transformOptionalSelectInto(), and transformRuleStmt().

255 {
256  Query *result;
257 
258  /*
259  * We apply RAW_EXPRESSION_COVERAGE_TEST testing to basic DML statements;
260  * we can't just run it on everything because raw_expression_tree_walker()
261  * doesn't claim to handle utility statements.
262  */
263 #ifdef RAW_EXPRESSION_COVERAGE_TEST
264  switch (nodeTag(parseTree))
265  {
266  case T_SelectStmt:
267  case T_InsertStmt:
268  case T_UpdateStmt:
269  case T_DeleteStmt:
270  (void) test_raw_expression_coverage(parseTree, NULL);
271  break;
272  default:
273  break;
274  }
275 #endif /* RAW_EXPRESSION_COVERAGE_TEST */
276 
277  switch (nodeTag(parseTree))
278  {
279  /*
280  * Optimizable statements
281  */
282  case T_InsertStmt:
283  result = transformInsertStmt(pstate, (InsertStmt *) parseTree);
284  break;
285 
286  case T_DeleteStmt:
287  result = transformDeleteStmt(pstate, (DeleteStmt *) parseTree);
288  break;
289 
290  case T_UpdateStmt:
291  result = transformUpdateStmt(pstate, (UpdateStmt *) parseTree);
292  break;
293 
294  case T_SelectStmt:
295  {
296  SelectStmt *n = (SelectStmt *) parseTree;
297 
298  if (n->valuesLists)
299  result = transformValuesClause(pstate, n);
300  else if (n->op == SETOP_NONE)
301  result = transformSelectStmt(pstate, n);
302  else
303  result = transformSetOperationStmt(pstate, n);
304  }
305  break;
306 
307  /*
308  * Special cases
309  */
310  case T_DeclareCursorStmt:
311  result = transformDeclareCursorStmt(pstate,
312  (DeclareCursorStmt *) parseTree);
313  break;
314 
315  case T_ExplainStmt:
316  result = transformExplainStmt(pstate,
317  (ExplainStmt *) parseTree);
318  break;
319 
320  case T_CreateTableAsStmt:
321  result = transformCreateTableAsStmt(pstate,
322  (CreateTableAsStmt *) parseTree);
323  break;
324 
325  case T_CallStmt:
326  result = transformCallStmt(pstate,
327  (CallStmt *) parseTree);
328  break;
329 
330  default:
331 
332  /*
333  * other statements don't require any transformation; just return
334  * the original parsetree with a Query node plastered on top.
335  */
336  result = makeNode(Query);
337  result->commandType = CMD_UTILITY;
338  result->utilityStmt = (Node *) parseTree;
339  break;
340  }
341 
342  /* Mark as original query until we learn differently */
343  result->querySource = QSRC_ORIGINAL;
344  result->canSetTag = true;
345 
346  return result;
347 }
static Query * transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
Definition: analyze.c:2565
static Query * transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
Definition: analyze.c:2455
static Query * transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
Definition: analyze.c:2229
static Query * transformValuesClause(ParseState *pstate, SelectStmt *stmt)
Definition: analyze.c:1331
Definition: nodes.h:529
Node * utilityStmt
Definition: parsenodes.h:120
static Query * transformExplainStmt(ParseState *pstate, ExplainStmt *stmt)
Definition: analyze.c:2541
static Query * transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
Definition: analyze.c:1190
List * valuesLists
Definition: parsenodes.h:1613
static Query * transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
Definition: analyze.c:467
SetOperation op
Definition: parsenodes.h:1629
CmdType commandType
Definition: parsenodes.h:112
#define makeNode(_type_)
Definition: nodes.h:577
QuerySource querySource
Definition: parsenodes.h:114
bool canSetTag
Definition: parsenodes.h:118
static Query * transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
Definition: analyze.c:397
static Query * transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
Definition: analyze.c:1567
#define nodeTag(nodeptr)
Definition: nodes.h:534
static Query * transformCallStmt(ParseState *pstate, CallStmt *stmt)
Definition: analyze.c:2642

◆ transformTopLevelStmt()

Query* transformTopLevelStmt ( ParseState pstate,
RawStmt parseTree 
)

Definition at line 191 of file analyze.c.

References RawStmt::stmt, Query::stmt_len, RawStmt::stmt_len, Query::stmt_location, RawStmt::stmt_location, and transformOptionalSelectInto().

Referenced by inline_function(), parse_analyze(), parse_analyze_varparams(), and pg_analyze_and_rewrite_params().

192 {
193  Query *result;
194 
195  /* We're at top level, so allow SELECT INTO */
196  result = transformOptionalSelectInto(pstate, parseTree->stmt);
197 
198  result->stmt_location = parseTree->stmt_location;
199  result->stmt_len = parseTree->stmt_len;
200 
201  return result;
202 }
int stmt_location
Definition: parsenodes.h:181
Node * stmt
Definition: parsenodes.h:1509
int stmt_len
Definition: parsenodes.h:1511
int stmt_location
Definition: parsenodes.h:1510
static Query * transformOptionalSelectInto(ParseState *pstate, Node *parseTree)
Definition: analyze.c:215
int stmt_len
Definition: parsenodes.h:182

Variable Documentation

◆ post_parse_analyze_hook