PostgreSQL Source Code  git master
utility.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/collationcmds.h"
#include "commands/comment.h"
#include "commands/conversioncmds.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/discard.h"
#include "commands/event_trigger.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/lockcmds.h"
#include "commands/matview.h"
#include "commands/policy.h"
#include "commands/portalcmds.h"
#include "commands/prepare.h"
#include "commands/proclang.h"
#include "commands/publicationcmds.h"
#include "commands/schemacmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/subscriptioncmds.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/view.h"
#include "miscadmin.h"
#include "parser/parse_utilcmd.h"
#include "postmaster/bgwriter.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteRemove.h"
#include "storage/fd.h"
#include "tcop/pquery.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

static int ClassifyUtilityCommandAsReadOnly (Node *parsetree)
 
static void ProcessUtilitySlow (ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
static void ExecDropStmt (DropStmt *stmt, bool isTopLevel)
 
bool CommandIsReadOnly (PlannedStmt *pstmt)
 
void PreventCommandIfReadOnly (const char *cmdname)
 
void PreventCommandIfParallelMode (const char *cmdname)
 
void PreventCommandDuringRecovery (const char *cmdname)
 
static void CheckRestrictedOperation (const char *cmdname)
 
void ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
static CommandTag AlterObjectTypeCommandTag (ObjectType objtype)
 
CommandTag CreateCommandTag (Node *parsetree)
 
LogStmtLevel GetCommandLogLevel (Node *parsetree)
 

Variables

ProcessUtility_hook_type ProcessUtility_hook = NULL
 

Function Documentation

◆ AlterObjectTypeCommandTag()

static CommandTag AlterObjectTypeCommandTag ( ObjectType  objtype)
static

Definition at line 2105 of file utility.c.

References OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, and OBJECT_VIEW.

Referenced by CreateCommandTag().

2106 {
2107  CommandTag tag;
2108 
2109  switch (objtype)
2110  {
2111  case OBJECT_AGGREGATE:
2112  tag = CMDTAG_ALTER_AGGREGATE;
2113  break;
2114  case OBJECT_ATTRIBUTE:
2115  tag = CMDTAG_ALTER_TYPE;
2116  break;
2117  case OBJECT_CAST:
2118  tag = CMDTAG_ALTER_CAST;
2119  break;
2120  case OBJECT_COLLATION:
2121  tag = CMDTAG_ALTER_COLLATION;
2122  break;
2123  case OBJECT_COLUMN:
2124  tag = CMDTAG_ALTER_TABLE;
2125  break;
2126  case OBJECT_CONVERSION:
2127  tag = CMDTAG_ALTER_CONVERSION;
2128  break;
2129  case OBJECT_DATABASE:
2130  tag = CMDTAG_ALTER_DATABASE;
2131  break;
2132  case OBJECT_DOMAIN:
2133  case OBJECT_DOMCONSTRAINT:
2134  tag = CMDTAG_ALTER_DOMAIN;
2135  break;
2136  case OBJECT_EXTENSION:
2137  tag = CMDTAG_ALTER_EXTENSION;
2138  break;
2139  case OBJECT_FDW:
2140  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2141  break;
2142  case OBJECT_FOREIGN_SERVER:
2143  tag = CMDTAG_ALTER_SERVER;
2144  break;
2145  case OBJECT_FOREIGN_TABLE:
2146  tag = CMDTAG_ALTER_FOREIGN_TABLE;
2147  break;
2148  case OBJECT_FUNCTION:
2149  tag = CMDTAG_ALTER_FUNCTION;
2150  break;
2151  case OBJECT_INDEX:
2152  tag = CMDTAG_ALTER_INDEX;
2153  break;
2154  case OBJECT_LANGUAGE:
2155  tag = CMDTAG_ALTER_LANGUAGE;
2156  break;
2157  case OBJECT_LARGEOBJECT:
2158  tag = CMDTAG_ALTER_LARGE_OBJECT;
2159  break;
2160  case OBJECT_OPCLASS:
2161  tag = CMDTAG_ALTER_OPERATOR_CLASS;
2162  break;
2163  case OBJECT_OPERATOR:
2164  tag = CMDTAG_ALTER_OPERATOR;
2165  break;
2166  case OBJECT_OPFAMILY:
2167  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2168  break;
2169  case OBJECT_POLICY:
2170  tag = CMDTAG_ALTER_POLICY;
2171  break;
2172  case OBJECT_PROCEDURE:
2173  tag = CMDTAG_ALTER_PROCEDURE;
2174  break;
2175  case OBJECT_ROLE:
2176  tag = CMDTAG_ALTER_ROLE;
2177  break;
2178  case OBJECT_ROUTINE:
2179  tag = CMDTAG_ALTER_ROUTINE;
2180  break;
2181  case OBJECT_RULE:
2182  tag = CMDTAG_ALTER_RULE;
2183  break;
2184  case OBJECT_SCHEMA:
2185  tag = CMDTAG_ALTER_SCHEMA;
2186  break;
2187  case OBJECT_SEQUENCE:
2188  tag = CMDTAG_ALTER_SEQUENCE;
2189  break;
2190  case OBJECT_TABLE:
2191  case OBJECT_TABCONSTRAINT:
2192  tag = CMDTAG_ALTER_TABLE;
2193  break;
2194  case OBJECT_TABLESPACE:
2195  tag = CMDTAG_ALTER_TABLESPACE;
2196  break;
2197  case OBJECT_TRIGGER:
2198  tag = CMDTAG_ALTER_TRIGGER;
2199  break;
2200  case OBJECT_EVENT_TRIGGER:
2201  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2202  break;
2204  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2205  break;
2206  case OBJECT_TSDICTIONARY:
2207  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2208  break;
2209  case OBJECT_TSPARSER:
2210  tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2211  break;
2212  case OBJECT_TSTEMPLATE:
2213  tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2214  break;
2215  case OBJECT_TYPE:
2216  tag = CMDTAG_ALTER_TYPE;
2217  break;
2218  case OBJECT_VIEW:
2219  tag = CMDTAG_ALTER_VIEW;
2220  break;
2221  case OBJECT_MATVIEW:
2222  tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2223  break;
2224  case OBJECT_PUBLICATION:
2225  tag = CMDTAG_ALTER_PUBLICATION;
2226  break;
2227  case OBJECT_SUBSCRIPTION:
2228  tag = CMDTAG_ALTER_SUBSCRIPTION;
2229  break;
2230  case OBJECT_STATISTIC_EXT:
2231  tag = CMDTAG_ALTER_STATISTICS;
2232  break;
2233  default:
2234  tag = CMDTAG_UNKNOWN;
2235  break;
2236  }
2237 
2238  return tag;
2239 }
CommandTag
Definition: cmdtag.h:20

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 463 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and InSecurityRestrictedOperation().

Referenced by standard_ProcessUtility().

464 {
466  ereport(ERROR,
467  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
468  /* translator: %s is name of a SQL command, eg PREPARE */
469  errmsg("cannot execute %s within security-restricted operation",
470  cmdname)));
471 }
int errcode(int sqlerrcode)
Definition: elog.c:704
#define ERROR
Definition: elog.h:45
#define ereport(elevel,...)
Definition: elog.h:155
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:608
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ ClassifyUtilityCommandAsReadOnly()

static int ClassifyUtilityCommandAsReadOnly ( Node parsetree)
static

Definition at line 133 of file utility.c.

References COMMAND_IS_NOT_READ_ONLY, COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, elog, ERROR, CopyStmt::is_from, TransactionStmt::kind, LockStmt::mode, nodeTag, RowExclusiveLock, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, and TRANS_STMT_START.

Referenced by standard_ProcessUtility().

134 {
135  switch (nodeTag(parsetree))
136  {
139  case T_AlterDatabaseStmt:
141  case T_AlterDomainStmt:
142  case T_AlterEnumStmt:
146  case T_AlterFdwStmt:
148  case T_AlterFunctionStmt:
151  case T_AlterOpFamilyStmt:
152  case T_AlterOperatorStmt:
153  case T_AlterOwnerStmt:
154  case T_AlterPolicyStmt:
156  case T_AlterRoleSetStmt:
157  case T_AlterRoleStmt:
158  case T_AlterSeqStmt:
159  case T_AlterStatsStmt:
165  case T_AlterTableStmt:
166  case T_AlterTypeStmt:
168  case T_CommentStmt:
169  case T_CompositeTypeStmt:
170  case T_CreateAmStmt:
171  case T_CreateCastStmt:
173  case T_CreateDomainStmt:
174  case T_CreateEnumStmt:
177  case T_CreateFdwStmt:
181  case T_CreateOpClassStmt:
183  case T_CreatePLangStmt:
184  case T_CreatePolicyStmt:
186  case T_CreateRangeStmt:
187  case T_CreateRoleStmt:
188  case T_CreateSchemaStmt:
189  case T_CreateSeqStmt:
190  case T_CreateStatsStmt:
191  case T_CreateStmt:
193  case T_CreateTableAsStmt:
196  case T_CreateTrigStmt:
198  case T_CreatedbStmt:
199  case T_DefineStmt:
200  case T_DropOwnedStmt:
201  case T_DropRoleStmt:
202  case T_DropStmt:
206  case T_DropdbStmt:
207  case T_GrantRoleStmt:
208  case T_GrantStmt:
210  case T_IndexStmt:
211  case T_ReassignOwnedStmt:
213  case T_RenameStmt:
214  case T_RuleStmt:
215  case T_SecLabelStmt:
216  case T_TruncateStmt:
217  case T_ViewStmt:
218  {
219  /* DDL is not read-only, and neither is TRUNCATE. */
221  }
222 
223  case T_AlterSystemStmt:
224  {
225  /*
226  * Surprisingly, ALTER SYSTEM meets all our definitions of
227  * read-only: it changes nothing that affects the output of
228  * pg_dump, it doesn't write WAL or imperil the application of
229  * future WAL, and it doesn't depend on any state that needs
230  * to be synchronized with parallel workers.
231  *
232  * So, despite the fact that it writes to a file, it's read
233  * only!
234  */
236  }
237 
238  case T_CallStmt:
239  case T_DoStmt:
240  {
241  /*
242  * Commands inside the DO block or the called procedure might
243  * not be read only, but they'll be checked separately when we
244  * try to execute them. Here we only need to worry about the
245  * DO or CALL command itself.
246  */
248  }
249 
250  case T_CheckPointStmt:
251  {
252  /*
253  * You might think that this should not be permitted in
254  * recovery, but we interpret a CHECKPOINT command during
255  * recovery as a request for a restartpoint instead. We allow
256  * this since it can be a useful way of reducing switchover
257  * time when using various forms of replication.
258  */
260  }
261 
262  case T_ClosePortalStmt:
264  case T_DeallocateStmt:
265  case T_DeclareCursorStmt:
266  case T_DiscardStmt:
267  case T_ExecuteStmt:
268  case T_FetchStmt:
269  case T_LoadStmt:
270  case T_PrepareStmt:
271  case T_UnlistenStmt:
272  case T_VariableSetStmt:
273  {
274  /*
275  * These modify only backend-local state, so they're OK to run
276  * in a read-only transaction or on a standby. However, they
277  * are disallowed in parallel mode, because they either rely
278  * upon or modify backend-local state that might not be
279  * synchronized among cooperating backends.
280  */
282  }
283 
284  case T_ClusterStmt:
285  case T_ReindexStmt:
286  case T_VacuumStmt:
287  {
288  /*
289  * These commands write WAL, so they're not strictly
290  * read-only, and running them in parallel workers isn't
291  * supported.
292  *
293  * However, they don't change the database state in a way that
294  * would affect pg_dump output, so it's fine to run them in a
295  * read-only transaction. (CLUSTER might change the order of
296  * rows on disk, which could affect the ordering of pg_dump
297  * output, but that's not semantically significant.)
298  */
300  }
301 
302  case T_CopyStmt:
303  {
304  CopyStmt *stmt = (CopyStmt *) parsetree;
305 
306  /*
307  * You might think that COPY FROM is not at all read only, but
308  * it's OK to copy into a temporary table, because that
309  * wouldn't change the output of pg_dump. If the target table
310  * turns out to be non-temporary, DoCopy itself will call
311  * PreventCommandIfReadOnly.
312  */
313  if (stmt->is_from)
315  else
317  }
318 
319  case T_ExplainStmt:
320  case T_VariableShowStmt:
321  {
322  /*
323  * These commands don't modify any data and are safe to run in
324  * a parallel worker.
325  */
327  }
328 
329  case T_ListenStmt:
330  case T_NotifyStmt:
331  {
332  /*
333  * NOTIFY requires an XID assignment, so it can't be permitted
334  * on a standby. Perhaps LISTEN could, since without NOTIFY it
335  * would be OK to just do nothing, at least until promotion,
336  * but we currently prohibit it lest the user get the wrong
337  * idea.
338  *
339  * (We do allow T_UnlistenStmt on a standby, though, because
340  * it's a no-op.)
341  */
343  }
344 
345  case T_LockStmt:
346  {
347  LockStmt *stmt = (LockStmt *) parsetree;
348 
349  /*
350  * Only weaker locker modes are allowed during recovery. The
351  * restrictions here must match those in
352  * LockAcquireExtended().
353  */
354  if (stmt->mode > RowExclusiveLock)
356  else
358  }
359 
360  case T_TransactionStmt:
361  {
362  TransactionStmt *stmt = (TransactionStmt *) parsetree;
363 
364  /*
365  * PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all write
366  * WAL, so they're not read-only in the strict sense; but the
367  * first and third do not change pg_dump output, so they're OK
368  * in a read-only transactions.
369  *
370  * We also consider COMMIT PREPARED to be OK in a read-only
371  * transaction environment, by way of exception.
372  */
373  switch (stmt->kind)
374  {
375  case TRANS_STMT_BEGIN:
376  case TRANS_STMT_START:
377  case TRANS_STMT_COMMIT:
378  case TRANS_STMT_ROLLBACK:
380  case TRANS_STMT_RELEASE:
383 
384  case TRANS_STMT_PREPARE:
388  }
389  elog(ERROR, "unrecognized TransactionStmtKind: %d",
390  (int) stmt->kind);
391  return 0; /* silence stupider compilers */
392  }
393 
394  default:
395  elog(ERROR, "unrecognized node type: %d",
396  (int) nodeTag(parsetree));
397  return 0; /* silence stupider compilers */
398  }
399 }
#define COMMAND_OK_IN_RECOVERY
Definition: utility.h:58
#define ERROR
Definition: elog.h:45
#define RowExclusiveLock
Definition: lockdefs.h:38
#define nodeTag(nodeptr)
Definition: nodes.h:535
#define COMMAND_IS_NOT_READ_ONLY
Definition: utility.h:68
bool is_from
Definition: parsenodes.h:2058
#define elog(elevel,...)
Definition: elog.h:228
#define COMMAND_IS_STRICTLY_READ_ONLY
Definition: utility.h:65
#define COMMAND_OK_IN_READ_ONLY_TXN
Definition: utility.h:56
TransactionStmtKind kind
Definition: parsenodes.h:3103

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 100 of file utility.c.

References Assert, CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, elog, PlannedStmt::hasModifyingCTE, IsA, NIL, PlannedStmt::rowMarks, and WARNING.

Referenced by _SPI_execute_plan(), CreateCommandName(), init_execution_state(), and SPI_cursor_open_internal().

101 {
102  Assert(IsA(pstmt, PlannedStmt));
103  switch (pstmt->commandType)
104  {
105  case CMD_SELECT:
106  if (pstmt->rowMarks != NIL)
107  return false; /* SELECT FOR [KEY] UPDATE/SHARE */
108  else if (pstmt->hasModifyingCTE)
109  return false; /* data-modifying CTE */
110  else
111  return true;
112  case CMD_UPDATE:
113  case CMD_INSERT:
114  case CMD_DELETE:
115  return false;
116  case CMD_UTILITY:
117  /* For now, treat all utility commands as read/write */
118  return false;
119  default:
120  elog(WARNING, "unrecognized commandType: %d",
121  (int) pstmt->commandType);
122  break;
123  }
124  return false;
125 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:581
#define WARNING
Definition: elog.h:40
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:78
#define Assert(condition)
Definition: c.h:804
bool hasModifyingCTE
Definition: plannodes.h:52
#define elog(elevel,...)
Definition: elog.h:228

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2251 of file utility.c.

References AlterObjectTypeCommandTag(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, Query::commandType, CreateCommandTag(), DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, DISCARD_TEMP, elog, GrantStmt::is_grant, GrantRoleStmt::is_grant, FetchStmt::ismove, TransactionStmt::kind, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, linitial, DeallocateStmt::name, NIL, nodeTag, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, PlannedStmt::rowMarks, Query::rowMarks, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PLAssignStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, PlannedStmt::utilityStmt, Query::utilityStmt, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WARNING.

Referenced by _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), CreateCommandName(), CreateCommandTag(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), PrepareQuery(), and standard_ProcessUtility().

2252 {
2253  CommandTag tag;
2254 
2255  switch (nodeTag(parsetree))
2256  {
2257  /* recurse if we're given a RawStmt */
2258  case T_RawStmt:
2259  tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2260  break;
2261 
2262  /* raw plannable queries */
2263  case T_InsertStmt:
2264  tag = CMDTAG_INSERT;
2265  break;
2266 
2267  case T_DeleteStmt:
2268  tag = CMDTAG_DELETE;
2269  break;
2270 
2271  case T_UpdateStmt:
2272  tag = CMDTAG_UPDATE;
2273  break;
2274 
2275  case T_SelectStmt:
2276  tag = CMDTAG_SELECT;
2277  break;
2278 
2279  case T_PLAssignStmt:
2280  tag = CMDTAG_SELECT;
2281  break;
2282 
2283  /* utility statements --- same whether raw or cooked */
2284  case T_TransactionStmt:
2285  {
2286  TransactionStmt *stmt = (TransactionStmt *) parsetree;
2287 
2288  switch (stmt->kind)
2289  {
2290  case TRANS_STMT_BEGIN:
2291  tag = CMDTAG_BEGIN;
2292  break;
2293 
2294  case TRANS_STMT_START:
2295  tag = CMDTAG_START_TRANSACTION;
2296  break;
2297 
2298  case TRANS_STMT_COMMIT:
2299  tag = CMDTAG_COMMIT;
2300  break;
2301 
2302  case TRANS_STMT_ROLLBACK:
2304  tag = CMDTAG_ROLLBACK;
2305  break;
2306 
2307  case TRANS_STMT_SAVEPOINT:
2308  tag = CMDTAG_SAVEPOINT;
2309  break;
2310 
2311  case TRANS_STMT_RELEASE:
2312  tag = CMDTAG_RELEASE;
2313  break;
2314 
2315  case TRANS_STMT_PREPARE:
2316  tag = CMDTAG_PREPARE_TRANSACTION;
2317  break;
2318 
2320  tag = CMDTAG_COMMIT_PREPARED;
2321  break;
2322 
2324  tag = CMDTAG_ROLLBACK_PREPARED;
2325  break;
2326 
2327  default:
2328  tag = CMDTAG_UNKNOWN;
2329  break;
2330  }
2331  }
2332  break;
2333 
2334  case T_DeclareCursorStmt:
2335  tag = CMDTAG_DECLARE_CURSOR;
2336  break;
2337 
2338  case T_ClosePortalStmt:
2339  {
2340  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2341 
2342  if (stmt->portalname == NULL)
2343  tag = CMDTAG_CLOSE_CURSOR_ALL;
2344  else
2345  tag = CMDTAG_CLOSE_CURSOR;
2346  }
2347  break;
2348 
2349  case T_FetchStmt:
2350  {
2351  FetchStmt *stmt = (FetchStmt *) parsetree;
2352 
2353  tag = (stmt->ismove) ? CMDTAG_MOVE : CMDTAG_FETCH;
2354  }
2355  break;
2356 
2357  case T_CreateDomainStmt:
2358  tag = CMDTAG_CREATE_DOMAIN;
2359  break;
2360 
2361  case T_CreateSchemaStmt:
2362  tag = CMDTAG_CREATE_SCHEMA;
2363  break;
2364 
2365  case T_CreateStmt:
2366  tag = CMDTAG_CREATE_TABLE;
2367  break;
2368 
2370  tag = CMDTAG_CREATE_TABLESPACE;
2371  break;
2372 
2373  case T_DropTableSpaceStmt:
2374  tag = CMDTAG_DROP_TABLESPACE;
2375  break;
2376 
2378  tag = CMDTAG_ALTER_TABLESPACE;
2379  break;
2380 
2381  case T_CreateExtensionStmt:
2382  tag = CMDTAG_CREATE_EXTENSION;
2383  break;
2384 
2385  case T_AlterExtensionStmt:
2386  tag = CMDTAG_ALTER_EXTENSION;
2387  break;
2388 
2390  tag = CMDTAG_ALTER_EXTENSION;
2391  break;
2392 
2393  case T_CreateFdwStmt:
2394  tag = CMDTAG_CREATE_FOREIGN_DATA_WRAPPER;
2395  break;
2396 
2397  case T_AlterFdwStmt:
2398  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2399  break;
2400 
2402  tag = CMDTAG_CREATE_SERVER;
2403  break;
2404 
2406  tag = CMDTAG_ALTER_SERVER;
2407  break;
2408 
2410  tag = CMDTAG_CREATE_USER_MAPPING;
2411  break;
2412 
2414  tag = CMDTAG_ALTER_USER_MAPPING;
2415  break;
2416 
2417  case T_DropUserMappingStmt:
2418  tag = CMDTAG_DROP_USER_MAPPING;
2419  break;
2420 
2422  tag = CMDTAG_CREATE_FOREIGN_TABLE;
2423  break;
2424 
2426  tag = CMDTAG_IMPORT_FOREIGN_SCHEMA;
2427  break;
2428 
2429  case T_DropStmt:
2430  switch (((DropStmt *) parsetree)->removeType)
2431  {
2432  case OBJECT_TABLE:
2433  tag = CMDTAG_DROP_TABLE;
2434  break;
2435  case OBJECT_SEQUENCE:
2436  tag = CMDTAG_DROP_SEQUENCE;
2437  break;
2438  case OBJECT_VIEW:
2439  tag = CMDTAG_DROP_VIEW;
2440  break;
2441  case OBJECT_MATVIEW:
2442  tag = CMDTAG_DROP_MATERIALIZED_VIEW;
2443  break;
2444  case OBJECT_INDEX:
2445  tag = CMDTAG_DROP_INDEX;
2446  break;
2447  case OBJECT_TYPE:
2448  tag = CMDTAG_DROP_TYPE;
2449  break;
2450  case OBJECT_DOMAIN:
2451  tag = CMDTAG_DROP_DOMAIN;
2452  break;
2453  case OBJECT_COLLATION:
2454  tag = CMDTAG_DROP_COLLATION;
2455  break;
2456  case OBJECT_CONVERSION:
2457  tag = CMDTAG_DROP_CONVERSION;
2458  break;
2459  case OBJECT_SCHEMA:
2460  tag = CMDTAG_DROP_SCHEMA;
2461  break;
2462  case OBJECT_TSPARSER:
2463  tag = CMDTAG_DROP_TEXT_SEARCH_PARSER;
2464  break;
2465  case OBJECT_TSDICTIONARY:
2466  tag = CMDTAG_DROP_TEXT_SEARCH_DICTIONARY;
2467  break;
2468  case OBJECT_TSTEMPLATE:
2469  tag = CMDTAG_DROP_TEXT_SEARCH_TEMPLATE;
2470  break;
2472  tag = CMDTAG_DROP_TEXT_SEARCH_CONFIGURATION;
2473  break;
2474  case OBJECT_FOREIGN_TABLE:
2475  tag = CMDTAG_DROP_FOREIGN_TABLE;
2476  break;
2477  case OBJECT_EXTENSION:
2478  tag = CMDTAG_DROP_EXTENSION;
2479  break;
2480  case OBJECT_FUNCTION:
2481  tag = CMDTAG_DROP_FUNCTION;
2482  break;
2483  case OBJECT_PROCEDURE:
2484  tag = CMDTAG_DROP_PROCEDURE;
2485  break;
2486  case OBJECT_ROUTINE:
2487  tag = CMDTAG_DROP_ROUTINE;
2488  break;
2489  case OBJECT_AGGREGATE:
2490  tag = CMDTAG_DROP_AGGREGATE;
2491  break;
2492  case OBJECT_OPERATOR:
2493  tag = CMDTAG_DROP_OPERATOR;
2494  break;
2495  case OBJECT_LANGUAGE:
2496  tag = CMDTAG_DROP_LANGUAGE;
2497  break;
2498  case OBJECT_CAST:
2499  tag = CMDTAG_DROP_CAST;
2500  break;
2501  case OBJECT_TRIGGER:
2502  tag = CMDTAG_DROP_TRIGGER;
2503  break;
2504  case OBJECT_EVENT_TRIGGER:
2505  tag = CMDTAG_DROP_EVENT_TRIGGER;
2506  break;
2507  case OBJECT_RULE:
2508  tag = CMDTAG_DROP_RULE;
2509  break;
2510  case OBJECT_FDW:
2511  tag = CMDTAG_DROP_FOREIGN_DATA_WRAPPER;
2512  break;
2513  case OBJECT_FOREIGN_SERVER:
2514  tag = CMDTAG_DROP_SERVER;
2515  break;
2516  case OBJECT_OPCLASS:
2517  tag = CMDTAG_DROP_OPERATOR_CLASS;
2518  break;
2519  case OBJECT_OPFAMILY:
2520  tag = CMDTAG_DROP_OPERATOR_FAMILY;
2521  break;
2522  case OBJECT_POLICY:
2523  tag = CMDTAG_DROP_POLICY;
2524  break;
2525  case OBJECT_TRANSFORM:
2526  tag = CMDTAG_DROP_TRANSFORM;
2527  break;
2528  case OBJECT_ACCESS_METHOD:
2529  tag = CMDTAG_DROP_ACCESS_METHOD;
2530  break;
2531  case OBJECT_PUBLICATION:
2532  tag = CMDTAG_DROP_PUBLICATION;
2533  break;
2534  case OBJECT_STATISTIC_EXT:
2535  tag = CMDTAG_DROP_STATISTICS;
2536  break;
2537  default:
2538  tag = CMDTAG_UNKNOWN;
2539  }
2540  break;
2541 
2542  case T_TruncateStmt:
2543  tag = CMDTAG_TRUNCATE_TABLE;
2544  break;
2545 
2546  case T_CommentStmt:
2547  tag = CMDTAG_COMMENT;
2548  break;
2549 
2550  case T_SecLabelStmt:
2551  tag = CMDTAG_SECURITY_LABEL;
2552  break;
2553 
2554  case T_CopyStmt:
2555  tag = CMDTAG_COPY;
2556  break;
2557 
2558  case T_RenameStmt:
2559 
2560  /*
2561  * When the column is renamed, the command tag is created from its
2562  * relation type
2563  */
2564  tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
2565  ((RenameStmt *) parsetree)->relationType :
2566  ((RenameStmt *) parsetree)->renameType);
2567  break;
2568 
2570  tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2571  break;
2572 
2574  tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2575  break;
2576 
2577  case T_AlterOwnerStmt:
2578  tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2579  break;
2580 
2582  tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2583  break;
2584 
2585  case T_AlterTableStmt:
2586  tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->objtype);
2587  break;
2588 
2589  case T_AlterDomainStmt:
2590  tag = CMDTAG_ALTER_DOMAIN;
2591  break;
2592 
2593  case T_AlterFunctionStmt:
2594  switch (((AlterFunctionStmt *) parsetree)->objtype)
2595  {
2596  case OBJECT_FUNCTION:
2597  tag = CMDTAG_ALTER_FUNCTION;
2598  break;
2599  case OBJECT_PROCEDURE:
2600  tag = CMDTAG_ALTER_PROCEDURE;
2601  break;
2602  case OBJECT_ROUTINE:
2603  tag = CMDTAG_ALTER_ROUTINE;
2604  break;
2605  default:
2606  tag = CMDTAG_UNKNOWN;
2607  }
2608  break;
2609 
2610  case T_GrantStmt:
2611  {
2612  GrantStmt *stmt = (GrantStmt *) parsetree;
2613 
2614  tag = (stmt->is_grant) ? CMDTAG_GRANT : CMDTAG_REVOKE;
2615  }
2616  break;
2617 
2618  case T_GrantRoleStmt:
2619  {
2620  GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2621 
2622  tag = (stmt->is_grant) ? CMDTAG_GRANT_ROLE : CMDTAG_REVOKE_ROLE;
2623  }
2624  break;
2625 
2627  tag = CMDTAG_ALTER_DEFAULT_PRIVILEGES;
2628  break;
2629 
2630  case T_DefineStmt:
2631  switch (((DefineStmt *) parsetree)->kind)
2632  {
2633  case OBJECT_AGGREGATE:
2634  tag = CMDTAG_CREATE_AGGREGATE;
2635  break;
2636  case OBJECT_OPERATOR:
2637  tag = CMDTAG_CREATE_OPERATOR;
2638  break;
2639  case OBJECT_TYPE:
2640  tag = CMDTAG_CREATE_TYPE;
2641  break;
2642  case OBJECT_TSPARSER:
2643  tag = CMDTAG_CREATE_TEXT_SEARCH_PARSER;
2644  break;
2645  case OBJECT_TSDICTIONARY:
2646  tag = CMDTAG_CREATE_TEXT_SEARCH_DICTIONARY;
2647  break;
2648  case OBJECT_TSTEMPLATE:
2649  tag = CMDTAG_CREATE_TEXT_SEARCH_TEMPLATE;
2650  break;
2652  tag = CMDTAG_CREATE_TEXT_SEARCH_CONFIGURATION;
2653  break;
2654  case OBJECT_COLLATION:
2655  tag = CMDTAG_CREATE_COLLATION;
2656  break;
2657  case OBJECT_ACCESS_METHOD:
2658  tag = CMDTAG_CREATE_ACCESS_METHOD;
2659  break;
2660  default:
2661  tag = CMDTAG_UNKNOWN;
2662  }
2663  break;
2664 
2665  case T_CompositeTypeStmt:
2666  tag = CMDTAG_CREATE_TYPE;
2667  break;
2668 
2669  case T_CreateEnumStmt:
2670  tag = CMDTAG_CREATE_TYPE;
2671  break;
2672 
2673  case T_CreateRangeStmt:
2674  tag = CMDTAG_CREATE_TYPE;
2675  break;
2676 
2677  case T_AlterEnumStmt:
2678  tag = CMDTAG_ALTER_TYPE;
2679  break;
2680 
2681  case T_ViewStmt:
2682  tag = CMDTAG_CREATE_VIEW;
2683  break;
2684 
2685  case T_CreateFunctionStmt:
2686  if (((CreateFunctionStmt *) parsetree)->is_procedure)
2687  tag = CMDTAG_CREATE_PROCEDURE;
2688  else
2689  tag = CMDTAG_CREATE_FUNCTION;
2690  break;
2691 
2692  case T_IndexStmt:
2693  tag = CMDTAG_CREATE_INDEX;
2694  break;
2695 
2696  case T_RuleStmt:
2697  tag = CMDTAG_CREATE_RULE;
2698  break;
2699 
2700  case T_CreateSeqStmt:
2701  tag = CMDTAG_CREATE_SEQUENCE;
2702  break;
2703 
2704  case T_AlterSeqStmt:
2705  tag = CMDTAG_ALTER_SEQUENCE;
2706  break;
2707 
2708  case T_DoStmt:
2709  tag = CMDTAG_DO;
2710  break;
2711 
2712  case T_CreatedbStmt:
2713  tag = CMDTAG_CREATE_DATABASE;
2714  break;
2715 
2716  case T_AlterDatabaseStmt:
2717  tag = CMDTAG_ALTER_DATABASE;
2718  break;
2719 
2721  tag = CMDTAG_ALTER_DATABASE;
2722  break;
2723 
2724  case T_DropdbStmt:
2725  tag = CMDTAG_DROP_DATABASE;
2726  break;
2727 
2728  case T_NotifyStmt:
2729  tag = CMDTAG_NOTIFY;
2730  break;
2731 
2732  case T_ListenStmt:
2733  tag = CMDTAG_LISTEN;
2734  break;
2735 
2736  case T_UnlistenStmt:
2737  tag = CMDTAG_UNLISTEN;
2738  break;
2739 
2740  case T_LoadStmt:
2741  tag = CMDTAG_LOAD;
2742  break;
2743 
2744  case T_CallStmt:
2745  tag = CMDTAG_CALL;
2746  break;
2747 
2748  case T_ClusterStmt:
2749  tag = CMDTAG_CLUSTER;
2750  break;
2751 
2752  case T_VacuumStmt:
2753  if (((VacuumStmt *) parsetree)->is_vacuumcmd)
2754  tag = CMDTAG_VACUUM;
2755  else
2756  tag = CMDTAG_ANALYZE;
2757  break;
2758 
2759  case T_ExplainStmt:
2760  tag = CMDTAG_EXPLAIN;
2761  break;
2762 
2763  case T_CreateTableAsStmt:
2764  switch (((CreateTableAsStmt *) parsetree)->objtype)
2765  {
2766  case OBJECT_TABLE:
2767  if (((CreateTableAsStmt *) parsetree)->is_select_into)
2768  tag = CMDTAG_SELECT_INTO;
2769  else
2770  tag = CMDTAG_CREATE_TABLE_AS;
2771  break;
2772  case OBJECT_MATVIEW:
2773  tag = CMDTAG_CREATE_MATERIALIZED_VIEW;
2774  break;
2775  default:
2776  tag = CMDTAG_UNKNOWN;
2777  }
2778  break;
2779 
2780  case T_RefreshMatViewStmt:
2781  tag = CMDTAG_REFRESH_MATERIALIZED_VIEW;
2782  break;
2783 
2784  case T_AlterSystemStmt:
2785  tag = CMDTAG_ALTER_SYSTEM;
2786  break;
2787 
2788  case T_VariableSetStmt:
2789  switch (((VariableSetStmt *) parsetree)->kind)
2790  {
2791  case VAR_SET_VALUE:
2792  case VAR_SET_CURRENT:
2793  case VAR_SET_DEFAULT:
2794  case VAR_SET_MULTI:
2795  tag = CMDTAG_SET;
2796  break;
2797  case VAR_RESET:
2798  case VAR_RESET_ALL:
2799  tag = CMDTAG_RESET;
2800  break;
2801  default:
2802  tag = CMDTAG_UNKNOWN;
2803  }
2804  break;
2805 
2806  case T_VariableShowStmt:
2807  tag = CMDTAG_SHOW;
2808  break;
2809 
2810  case T_DiscardStmt:
2811  switch (((DiscardStmt *) parsetree)->target)
2812  {
2813  case DISCARD_ALL:
2814  tag = CMDTAG_DISCARD_ALL;
2815  break;
2816  case DISCARD_PLANS:
2817  tag = CMDTAG_DISCARD_PLANS;
2818  break;
2819  case DISCARD_TEMP:
2820  tag = CMDTAG_DISCARD_TEMP;
2821  break;
2822  case DISCARD_SEQUENCES:
2823  tag = CMDTAG_DISCARD_SEQUENCES;
2824  break;
2825  default:
2826  tag = CMDTAG_UNKNOWN;
2827  }
2828  break;
2829 
2830  case T_CreateTransformStmt:
2831  tag = CMDTAG_CREATE_TRANSFORM;
2832  break;
2833 
2834  case T_CreateTrigStmt:
2835  tag = CMDTAG_CREATE_TRIGGER;
2836  break;
2837 
2838  case T_CreateEventTrigStmt:
2839  tag = CMDTAG_CREATE_EVENT_TRIGGER;
2840  break;
2841 
2842  case T_AlterEventTrigStmt:
2843  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2844  break;
2845 
2846  case T_CreatePLangStmt:
2847  tag = CMDTAG_CREATE_LANGUAGE;
2848  break;
2849 
2850  case T_CreateRoleStmt:
2851  tag = CMDTAG_CREATE_ROLE;
2852  break;
2853 
2854  case T_AlterRoleStmt:
2855  tag = CMDTAG_ALTER_ROLE;
2856  break;
2857 
2858  case T_AlterRoleSetStmt:
2859  tag = CMDTAG_ALTER_ROLE;
2860  break;
2861 
2862  case T_DropRoleStmt:
2863  tag = CMDTAG_DROP_ROLE;
2864  break;
2865 
2866  case T_DropOwnedStmt:
2867  tag = CMDTAG_DROP_OWNED;
2868  break;
2869 
2870  case T_ReassignOwnedStmt:
2871  tag = CMDTAG_REASSIGN_OWNED;
2872  break;
2873 
2874  case T_LockStmt:
2875  tag = CMDTAG_LOCK_TABLE;
2876  break;
2877 
2878  case T_ConstraintsSetStmt:
2879  tag = CMDTAG_SET_CONSTRAINTS;
2880  break;
2881 
2882  case T_CheckPointStmt:
2883  tag = CMDTAG_CHECKPOINT;
2884  break;
2885 
2886  case T_ReindexStmt:
2887  tag = CMDTAG_REINDEX;
2888  break;
2889 
2891  tag = CMDTAG_CREATE_CONVERSION;
2892  break;
2893 
2894  case T_CreateCastStmt:
2895  tag = CMDTAG_CREATE_CAST;
2896  break;
2897 
2898  case T_CreateOpClassStmt:
2899  tag = CMDTAG_CREATE_OPERATOR_CLASS;
2900  break;
2901 
2902  case T_CreateOpFamilyStmt:
2903  tag = CMDTAG_CREATE_OPERATOR_FAMILY;
2904  break;
2905 
2906  case T_AlterOpFamilyStmt:
2907  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2908  break;
2909 
2910  case T_AlterOperatorStmt:
2911  tag = CMDTAG_ALTER_OPERATOR;
2912  break;
2913 
2914  case T_AlterTypeStmt:
2915  tag = CMDTAG_ALTER_TYPE;
2916  break;
2917 
2919  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2920  break;
2921 
2923  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2924  break;
2925 
2926  case T_CreatePolicyStmt:
2927  tag = CMDTAG_CREATE_POLICY;
2928  break;
2929 
2930  case T_AlterPolicyStmt:
2931  tag = CMDTAG_ALTER_POLICY;
2932  break;
2933 
2934  case T_CreateAmStmt:
2935  tag = CMDTAG_CREATE_ACCESS_METHOD;
2936  break;
2937 
2939  tag = CMDTAG_CREATE_PUBLICATION;
2940  break;
2941 
2943  tag = CMDTAG_ALTER_PUBLICATION;
2944  break;
2945 
2947  tag = CMDTAG_CREATE_SUBSCRIPTION;
2948  break;
2949 
2951  tag = CMDTAG_ALTER_SUBSCRIPTION;
2952  break;
2953 
2955  tag = CMDTAG_DROP_SUBSCRIPTION;
2956  break;
2957 
2958  case T_PrepareStmt:
2959  tag = CMDTAG_PREPARE;
2960  break;
2961 
2962  case T_ExecuteStmt:
2963  tag = CMDTAG_EXECUTE;
2964  break;
2965 
2966  case T_CreateStatsStmt:
2967  tag = CMDTAG_CREATE_STATISTICS;
2968  break;
2969 
2970  case T_AlterStatsStmt:
2971  tag = CMDTAG_ALTER_STATISTICS;
2972  break;
2973 
2974  case T_DeallocateStmt:
2975  {
2976  DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2977 
2978  if (stmt->name == NULL)
2979  tag = CMDTAG_DEALLOCATE_ALL;
2980  else
2981  tag = CMDTAG_DEALLOCATE;
2982  }
2983  break;
2984 
2985  /* already-planned queries */
2986  case T_PlannedStmt:
2987  {
2988  PlannedStmt *stmt = (PlannedStmt *) parsetree;
2989 
2990  switch (stmt->commandType)
2991  {
2992  case CMD_SELECT:
2993 
2994  /*
2995  * We take a little extra care here so that the result
2996  * will be useful for complaints about read-only
2997  * statements
2998  */
2999  if (stmt->rowMarks != NIL)
3000  {
3001  /* not 100% but probably close enough */
3002  switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
3003  {
3004  case LCS_FORKEYSHARE:
3005  tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3006  break;
3007  case LCS_FORSHARE:
3008  tag = CMDTAG_SELECT_FOR_SHARE;
3009  break;
3010  case LCS_FORNOKEYUPDATE:
3011  tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3012  break;
3013  case LCS_FORUPDATE:
3014  tag = CMDTAG_SELECT_FOR_UPDATE;
3015  break;
3016  default:
3017  tag = CMDTAG_SELECT;
3018  break;
3019  }
3020  }
3021  else
3022  tag = CMDTAG_SELECT;
3023  break;
3024  case CMD_UPDATE:
3025  tag = CMDTAG_UPDATE;
3026  break;
3027  case CMD_INSERT:
3028  tag = CMDTAG_INSERT;
3029  break;
3030  case CMD_DELETE:
3031  tag = CMDTAG_DELETE;
3032  break;
3033  case CMD_UTILITY:
3034  tag = CreateCommandTag(stmt->utilityStmt);
3035  break;
3036  default:
3037  elog(WARNING, "unrecognized commandType: %d",
3038  (int) stmt->commandType);
3039  tag = CMDTAG_UNKNOWN;
3040  break;
3041  }
3042  }
3043  break;
3044 
3045  /* parsed-and-rewritten-but-not-planned queries */
3046  case T_Query:
3047  {
3048  Query *stmt = (Query *) parsetree;
3049 
3050  switch (stmt->commandType)
3051  {
3052  case CMD_SELECT:
3053 
3054  /*
3055  * We take a little extra care here so that the result
3056  * will be useful for complaints about read-only
3057  * statements
3058  */
3059  if (stmt->rowMarks != NIL)
3060  {
3061  /* not 100% but probably close enough */
3062  switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
3063  {
3064  case LCS_FORKEYSHARE:
3065  tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3066  break;
3067  case LCS_FORSHARE:
3068  tag = CMDTAG_SELECT_FOR_SHARE;
3069  break;
3070  case LCS_FORNOKEYUPDATE:
3071  tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3072  break;
3073  case LCS_FORUPDATE:
3074  tag = CMDTAG_SELECT_FOR_UPDATE;
3075  break;
3076  default:
3077  tag = CMDTAG_UNKNOWN;
3078  break;
3079  }
3080  }
3081  else
3082  tag = CMDTAG_SELECT;
3083  break;
3084  case CMD_UPDATE:
3085  tag = CMDTAG_UPDATE;
3086  break;
3087  case CMD_INSERT:
3088  tag = CMDTAG_INSERT;
3089  break;
3090  case CMD_DELETE:
3091  tag = CMDTAG_DELETE;
3092  break;
3093  case CMD_UTILITY:
3094  tag = CreateCommandTag(stmt->utilityStmt);
3095  break;
3096  default:
3097  elog(WARNING, "unrecognized commandType: %d",
3098  (int) stmt->commandType);
3099  tag = CMDTAG_UNKNOWN;
3100  break;
3101  }
3102  }
3103  break;
3104 
3105  default:
3106  elog(WARNING, "unrecognized node type: %d",
3107  (int) nodeTag(parsetree));
3108  tag = CMDTAG_UNKNOWN;
3109  break;
3110  }
3111 
3112  return tag;
3113 }
#define NIL
Definition: pg_list.h:65
CommandTag
Definition: cmdtag.h:20
static CommandTag AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:2105
List * rowMarks
Definition: parsenodes.h:164
Node * utilityStmt
Definition: parsenodes.h:120
#define linitial(l)
Definition: pg_list.h:174
Node * utilityStmt
Definition: plannodes.h:86
bool is_grant
Definition: parsenodes.h:1969
#define WARNING
Definition: elog.h:40
Definition: nodes.h:311
bool ismove
Definition: parsenodes.h:2802
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:78
CmdType commandType
Definition: parsenodes.h:112
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2251
#define nodeTag(nodeptr)
Definition: nodes.h:535
#define elog(elevel,...)
Definition: elog.h:228
TransactionStmtKind kind
Definition: parsenodes.h:3103

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1885 of file utility.c.

References DropStmt::concurrent, OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, PreventInTransactionBlock(), RemoveObjects(), RemoveRelations(), and DropStmt::removeType.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

1886 {
1887  switch (stmt->removeType)
1888  {
1889  case OBJECT_INDEX:
1890  if (stmt->concurrent)
1891  PreventInTransactionBlock(isTopLevel,
1892  "DROP INDEX CONCURRENTLY");
1893  /* fall through */
1894 
1895  case OBJECT_TABLE:
1896  case OBJECT_SEQUENCE:
1897  case OBJECT_VIEW:
1898  case OBJECT_MATVIEW:
1899  case OBJECT_FOREIGN_TABLE:
1900  RemoveRelations(stmt);
1901  break;
1902  default:
1903  RemoveObjects(stmt);
1904  break;
1905  }
1906 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:57
ObjectType removeType
Definition: parsenodes.h:2699
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1259
bool concurrent
Definition: parsenodes.h:2702
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3379

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3126 of file utility.c.

References analyze(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, Query::commandType, defGetBoolean(), DefElem::defname, elog, FetchPreparedStatement(), GetCommandLogLevel(), lfirst, LOGSTMT_ALL, LOGSTMT_DDL, LOGSTMT_MOD, ExecuteStmt::name, nodeTag, ExplainStmt::options, PreparedStatement::plansource, ExplainStmt::query, PrepareStmt::query, CachedPlanSource::raw_parse_tree, RawStmt::stmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PLAssignStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, PlannedStmt::utilityStmt, Query::utilityStmt, and WARNING.

Referenced by check_log_statement(), CreateCommandName(), and GetCommandLogLevel().

3127 {
3128  LogStmtLevel lev;
3129 
3130  switch (nodeTag(parsetree))
3131  {
3132  /* recurse if we're given a RawStmt */
3133  case T_RawStmt:
3134  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
3135  break;
3136 
3137  /* raw plannable queries */
3138  case T_InsertStmt:
3139  case T_DeleteStmt:
3140  case T_UpdateStmt:
3141  lev = LOGSTMT_MOD;
3142  break;
3143 
3144  case T_SelectStmt:
3145  if (((SelectStmt *) parsetree)->intoClause)
3146  lev = LOGSTMT_DDL; /* SELECT INTO */
3147  else
3148  lev = LOGSTMT_ALL;
3149  break;
3150 
3151  case T_PLAssignStmt:
3152  lev = LOGSTMT_ALL;
3153  break;
3154 
3155  /* utility statements --- same whether raw or cooked */
3156  case T_TransactionStmt:
3157  lev = LOGSTMT_ALL;
3158  break;
3159 
3160  case T_DeclareCursorStmt:
3161  lev = LOGSTMT_ALL;
3162  break;
3163 
3164  case T_ClosePortalStmt:
3165  lev = LOGSTMT_ALL;
3166  break;
3167 
3168  case T_FetchStmt:
3169  lev = LOGSTMT_ALL;
3170  break;
3171 
3172  case T_CreateSchemaStmt:
3173  lev = LOGSTMT_DDL;
3174  break;
3175 
3176  case T_CreateStmt:
3178  lev = LOGSTMT_DDL;
3179  break;
3180 
3182  case T_DropTableSpaceStmt:
3184  lev = LOGSTMT_DDL;
3185  break;
3186 
3187  case T_CreateExtensionStmt:
3188  case T_AlterExtensionStmt:
3190  lev = LOGSTMT_DDL;
3191  break;
3192 
3193  case T_CreateFdwStmt:
3194  case T_AlterFdwStmt:
3199  case T_DropUserMappingStmt:
3201  lev = LOGSTMT_DDL;
3202  break;
3203 
3204  case T_DropStmt:
3205  lev = LOGSTMT_DDL;
3206  break;
3207 
3208  case T_TruncateStmt:
3209  lev = LOGSTMT_MOD;
3210  break;
3211 
3212  case T_CommentStmt:
3213  lev = LOGSTMT_DDL;
3214  break;
3215 
3216  case T_SecLabelStmt:
3217  lev = LOGSTMT_DDL;
3218  break;
3219 
3220  case T_CopyStmt:
3221  if (((CopyStmt *) parsetree)->is_from)
3222  lev = LOGSTMT_MOD;
3223  else
3224  lev = LOGSTMT_ALL;
3225  break;
3226 
3227  case T_PrepareStmt:
3228  {
3229  PrepareStmt *stmt = (PrepareStmt *) parsetree;
3230 
3231  /* Look through a PREPARE to the contained stmt */
3232  lev = GetCommandLogLevel(stmt->query);
3233  }
3234  break;
3235 
3236  case T_ExecuteStmt:
3237  {
3238  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3239  PreparedStatement *ps;
3240 
3241  /* Look through an EXECUTE to the referenced stmt */
3242  ps = FetchPreparedStatement(stmt->name, false);
3243  if (ps && ps->plansource->raw_parse_tree)
3245  else
3246  lev = LOGSTMT_ALL;
3247  }
3248  break;
3249 
3250  case T_DeallocateStmt:
3251  lev = LOGSTMT_ALL;
3252  break;
3253 
3254  case T_RenameStmt:
3255  lev = LOGSTMT_DDL;
3256  break;
3257 
3259  lev = LOGSTMT_DDL;
3260  break;
3261 
3263  lev = LOGSTMT_DDL;
3264  break;
3265 
3266  case T_AlterOwnerStmt:
3267  lev = LOGSTMT_DDL;
3268  break;
3269 
3270  case T_AlterOperatorStmt:
3271  lev = LOGSTMT_DDL;
3272  break;
3273 
3274  case T_AlterTypeStmt:
3275  lev = LOGSTMT_DDL;
3276  break;
3277 
3279  case T_AlterTableStmt:
3280  lev = LOGSTMT_DDL;
3281  break;
3282 
3283  case T_AlterDomainStmt:
3284  lev = LOGSTMT_DDL;
3285  break;
3286 
3287  case T_GrantStmt:
3288  lev = LOGSTMT_DDL;
3289  break;
3290 
3291  case T_GrantRoleStmt:
3292  lev = LOGSTMT_DDL;
3293  break;
3294 
3296  lev = LOGSTMT_DDL;
3297  break;
3298 
3299  case T_DefineStmt:
3300  lev = LOGSTMT_DDL;
3301  break;
3302 
3303  case T_CompositeTypeStmt:
3304  lev = LOGSTMT_DDL;
3305  break;
3306 
3307  case T_CreateEnumStmt:
3308  lev = LOGSTMT_DDL;
3309  break;
3310 
3311  case T_CreateRangeStmt:
3312  lev = LOGSTMT_DDL;
3313  break;
3314 
3315  case T_AlterEnumStmt:
3316  lev = LOGSTMT_DDL;
3317  break;
3318 
3319  case T_ViewStmt:
3320  lev = LOGSTMT_DDL;
3321  break;
3322 
3323  case T_CreateFunctionStmt:
3324  lev = LOGSTMT_DDL;
3325  break;
3326 
3327  case T_AlterFunctionStmt:
3328  lev = LOGSTMT_DDL;
3329  break;
3330 
3331  case T_IndexStmt:
3332  lev = LOGSTMT_DDL;
3333  break;
3334 
3335  case T_RuleStmt:
3336  lev = LOGSTMT_DDL;
3337  break;
3338 
3339  case T_CreateSeqStmt:
3340  lev = LOGSTMT_DDL;
3341  break;
3342 
3343  case T_AlterSeqStmt:
3344  lev = LOGSTMT_DDL;
3345  break;
3346 
3347  case T_DoStmt:
3348  lev = LOGSTMT_ALL;
3349  break;
3350 
3351  case T_CreatedbStmt:
3352  lev = LOGSTMT_DDL;
3353  break;
3354 
3355  case T_AlterDatabaseStmt:
3356  lev = LOGSTMT_DDL;
3357  break;
3358 
3360  lev = LOGSTMT_DDL;
3361  break;
3362 
3363  case T_DropdbStmt:
3364  lev = LOGSTMT_DDL;
3365  break;
3366 
3367  case T_NotifyStmt:
3368  lev = LOGSTMT_ALL;
3369  break;
3370 
3371  case T_ListenStmt:
3372  lev = LOGSTMT_ALL;
3373  break;
3374 
3375  case T_UnlistenStmt:
3376  lev = LOGSTMT_ALL;
3377  break;
3378 
3379  case T_LoadStmt:
3380  lev = LOGSTMT_ALL;
3381  break;
3382 
3383  case T_CallStmt:
3384  lev = LOGSTMT_ALL;
3385  break;
3386 
3387  case T_ClusterStmt:
3388  lev = LOGSTMT_DDL;
3389  break;
3390 
3391  case T_VacuumStmt:
3392  lev = LOGSTMT_ALL;
3393  break;
3394 
3395  case T_ExplainStmt:
3396  {
3397  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3398  bool analyze = false;
3399  ListCell *lc;
3400 
3401  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3402  foreach(lc, stmt->options)
3403  {
3404  DefElem *opt = (DefElem *) lfirst(lc);
3405 
3406  if (strcmp(opt->defname, "analyze") == 0)
3407  analyze = defGetBoolean(opt);
3408  /* don't "break", as explain.c will use the last value */
3409  }
3410  if (analyze)
3411  return GetCommandLogLevel(stmt->query);
3412 
3413  /* Plain EXPLAIN isn't so interesting */
3414  lev = LOGSTMT_ALL;
3415  }
3416  break;
3417 
3418  case T_CreateTableAsStmt:
3419  lev = LOGSTMT_DDL;
3420  break;
3421 
3422  case T_RefreshMatViewStmt:
3423  lev = LOGSTMT_DDL;
3424  break;
3425 
3426  case T_AlterSystemStmt:
3427  lev = LOGSTMT_DDL;
3428  break;
3429 
3430  case T_VariableSetStmt:
3431  lev = LOGSTMT_ALL;
3432  break;
3433 
3434  case T_VariableShowStmt:
3435  lev = LOGSTMT_ALL;
3436  break;
3437 
3438  case T_DiscardStmt:
3439  lev = LOGSTMT_ALL;
3440  break;
3441 
3442  case T_CreateTrigStmt:
3443  lev = LOGSTMT_DDL;
3444  break;
3445 
3446  case T_CreateEventTrigStmt:
3447  lev = LOGSTMT_DDL;
3448  break;
3449 
3450  case T_AlterEventTrigStmt:
3451  lev = LOGSTMT_DDL;
3452  break;
3453 
3454  case T_CreatePLangStmt:
3455  lev = LOGSTMT_DDL;
3456  break;
3457 
3458  case T_CreateDomainStmt:
3459  lev = LOGSTMT_DDL;
3460  break;
3461 
3462  case T_CreateRoleStmt:
3463  lev = LOGSTMT_DDL;
3464  break;
3465 
3466  case T_AlterRoleStmt:
3467  lev = LOGSTMT_DDL;
3468  break;
3469 
3470  case T_AlterRoleSetStmt:
3471  lev = LOGSTMT_DDL;
3472  break;
3473 
3474  case T_DropRoleStmt:
3475  lev = LOGSTMT_DDL;
3476  break;
3477 
3478  case T_DropOwnedStmt:
3479  lev = LOGSTMT_DDL;
3480  break;
3481 
3482  case T_ReassignOwnedStmt:
3483  lev = LOGSTMT_DDL;
3484  break;
3485 
3486  case T_LockStmt:
3487  lev = LOGSTMT_ALL;
3488  break;
3489 
3490  case T_ConstraintsSetStmt:
3491  lev = LOGSTMT_ALL;
3492  break;
3493 
3494  case T_CheckPointStmt:
3495  lev = LOGSTMT_ALL;
3496  break;
3497 
3498  case T_ReindexStmt:
3499  lev = LOGSTMT_ALL; /* should this be DDL? */
3500  break;
3501 
3503  lev = LOGSTMT_DDL;
3504  break;
3505 
3506  case T_CreateCastStmt:
3507  lev = LOGSTMT_DDL;
3508  break;
3509 
3510  case T_CreateOpClassStmt:
3511  lev = LOGSTMT_DDL;
3512  break;
3513 
3514  case T_CreateOpFamilyStmt:
3515  lev = LOGSTMT_DDL;
3516  break;
3517 
3518  case T_CreateTransformStmt:
3519  lev = LOGSTMT_DDL;
3520  break;
3521 
3522  case T_AlterOpFamilyStmt:
3523  lev = LOGSTMT_DDL;
3524  break;
3525 
3526  case T_CreatePolicyStmt:
3527  lev = LOGSTMT_DDL;
3528  break;
3529 
3530  case T_AlterPolicyStmt:
3531  lev = LOGSTMT_DDL;
3532  break;
3533 
3535  lev = LOGSTMT_DDL;
3536  break;
3537 
3539  lev = LOGSTMT_DDL;
3540  break;
3541 
3542  case T_CreateAmStmt:
3543  lev = LOGSTMT_DDL;
3544  break;
3545 
3547  lev = LOGSTMT_DDL;
3548  break;
3549 
3551  lev = LOGSTMT_DDL;
3552  break;
3553 
3555  lev = LOGSTMT_DDL;
3556  break;
3557 
3559  lev = LOGSTMT_DDL;
3560  break;
3561 
3563  lev = LOGSTMT_DDL;
3564  break;
3565 
3566  case T_CreateStatsStmt:
3567  lev = LOGSTMT_DDL;
3568  break;
3569 
3570  case T_AlterStatsStmt:
3571  lev = LOGSTMT_DDL;
3572  break;
3573 
3574  /* already-planned queries */
3575  case T_PlannedStmt:
3576  {
3577  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3578 
3579  switch (stmt->commandType)
3580  {
3581  case CMD_SELECT:
3582  lev = LOGSTMT_ALL;
3583  break;
3584 
3585  case CMD_UPDATE:
3586  case CMD_INSERT:
3587  case CMD_DELETE:
3588  lev = LOGSTMT_MOD;
3589  break;
3590 
3591  case CMD_UTILITY:
3592  lev = GetCommandLogLevel(stmt->utilityStmt);
3593  break;
3594 
3595  default:
3596  elog(WARNING, "unrecognized commandType: %d",
3597  (int) stmt->commandType);
3598  lev = LOGSTMT_ALL;
3599  break;
3600  }
3601  }
3602  break;
3603 
3604  /* parsed-and-rewritten-but-not-planned queries */
3605  case T_Query:
3606  {
3607  Query *stmt = (Query *) parsetree;
3608 
3609  switch (stmt->commandType)
3610  {
3611  case CMD_SELECT:
3612  lev = LOGSTMT_ALL;
3613  break;
3614 
3615  case CMD_UPDATE:
3616  case CMD_INSERT:
3617  case CMD_DELETE:
3618  lev = LOGSTMT_MOD;
3619  break;
3620 
3621  case CMD_UTILITY:
3622  lev = GetCommandLogLevel(stmt->utilityStmt);
3623  break;
3624 
3625  default:
3626  elog(WARNING, "unrecognized commandType: %d",
3627  (int) stmt->commandType);
3628  lev = LOGSTMT_ALL;
3629  break;
3630  }
3631 
3632  }
3633  break;
3634 
3635  default:
3636  elog(WARNING, "unrecognized node type: %d",
3637  (int) nodeTag(parsetree));
3638  lev = LOGSTMT_ALL;
3639  break;
3640  }
3641 
3642  return lev;
3643 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:35
List * options
Definition: parsenodes.h:3295
Node * utilityStmt
Definition: parsenodes.h:120
Node * query
Definition: parsenodes.h:3294
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1539
Node * utilityStmt
Definition: plannodes.h:86
#define WARNING
Definition: elog.h:40
Definition: nodes.h:311
CmdType commandType
Definition: plannodes.h:46
CmdType commandType
Definition: parsenodes.h:112
#define lfirst(lc)
Definition: pg_list.h:169
Node * query
Definition: parsenodes.h:3458
struct RawStmt * raw_parse_tree
Definition: plancache.h:99
#define nodeTag(nodeptr)
Definition: nodes.h:535
#define elog(elevel,...)
Definition: elog.h:228
char * name
Definition: parsenodes.h:3470
char * defname
Definition: parsenodes.h:733
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:467
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2916
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3126

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 445 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and RecoveryInProgress().

Referenced by pg_current_xact_id(), pg_notify(), and standard_ProcessUtility().

446 {
447  if (RecoveryInProgress())
448  ereport(ERROR,
449  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
450  /* translator: %s is name of a SQL command, eg CREATE */
451  errmsg("cannot execute %s during recovery",
452  cmdname)));
453 }
int errcode(int sqlerrcode)
Definition: elog.c:704
bool RecoveryInProgress(void)
Definition: xlog.c:8132
#define ERROR
Definition: elog.h:45
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 426 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and IsInParallelMode().

Referenced by do_setval(), ExecCheckXactReadOnly(), nextval_internal(), and standard_ProcessUtility().

427 {
428  if (IsInParallelMode())
429  ereport(ERROR,
430  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
431  /* translator: %s is name of a SQL command, eg CREATE */
432  errmsg("cannot execute %s during a parallel operation",
433  cmdname)));
434 }
int errcode(int sqlerrcode)
Definition: elog.c:704
bool IsInParallelMode(void)
Definition: xact.c:1012
#define ERROR
Definition: elog.h:45
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 408 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and XactReadOnly.

Referenced by do_setval(), DoCopy(), ExecCheckXactReadOnly(), nextval_internal(), and standard_ProcessUtility().

409 {
410  if (XactReadOnly)
411  ereport(ERROR,
412  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
413  /* translator: %s is name of a SQL command, eg CREATE */
414  errmsg("cannot execute %s in a read-only transaction",
415  cmdname)));
416 }
int errcode(int sqlerrcode)
Definition: elog.c:704
#define ERROR
Definition: elog.h:45
#define ereport(elevel,...)
Definition: elog.h:155
bool XactReadOnly
Definition: xact.c:78
int errmsg(const char *fmt,...)
Definition: elog.c:915

◆ ProcessUtility()

void ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)

Definition at line 502 of file utility.c.

References Assert, CMD_UTILITY, QueryCompletion::commandTag, PlannedStmt::commandType, generate_unaccent_rules::dest, IsA, ProcessUtility_hook, and standard_ProcessUtility().

Referenced by _SPI_execute_plan(), CreateSchemaCommand(), execute_sql_string(), ImportForeignSchema(), PortalRunUtility(), postquel_getnext(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

509 {
510  Assert(IsA(pstmt, PlannedStmt));
511  Assert(pstmt->commandType == CMD_UTILITY);
512  Assert(queryString != NULL); /* required as of 8.4 */
513  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
514 
515  /*
516  * We provide a function hook variable that lets loadable plugins get
517  * control when ProcessUtility is called. Such a plugin would normally
518  * call standard_ProcessUtility().
519  */
521  (*ProcessUtility_hook) (pstmt, queryString,
522  context, params, queryEnv,
523  dest, qc);
524  else
525  standard_ProcessUtility(pstmt, queryString,
526  context, params, queryEnv,
527  dest, qc);
528 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:581
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:76
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:542
CmdType commandType
Definition: plannodes.h:46
CommandTag commandTag
Definition: cmdtag.h:30
#define Assert(condition)
Definition: c.h:804

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1850 of file utility.c.

References PlannedStmt::canSetTag, CMD_UTILITY, PlannedStmt::commandType, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), makeNode, None_Receiver, AlterTableUtilityContext::params, PROCESS_UTILITY_SUBCOMMAND, ProcessUtility(), AlterTableUtilityContext::pstmt, AlterTableUtilityContext::queryEnv, AlterTableUtilityContext::queryString, AlterTableUtilityContext::relid, PlannedStmt::stmt_len, PlannedStmt::stmt_location, and PlannedStmt::utilityStmt.

Referenced by ATParseTransformCmd(), and ATRewriteTables().

1851 {
1852  PlannedStmt *wrapper;
1853 
1854  /*
1855  * For event triggers, we must "close" the current complex-command set,
1856  * and start a new one afterwards; this is needed to ensure the ordering
1857  * of command events is consistent with the way they were executed.
1858  */
1860 
1861  /* Create a suitable wrapper */
1862  wrapper = makeNode(PlannedStmt);
1863  wrapper->commandType = CMD_UTILITY;
1864  wrapper->canSetTag = false;
1865  wrapper->utilityStmt = stmt;
1866  wrapper->stmt_location = context->pstmt->stmt_location;
1867  wrapper->stmt_len = context->pstmt->stmt_len;
1868 
1869  ProcessUtility(wrapper,
1870  context->queryString,
1872  context->params,
1873  context->queryEnv,
1874  None_Receiver,
1875  NULL);
1876 
1879 }
PlannedStmt * pstmt
Definition: utility.h:32
DestReceiver * None_Receiver
Definition: dest.c:96
int stmt_len
Definition: plannodes.h:90
void EventTriggerAlterTableStart(Node *parsetree)
int stmt_location
Definition: plannodes.h:89
Node * utilityStmt
Definition: plannodes.h:86
const char * queryString
Definition: utility.h:33
QueryEnvironment * queryEnv
Definition: utility.h:36
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define makeNode(_type_)
Definition: nodes.h:578
void EventTriggerAlterTableRelid(Oid objectId)
ParamListInfo params
Definition: utility.h:35
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:502
void EventTriggerAlterTableEnd(void)

◆ ProcessUtilitySlow()

static void ProcessUtilitySlow ( ParseState pstate,
PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)
static

Definition at line 1056 of file utility.c.

References AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterOperator(), AlterOpFamily(), AlterPolicy(), AlterPublication(), AlterSequence(), AlterStatistics(), AlterSubscription(), AlterTable(), AlterTableGetLockLevel(), AlterTableLookupRelation(), AlterTableMoveAll(), AlterTSConfiguration(), AlterTSDictionary(), AlterType(), AlterUserMapping(), DefineStmt::args, Assert, CreateForeignTableStmt::base, AlterDomainStmt::behavior, PlannedStmt::canSetTag, CMD_UTILITY, AlterTableStmt::cmds, CompositeTypeStmt::coldeflist, CommandCounterIncrement(), PlannedStmt::commandType, CommentObject(), IndexStmt::concurrent, CreateAccessMethod(), CreateCast(), CreateConversionCommand(), CreateExtension(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateFunction(), CreatePolicy(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTransform(), CreateTrigger(), CreateUserMapping(), AlterDomainStmt::def, DefineAggregate(), DefineCollation(), DefineCompositeType(), DefineDomain(), DefineEnum(), DefineIndex(), DefineOpClass(), DefineOperator(), DefineOpFamily(), DefineRange(), DefineRelation(), DefineRule(), DefineSequence(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), DefineType(), DefineView(), DefineStmt::definition, DefineStmt::defnames, DropOwnedObjects(), DropSubscription(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), EventTriggerBeginCompleteQuery(), EventTriggerCollectAlterDefPrivs(), EventTriggerCollectSimpleCommand(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerEndCompleteQuery(), EventTriggerInhibitCommandCollection(), EventTriggerSQLDrop(), EventTriggerUndoInhibitCommandCollection(), ExecAlterDefaultPrivilegesStmt(), ExecAlterExtensionContentsStmt(), ExecAlterExtensionStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecCreateTableAs(), ExecDropStmt(), ExecRefreshMatView(), ExecRenameStmt(), ExecSecLabelStmt(), ExecuteGrantStmt(), expandTableLikeClause(), find_all_inheritors(), get_rel_relkind(), HEAP_RELOPT_NAMESPACES, heap_reloptions(), DefineStmt::if_not_exists, ImportForeignSchema(), RangeVar::inh, InvalidObjectAddress, InvalidOid, IsA, DefineStmt::kind, lfirst_oid, linitial, list_concat(), list_delete_first(), list_free(), makeNode, AlterDomainStmt::missing_ok, AlterDomainStmt::name, NewRelationCreateToastTable(), NIL, nodeTag, None_Receiver, NOTICE, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_OPERATOR, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, ObjectAddress::objectId, OidIsValid, DefineStmt::oldstyle, CreateStmt::options, AlterTableUtilityContext::params, PG_END_TRY, PG_FINALLY, PG_TRY, PreventInTransactionBlock(), IndexStmt::primary, PROCESS_UTILITY_SUBCOMMAND, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), AlterTableUtilityContext::pstmt, AlterTableUtilityContext::queryEnv, AlterTableUtilityContext::queryString, RangeVarCallbackOwnsRelation(), RangeVarGetRelidExtended(), AlterTableStmt::relation, CreateStmt::relation, IndexStmt::relation, AlterTableUtilityContext::relid, RangeVar::relname, RemoveUserMapping(), DefineStmt::replace, ShareLock, ShareUpdateExclusiveLock, PlannedStmt::stmt_len, PlannedStmt::stmt_location, AlterDomainStmt::subtype, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterTableMoveAllStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CommentStmt, T_CompositeTypeStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DefineStmt, T_DropOwnedStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropUserMappingStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_RefreshMatViewStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_ViewStmt, transformCreateStmt(), IndexStmt::transformed, transformIndexStmt(), transformRelOptions(), AlterDomainStmt::typeName, CompositeTypeStmt::typevar, IndexStmt::unique, and PlannedStmt::utilityStmt.

Referenced by standard_ProcessUtility().

1064 {
1065  Node *parsetree = pstmt->utilityStmt;
1066  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
1067  bool isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
1068  bool needCleanup;
1069  bool commandCollected = false;
1070  ObjectAddress address;
1071  ObjectAddress secondaryObject = InvalidObjectAddress;
1072 
1073  /* All event trigger calls are done only when isCompleteQuery is true */
1074  needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
1075 
1076  /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
1077  PG_TRY();
1078  {
1079  if (isCompleteQuery)
1080  EventTriggerDDLCommandStart(parsetree);
1081 
1082  switch (nodeTag(parsetree))
1083  {
1084  /*
1085  * relation and attribute manipulation
1086  */
1087  case T_CreateSchemaStmt:
1088  CreateSchemaCommand((CreateSchemaStmt *) parsetree,
1089  queryString,
1090  pstmt->stmt_location,
1091  pstmt->stmt_len);
1092 
1093  /*
1094  * EventTriggerCollectSimpleCommand called by
1095  * CreateSchemaCommand
1096  */
1097  commandCollected = true;
1098  break;
1099 
1100  case T_CreateStmt:
1102  {
1103  List *stmts;
1104  RangeVar *table_rv = NULL;
1105 
1106  /* Run parse analysis ... */
1107  stmts = transformCreateStmt((CreateStmt *) parsetree,
1108  queryString);
1109 
1110  /*
1111  * ... and do it. We can't use foreach() because we may
1112  * modify the list midway through, so pick off the
1113  * elements one at a time, the hard way.
1114  */
1115  while (stmts != NIL)
1116  {
1117  Node *stmt = (Node *) linitial(stmts);
1118 
1119  stmts = list_delete_first(stmts);
1120 
1121  if (IsA(stmt, CreateStmt))
1122  {
1123  CreateStmt *cstmt = (CreateStmt *) stmt;
1124  Datum toast_options;
1125  static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
1126 
1127  /* Remember transformed RangeVar for LIKE */
1128  table_rv = cstmt->relation;
1129 
1130  /* Create the table itself */
1131  address = DefineRelation(cstmt,
1132  RELKIND_RELATION,
1133  InvalidOid, NULL,
1134  queryString);
1136  secondaryObject,
1137  stmt);
1138 
1139  /*
1140  * Let NewRelationCreateToastTable decide if this
1141  * one needs a secondary relation too.
1142  */
1144 
1145  /*
1146  * parse and validate reloptions for the toast
1147  * table
1148  */
1149  toast_options = transformRelOptions((Datum) 0,
1150  cstmt->options,
1151  "toast",
1152  validnsps,
1153  true,
1154  false);
1155  (void) heap_reloptions(RELKIND_TOASTVALUE,
1156  toast_options,
1157  true);
1158 
1160  toast_options);
1161  }
1162  else if (IsA(stmt, CreateForeignTableStmt))
1163  {
1165 
1166  /* Remember transformed RangeVar for LIKE */
1167  table_rv = cstmt->base.relation;
1168 
1169  /* Create the table itself */
1170  address = DefineRelation(&cstmt->base,
1171  RELKIND_FOREIGN_TABLE,
1172  InvalidOid, NULL,
1173  queryString);
1174  CreateForeignTable(cstmt,
1175  address.objectId);
1177  secondaryObject,
1178  stmt);
1179  }
1180  else if (IsA(stmt, TableLikeClause))
1181  {
1182  /*
1183  * Do delayed processing of LIKE options. This
1184  * will result in additional sub-statements for us
1185  * to process. Those should get done before any
1186  * remaining actions, so prepend them to "stmts".
1187  */
1188  TableLikeClause *like = (TableLikeClause *) stmt;
1189  List *morestmts;
1190 
1191  Assert(table_rv != NULL);
1192 
1193  morestmts = expandTableLikeClause(table_rv, like);
1194  stmts = list_concat(morestmts, stmts);
1195  }
1196  else
1197  {
1198  /*
1199  * Recurse for anything else. Note the recursive
1200  * call will stash the objects so created into our
1201  * event trigger context.
1202  */
1203  PlannedStmt *wrapper;
1204 
1205  wrapper = makeNode(PlannedStmt);
1206  wrapper->commandType = CMD_UTILITY;
1207  wrapper->canSetTag = false;
1208  wrapper->utilityStmt = stmt;
1209  wrapper->stmt_location = pstmt->stmt_location;
1210  wrapper->stmt_len = pstmt->stmt_len;
1211 
1212  ProcessUtility(wrapper,
1213  queryString,
1215  params,
1216  NULL,
1217  None_Receiver,
1218  NULL);
1219  }
1220 
1221  /* Need CCI between commands */
1222  if (stmts != NIL)
1224  }
1225 
1226  /*
1227  * The multiple commands generated here are stashed
1228  * individually, so disable collection below.
1229  */
1230  commandCollected = true;
1231  }
1232  break;
1233 
1234  case T_AlterTableStmt:
1235  {
1236  AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1237  Oid relid;
1238  LOCKMODE lockmode;
1239 
1240  /*
1241  * Figure out lock mode, and acquire lock. This also does
1242  * basic permissions checks, so that we won't wait for a
1243  * lock on (for example) a relation on which we have no
1244  * permissions.
1245  */
1246  lockmode = AlterTableGetLockLevel(atstmt->cmds);
1247  relid = AlterTableLookupRelation(atstmt, lockmode);
1248 
1249  if (OidIsValid(relid))
1250  {
1251  AlterTableUtilityContext atcontext;
1252 
1253  /* Set up info needed for recursive callbacks ... */
1254  atcontext.pstmt = pstmt;
1255  atcontext.queryString = queryString;
1256  atcontext.relid = relid;
1257  atcontext.params = params;
1258  atcontext.queryEnv = queryEnv;
1259 
1260  /* ... ensure we have an event trigger context ... */
1261  EventTriggerAlterTableStart(parsetree);
1263 
1264  /* ... and do it */
1265  AlterTable(atstmt, lockmode, &atcontext);
1266 
1267  /* done */
1269  }
1270  else
1271  ereport(NOTICE,
1272  (errmsg("relation \"%s\" does not exist, skipping",
1273  atstmt->relation->relname)));
1274  }
1275 
1276  /* ALTER TABLE stashes commands internally */
1277  commandCollected = true;
1278  break;
1279 
1280  case T_AlterDomainStmt:
1281  {
1282  AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
1283 
1284  /*
1285  * Some or all of these functions are recursive to cover
1286  * inherited things, so permission checks are done there.
1287  */
1288  switch (stmt->subtype)
1289  {
1290  case 'T': /* ALTER DOMAIN DEFAULT */
1291 
1292  /*
1293  * Recursively alter column default for table and,
1294  * if requested, for descendants
1295  */
1296  address =
1298  stmt->def);
1299  break;
1300  case 'N': /* ALTER DOMAIN DROP NOT NULL */
1301  address =
1303  false);
1304  break;
1305  case 'O': /* ALTER DOMAIN SET NOT NULL */
1306  address =
1308  true);
1309  break;
1310  case 'C': /* ADD CONSTRAINT */
1311  address =
1313  stmt->def,
1314  &secondaryObject);
1315  break;
1316  case 'X': /* DROP CONSTRAINT */
1317  address =
1319  stmt->name,
1320  stmt->behavior,
1321  stmt->missing_ok);
1322  break;
1323  case 'V': /* VALIDATE CONSTRAINT */
1324  address =
1326  stmt->name);
1327  break;
1328  default: /* oops */
1329  elog(ERROR, "unrecognized alter domain type: %d",
1330  (int) stmt->subtype);
1331  break;
1332  }
1333  }
1334  break;
1335 
1336  /*
1337  * ************* object creation / destruction **************
1338  */
1339  case T_DefineStmt:
1340  {
1341  DefineStmt *stmt = (DefineStmt *) parsetree;
1342 
1343  switch (stmt->kind)
1344  {
1345  case OBJECT_AGGREGATE:
1346  address =
1347  DefineAggregate(pstate, stmt->defnames, stmt->args,
1348  stmt->oldstyle,
1349  stmt->definition,
1350  stmt->replace);
1351  break;
1352  case OBJECT_OPERATOR:
1353  Assert(stmt->args == NIL);
1354  address = DefineOperator(stmt->defnames,
1355  stmt->definition);
1356  break;
1357  case OBJECT_TYPE:
1358  Assert(stmt->args == NIL);
1359  address = DefineType(pstate,
1360  stmt->defnames,
1361  stmt->definition);
1362  break;
1363  case OBJECT_TSPARSER:
1364  Assert(stmt->args == NIL);
1365  address = DefineTSParser(stmt->defnames,
1366  stmt->definition);
1367  break;
1368  case OBJECT_TSDICTIONARY:
1369  Assert(stmt->args == NIL);
1370  address = DefineTSDictionary(stmt->defnames,
1371  stmt->definition);
1372  break;
1373  case OBJECT_TSTEMPLATE:
1374  Assert(stmt->args == NIL);
1375  address = DefineTSTemplate(stmt->defnames,
1376  stmt->definition);
1377  break;
1379  Assert(stmt->args == NIL);
1380  address = DefineTSConfiguration(stmt->defnames,
1381  stmt->definition,
1382  &secondaryObject);
1383  break;
1384  case OBJECT_COLLATION:
1385  Assert(stmt->args == NIL);
1386  address = DefineCollation(pstate,
1387  stmt->defnames,
1388  stmt->definition,
1389  stmt->if_not_exists);
1390  break;
1391  default:
1392  elog(ERROR, "unrecognized define stmt type: %d",
1393  (int) stmt->kind);
1394  break;
1395  }
1396  }
1397  break;
1398 
1399  case T_IndexStmt: /* CREATE INDEX */
1400  {
1401  IndexStmt *stmt = (IndexStmt *) parsetree;
1402  Oid relid;
1403  LOCKMODE lockmode;
1404  bool is_alter_table;
1405 
1406  if (stmt->concurrent)
1407  PreventInTransactionBlock(isTopLevel,
1408  "CREATE INDEX CONCURRENTLY");
1409 
1410  /*
1411  * Look up the relation OID just once, right here at the
1412  * beginning, so that we don't end up repeating the name
1413  * lookup later and latching onto a different relation
1414  * partway through. To avoid lock upgrade hazards, it's
1415  * important that we take the strongest lock that will
1416  * eventually be needed here, so the lockmode calculation
1417  * needs to match what DefineIndex() does.
1418  */
1419  lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1420  : ShareLock;
1421  relid =
1422  RangeVarGetRelidExtended(stmt->relation, lockmode,
1423  0,
1425  NULL);
1426 
1427  /*
1428  * CREATE INDEX on partitioned tables (but not regular
1429  * inherited tables) recurses to partitions, so we must
1430  * acquire locks early to avoid deadlocks.
1431  *
1432  * We also take the opportunity to verify that all
1433  * partitions are something we can put an index on, to
1434  * avoid building some indexes only to fail later.
1435  */
1436  if (stmt->relation->inh &&
1437  get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
1438  {
1439  ListCell *lc;
1440  List *inheritors = NIL;
1441 
1442  inheritors = find_all_inheritors(relid, lockmode, NULL);
1443  foreach(lc, inheritors)
1444  {
1445  char relkind = get_rel_relkind(lfirst_oid(lc));
1446 
1447  if (relkind != RELKIND_RELATION &&
1448  relkind != RELKIND_MATVIEW &&
1449  relkind != RELKIND_PARTITIONED_TABLE &&
1450  relkind != RELKIND_FOREIGN_TABLE)
1451  elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
1452  relkind, stmt->relation->relname);
1453 
1454  if (relkind == RELKIND_FOREIGN_TABLE &&
1455  (stmt->unique || stmt->primary))
1456  ereport(ERROR,
1457  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1458  errmsg("cannot create unique index on partitioned table \"%s\"",
1459  stmt->relation->relname),
1460  errdetail("Table \"%s\" contains partitions that are foreign tables.",
1461  stmt->relation->relname)));
1462  }
1463  list_free(inheritors);
1464  }
1465 
1466  /*
1467  * If the IndexStmt is already transformed, it must have
1468  * come from generateClonedIndexStmt, which in current
1469  * usage means it came from expandTableLikeClause rather
1470  * than from original parse analysis. And that means we
1471  * must treat it like ALTER TABLE ADD INDEX, not CREATE.
1472  * (This is a bit grotty, but currently it doesn't seem
1473  * worth adding a separate bool field for the purpose.)
1474  */
1475  is_alter_table = stmt->transformed;
1476 
1477  /* Run parse analysis ... */
1478  stmt = transformIndexStmt(relid, stmt, queryString);
1479 
1480  /* ... and do it */
1481  EventTriggerAlterTableStart(parsetree);
1482  address =
1483  DefineIndex(relid, /* OID of heap relation */
1484  stmt,
1485  InvalidOid, /* no predefined OID */
1486  InvalidOid, /* no parent index */
1487  InvalidOid, /* no parent constraint */
1488  is_alter_table,
1489  true, /* check_rights */
1490  true, /* check_not_in_use */
1491  false, /* skip_build */
1492  false); /* quiet */
1493 
1494  /*
1495  * Add the CREATE INDEX node itself to stash right away;
1496  * if there were any commands stashed in the ALTER TABLE
1497  * code, we need them to appear after this one.
1498  */
1499  EventTriggerCollectSimpleCommand(address, secondaryObject,
1500  parsetree);
1501  commandCollected = true;
1503  }
1504  break;
1505 
1506  case T_CreateExtensionStmt:
1507  address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1508  break;
1509 
1510  case T_AlterExtensionStmt:
1511  address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1512  break;
1513 
1516  &secondaryObject);
1517  break;
1518 
1519  case T_CreateFdwStmt:
1520  address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
1521  break;
1522 
1523  case T_AlterFdwStmt:
1524  address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
1525  break;
1526 
1528  address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1529  break;
1530 
1532  address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1533  break;
1534 
1536  address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1537  break;
1538 
1540  address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1541  break;
1542 
1543  case T_DropUserMappingStmt:
1544  RemoveUserMapping((DropUserMappingStmt *) parsetree);
1545  /* no commands stashed for DROP */
1546  commandCollected = true;
1547  break;
1548 
1551  /* commands are stashed inside ImportForeignSchema */
1552  commandCollected = true;
1553  break;
1554 
1555  case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1556  {
1557  CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1558 
1559  address = DefineCompositeType(stmt->typevar,
1560  stmt->coldeflist);
1561  }
1562  break;
1563 
1564  case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1565  address = DefineEnum((CreateEnumStmt *) parsetree);
1566  break;
1567 
1568  case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1569  address = DefineRange((CreateRangeStmt *) parsetree);
1570  break;
1571 
1572  case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1573  address = AlterEnum((AlterEnumStmt *) parsetree);
1574  break;
1575 
1576  case T_ViewStmt: /* CREATE VIEW */
1577  EventTriggerAlterTableStart(parsetree);
1578  address = DefineView((ViewStmt *) parsetree, queryString,
1579  pstmt->stmt_location, pstmt->stmt_len);
1580  EventTriggerCollectSimpleCommand(address, secondaryObject,
1581  parsetree);
1582  /* stashed internally */
1583  commandCollected = true;
1585  break;
1586 
1587  case T_CreateFunctionStmt: /* CREATE FUNCTION */
1588  address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1589  break;
1590 
1591  case T_AlterFunctionStmt: /* ALTER FUNCTION */
1592  address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1593  break;
1594 
1595  case T_RuleStmt: /* CREATE RULE */
1596  address = DefineRule((RuleStmt *) parsetree, queryString);
1597  break;
1598 
1599  case T_CreateSeqStmt:
1600  address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1601  break;
1602 
1603  case T_AlterSeqStmt:
1604  address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1605  break;
1606 
1607  case T_CreateTableAsStmt:
1608  address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
1609  params, queryEnv, qc);
1610  break;
1611 
1612  case T_RefreshMatViewStmt:
1613 
1614  /*
1615  * REFRESH CONCURRENTLY executes some DDL commands internally.
1616  * Inhibit DDL command collection here to avoid those commands
1617  * from showing up in the deparsed command queue. The refresh
1618  * command itself is queued, which is enough.
1619  */
1621  PG_TRY();
1622  {
1623  address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1624  queryString, params, qc);
1625  }
1626  PG_FINALLY();
1627  {
1629  }
1630  PG_END_TRY();
1631  break;
1632 
1633  case T_CreateTrigStmt:
1634  address = CreateTrigger((CreateTrigStmt *) parsetree,
1635  queryString, InvalidOid, InvalidOid,
1637  InvalidOid, NULL, false, false);
1638  break;
1639 
1640  case T_CreatePLangStmt:
1641  address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1642  break;
1643 
1644  case T_CreateDomainStmt:
1645  address = DefineDomain((CreateDomainStmt *) parsetree);
1646  break;
1647 
1649  address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1650  break;
1651 
1652  case T_CreateCastStmt:
1653  address = CreateCast((CreateCastStmt *) parsetree);
1654  break;
1655 
1656  case T_CreateOpClassStmt:
1657  DefineOpClass((CreateOpClassStmt *) parsetree);
1658  /* command is stashed in DefineOpClass */
1659  commandCollected = true;
1660  break;
1661 
1662  case T_CreateOpFamilyStmt:
1663  address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1664  break;
1665 
1666  case T_CreateTransformStmt:
1667  address = CreateTransform((CreateTransformStmt *) parsetree);
1668  break;
1669 
1670  case T_AlterOpFamilyStmt:
1671  AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1672  /* commands are stashed in AlterOpFamily */
1673  commandCollected = true;
1674  break;
1675 
1677  address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1678  break;
1679 
1682 
1683  /*
1684  * Commands are stashed in MakeConfigurationMapping and
1685  * DropConfigurationMapping, which are called from
1686  * AlterTSConfiguration
1687  */
1688  commandCollected = true;
1689  break;
1690 
1693  /* commands are stashed in AlterTableMoveAll */
1694  commandCollected = true;
1695  break;
1696 
1697  case T_DropStmt:
1698  ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1699  /* no commands stashed for DROP */
1700  commandCollected = true;
1701  break;
1702 
1703  case T_RenameStmt:
1704  address = ExecRenameStmt((RenameStmt *) parsetree);
1705  break;
1706 
1708  address =
1710  &secondaryObject);
1711  break;
1712 
1714  address =
1716  &secondaryObject);
1717  break;
1718 
1719  case T_AlterOwnerStmt:
1720  address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1721  break;
1722 
1723  case T_AlterOperatorStmt:
1724  address = AlterOperator((AlterOperatorStmt *) parsetree);
1725  break;
1726 
1727  case T_AlterTypeStmt:
1728  address = AlterType((AlterTypeStmt *) parsetree);
1729  break;
1730 
1731  case T_CommentStmt:
1732  address = CommentObject((CommentStmt *) parsetree);
1733  break;
1734 
1735  case T_GrantStmt:
1736  ExecuteGrantStmt((GrantStmt *) parsetree);
1737  /* commands are stashed in ExecGrantStmt_oids */
1738  commandCollected = true;
1739  break;
1740 
1741  case T_DropOwnedStmt:
1742  DropOwnedObjects((DropOwnedStmt *) parsetree);
1743  /* no commands stashed for DROP */
1744  commandCollected = true;
1745  break;
1746 
1750  commandCollected = true;
1751  break;
1752 
1753  case T_CreatePolicyStmt: /* CREATE POLICY */
1754  address = CreatePolicy((CreatePolicyStmt *) parsetree);
1755  break;
1756 
1757  case T_AlterPolicyStmt: /* ALTER POLICY */
1758  address = AlterPolicy((AlterPolicyStmt *) parsetree);
1759  break;
1760 
1761  case T_SecLabelStmt:
1762  address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1763  break;
1764 
1765  case T_CreateAmStmt:
1766  address = CreateAccessMethod((CreateAmStmt *) parsetree);
1767  break;
1768 
1770  address = CreatePublication((CreatePublicationStmt *) parsetree);
1771  break;
1772 
1774  AlterPublication((AlterPublicationStmt *) parsetree);
1775 
1776  /*
1777  * AlterPublication calls EventTriggerCollectSimpleCommand
1778  * directly
1779  */
1780  commandCollected = true;
1781  break;
1782 
1784  address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
1785  isTopLevel);
1786  break;
1787 
1789  address = AlterSubscription((AlterSubscriptionStmt *) parsetree,
1790  isTopLevel);
1791  break;
1792 
1794  DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1795  /* no commands stashed for DROP */
1796  commandCollected = true;
1797  break;
1798 
1799  case T_CreateStatsStmt:
1800  address = CreateStatistics((CreateStatsStmt *) parsetree);
1801  break;
1802 
1803  case T_AlterStatsStmt:
1804  address = AlterStatistics((AlterStatsStmt *) parsetree);
1805  break;
1806 
1807  default:
1808  elog(ERROR, "unrecognized node type: %d",
1809  (int) nodeTag(parsetree));
1810  break;
1811  }
1812 
1813  /*
1814  * Remember the object so that ddl_command_end event triggers have
1815  * access to it.
1816  */
1817  if (!commandCollected)
1818  EventTriggerCollectSimpleCommand(address, secondaryObject,
1819  parsetree);
1820 
1821  if (isCompleteQuery)
1822  {
1823  EventTriggerSQLDrop(parsetree);
1824  EventTriggerDDLCommandEnd(parsetree);
1825  }
1826  }
1827  PG_FINALLY();
1828  {
1829  if (needCleanup)
1831  }
1832  PG_END_TRY();
1833 }
RangeVar * relation
Definition: parsenodes.h:2115
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Definition: sequence.c:422
ObjectAddress DefineTSParser(List *names, List *parameters)
Definition: tsearchcmds.c:178
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1996
#define NIL
Definition: pg_list.h:65
bool primary
Definition: parsenodes.h:2836
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:969
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1395
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:581
ObjectAddress DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
Definition: tsearchcmds.c:893
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1885
ObjectAddress DefineIndex(Oid relationId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
Definition: indexcmds.c:506
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2929
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:1132
ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt)
Definition: foreigncmds.c:562
DropBehavior behavior
Definition: parsenodes.h:1950
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
Definition: functioncmds.c:918
int LOCKMODE
Definition: lockdefs.h:26
ObjectAddress CreatePublication(CreatePublicationStmt *stmt)
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:113
PlannedStmt * pstmt
Definition: utility.h:32
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:3728
ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName)
Definition: typecmds.c:3045
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters, bool replace)
Definition: aggregatecmds.c:56
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1974
ObjectAddress AlterEnum(AlterEnumStmt *stmt)
Definition: typecmds.c:1264
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1373
RangeVar * typevar
Definition: parsenodes.h:3117
void EventTriggerDDLCommandEnd(Node *parsetree)
Definition: nodes.h:530
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3277
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
int errcode(int sqlerrcode)
Definition: elog.c:704
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:39
void EventTriggerInhibitCommandCollection(void)
ObjectAddress DefineDomain(CreateDomainStmt *stmt)
Definition: typecmds.c:696
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2521
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:328
DestReceiver * None_Receiver
Definition: dest.c:96
ObjectAddress CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition: toasting.c:69
#define OidIsValid(objectId)
Definition: c.h:710
int stmt_len
Definition: plannodes.h:90
void EventTriggerAlterTableStart(Node *parsetree)
char * relname
Definition: primnodes.h:68
void AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode, AlterTableUtilityContext *context)
Definition: tablecmds.c:3784
RangeVar * relation
Definition: parsenodes.h:2820
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:870
ObjectAddress AlterStatistics(AlterStatsStmt *stmt)
Definition: statscmds.c:434
#define linitial(l)
Definition: pg_list.h:174
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:15688
List * args
Definition: parsenodes.h:2615
#define ERROR
Definition: elog.h:45
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2579
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:409
void EventTriggerDDLCommandStart(Node *parsetree)
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:670
void EventTriggerSQLDrop(Node *parsetree)
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1109
ObjectAddress AlterType(AlterTypeStmt *stmt)
Definition: typecmds.c:4109
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2710
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1315
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1095
int stmt_location
Definition: plannodes.h:89
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:487
bool transformed
Definition: parsenodes.h:2840
int errdetail(const char *fmt,...)
Definition: elog.c:1048
Node * utilityStmt
Definition: plannodes.h:86
ObjectAddress DefineRange(CreateRangeStmt *stmt)
Definition: typecmds.c:1339
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3379
const char * queryString
Definition: utility.h:33
List * options
Definition: parsenodes.h:2123
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:236
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1140
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:407
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: schemacmds.c:50
#define HEAP_RELOPT_NAMESPACES
Definition: reloptions.h:61
ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt)
Definition: foreigncmds.c:1217
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:331
ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
Definition: sequence.c:118
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:584
QueryEnvironment * queryEnv
Definition: utility.h:36
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:904
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:148
bool inh
Definition: primnodes.h:69
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1680
void EventTriggerEndCompleteQuery(void)
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:3858
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:842
bool replace
Definition: parsenodes.h:2618
#define PG_FINALLY()
Definition: elog.h:326
bool canSetTag
Definition: plannodes.h:54
void EventTriggerUndoInhibitCommandCollection(void)
uintptr_t Datum
Definition: postgres.h:367
CmdType commandType
Definition: plannodes.h:46
void CommandCounterIncrement(void)
Definition: xact.c:1021
bool unique
Definition: parsenodes.h:2835
ObjectType kind
Definition: parsenodes.h:2612
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:431
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
List * expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
#define InvalidOid
Definition: postgres_ext.h:36
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:53
List * defnames
Definition: parsenodes.h:2614
#define ereport(elevel,...)
Definition: elog.h:155
#define NOTICE
Definition: elog.h:37
ObjectAddress CreateCast(CreateCastStmt *stmt)
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:2969
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:495
#define makeNode(_type_)
Definition: nodes.h:578
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:391
#define Assert(condition)
Definition: c.h:804
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, QueryCompletion *qc)
Definition: matview.c:138
ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
Definition: tablecmds.c:13400
ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt)
Definition: foreigncmds.c:678
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:833
ObjectAddress ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, ParamListInfo params, QueryEnvironment *queryEnv, QueryCompletion *qc)
Definition: createas.c:226
#define nodeTag(nodeptr)
Definition: nodes.h:535
void EventTriggerAlterTableRelid(Oid objectId)
Oid AlterOpFamily(AlterOpFamilyStmt *stmt)
Definition: opclasscmds.c:808
ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt)
Definition: opclasscmds.c:763
ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok)
Definition: typecmds.c:2830
bool concurrent
Definition: parsenodes.h:2841
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:165
const ObjectAddress InvalidObjectAddress
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
Definition: foreigncmds.c:1475
int errmsg(const char *fmt,...)
Definition: elog.c:915
RangeVar * relation
Definition: parsenodes.h:1827
void list_free(List *list)
Definition: list.c:1391
#define elog(elevel,...)
Definition: elog.h:228
#define ShareLock
Definition: lockdefs.h:41
ObjectAddress DefineTSTemplate(List *names, List *parameters)
Definition: tsearchcmds.c:684
bool if_not_exists
Definition: parsenodes.h:2617
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)
Definition: trigger.c:150
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:43
List * definition
Definition: parsenodes.h:2616
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define PG_TRY()
Definition: elog.h:309
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
Definition: pg_list.h:50
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
ParamListInfo params
Definition: utility.h:35
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:502
bool oldstyle
Definition: parsenodes.h:2613
#define PG_END_TRY()
Definition: elog.h:334
ObjectAddress AlterSubscription(AlterSubscriptionStmt *stmt, bool isTopLevel)
#define lfirst_oid(lc)
Definition: pg_list.h:171
void AlterPublication(AlterPublicationStmt *stmt)
List * list_delete_first(List *list)
Definition: list.c:875
bool EventTriggerBeginCompleteQuery(void)
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:359
void EventTriggerAlterTableEnd(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:62

◆ standard_ProcessUtility()

void standard_ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)

Definition at line 542 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, TransactionStmt::chain, check_stack_depth(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), ClassifyUtilityCommandAsReadOnly(), closeAllVfds(), cluster(), COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_PARALLEL_MODE, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, CommandCounterIncrement(), CommentObject(), NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecReindex(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetCommandTagName(), GetPGVariable(), TransactionStmt::gid, GrantRole(), IsInParallelMode(), IsTransactionBlock(), TransactionStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), VariableShowStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ParseState::p_queryEnv, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), SetQueryCompletion(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSystemStmt, T_AlterTableSpaceOptionsStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

Referenced by pgss_ProcessUtility(), ProcessUtility(), and sepgsql_utility_command().

549 {
550  Node *parsetree = pstmt->utilityStmt;
551  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
552  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
553  ParseState *pstate;
554  int readonly_flags;
555 
556  /* This can recurse, so check for excessive recursion */
558 
559  /* Prohibit read/write commands in read-only states. */
560  readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
561  if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
563  {
564  CommandTag commandtag = CreateCommandTag(parsetree);
565 
566  if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
568  if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
570  if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
572  }
573 
574  pstate = make_parsestate(NULL);
575  pstate->p_sourcetext = queryString;
576  pstate->p_queryEnv = queryEnv;
577 
578  switch (nodeTag(parsetree))
579  {
580  /*
581  * ******************** transactions ********************
582  */
583  case T_TransactionStmt:
584  {
585  TransactionStmt *stmt = (TransactionStmt *) parsetree;
586 
587  switch (stmt->kind)
588  {
589  /*
590  * START TRANSACTION, as defined by SQL99: Identical
591  * to BEGIN. Same code for both.
592  */
593  case TRANS_STMT_BEGIN:
594  case TRANS_STMT_START:
595  {
596  ListCell *lc;
597 
599  foreach(lc, stmt->options)
600  {
601  DefElem *item = (DefElem *) lfirst(lc);
602 
603  if (strcmp(item->defname, "transaction_isolation") == 0)
604  SetPGVariable("transaction_isolation",
605  list_make1(item->arg),
606  true);
607  else if (strcmp(item->defname, "transaction_read_only") == 0)
608  SetPGVariable("transaction_read_only",
609  list_make1(item->arg),
610  true);
611  else if (strcmp(item->defname, "transaction_deferrable") == 0)
612  SetPGVariable("transaction_deferrable",
613  list_make1(item->arg),
614  true);
615  }
616  }
617  break;
618 
619  case TRANS_STMT_COMMIT:
620  if (!EndTransactionBlock(stmt->chain))
621  {
622  /* report unsuccessful commit in qc */
623  if (qc)
624  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
625  }
626  break;
627 
628  case TRANS_STMT_PREPARE:
629  if (!PrepareTransactionBlock(stmt->gid))
630  {
631  /* report unsuccessful commit in qc */
632  if (qc)
633  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
634  }
635  break;
636 
638  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
639  FinishPreparedTransaction(stmt->gid, true);
640  break;
641 
643  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
644  FinishPreparedTransaction(stmt->gid, false);
645  break;
646 
647  case TRANS_STMT_ROLLBACK:
649  break;
650 
652  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
654  break;
655 
656  case TRANS_STMT_RELEASE:
657  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
659  break;
660 
662  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
664 
665  /*
666  * CommitTransactionCommand is in charge of
667  * re-defining the savepoint again
668  */
669  break;
670  }
671  }
672  break;
673 
674  /*
675  * Portal (cursor) manipulation
676  */
677  case T_DeclareCursorStmt:
678  PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
679  isTopLevel);
680  break;
681 
682  case T_ClosePortalStmt:
683  {
684  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
685 
686  CheckRestrictedOperation("CLOSE");
688  }
689  break;
690 
691  case T_FetchStmt:
692  PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
693  break;
694 
695  case T_DoStmt:
696  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
697  break;
698 
700  /* no event triggers for global objects */
701  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
702  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
703  break;
704 
706  /* no event triggers for global objects */
707  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
708  DropTableSpace((DropTableSpaceStmt *) parsetree);
709  break;
710 
712  /* no event triggers for global objects */
714  break;
715 
716  case T_TruncateStmt:
717  ExecuteTruncate((TruncateStmt *) parsetree);
718  break;
719 
720  case T_CopyStmt:
721  {
722  uint64 processed;
723 
724  DoCopy(pstate, (CopyStmt *) parsetree,
725  pstmt->stmt_location, pstmt->stmt_len,
726  &processed);
727  if (qc)
728  SetQueryCompletion(qc, CMDTAG_COPY, processed);
729  }
730  break;
731 
732  case T_PrepareStmt:
733  CheckRestrictedOperation("PREPARE");
734  PrepareQuery(pstate, (PrepareStmt *) parsetree,
735  pstmt->stmt_location, pstmt->stmt_len);
736  break;
737 
738  case T_ExecuteStmt:
739  ExecuteQuery(pstate,
740  (ExecuteStmt *) parsetree, NULL,
741  params,
742  dest, qc);
743  break;
744 
745  case T_DeallocateStmt:
746  CheckRestrictedOperation("DEALLOCATE");
747  DeallocateQuery((DeallocateStmt *) parsetree);
748  break;
749 
750  case T_GrantRoleStmt:
751  /* no event triggers for global objects */
752  GrantRole((GrantRoleStmt *) parsetree);
753  break;
754 
755  case T_CreatedbStmt:
756  /* no event triggers for global objects */
757  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
758  createdb(pstate, (CreatedbStmt *) parsetree);
759  break;
760 
761  case T_AlterDatabaseStmt:
762  /* no event triggers for global objects */
763  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
764  break;
765 
767  /* no event triggers for global objects */
768  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
769  break;
770 
771  case T_DropdbStmt:
772  /* no event triggers for global objects */
773  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
774  DropDatabase(pstate, (DropdbStmt *) parsetree);
775  break;
776 
777  /* Query-level asynchronous notification */
778  case T_NotifyStmt:
779  {
780  NotifyStmt *stmt = (NotifyStmt *) parsetree;
781 
782  Async_Notify(stmt->conditionname, stmt->payload);
783  }
784  break;
785 
786  case T_ListenStmt:
787  {
788  ListenStmt *stmt = (ListenStmt *) parsetree;
789 
790  CheckRestrictedOperation("LISTEN");
792  }
793  break;
794 
795  case T_UnlistenStmt:
796  {
797  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
798 
799  CheckRestrictedOperation("UNLISTEN");
800  if (stmt->conditionname)
802  else
804  }
805  break;
806 
807  case T_LoadStmt:
808  {
809  LoadStmt *stmt = (LoadStmt *) parsetree;
810 
811  closeAllVfds(); /* probably not necessary... */
812  /* Allowed names are restricted if you're not superuser */
813  load_file(stmt->filename, !superuser());
814  }
815  break;
816 
817  case T_CallStmt:
818  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
819  break;
820 
821  case T_ClusterStmt:
822  cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
823  break;
824 
825  case T_VacuumStmt:
826  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
827  break;
828 
829  case T_ExplainStmt:
830  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
831  break;
832 
833  case T_AlterSystemStmt:
834  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
836  break;
837 
838  case T_VariableSetStmt:
839  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
840  break;
841 
842  case T_VariableShowStmt:
843  {
844  VariableShowStmt *n = (VariableShowStmt *) parsetree;
845 
846  GetPGVariable(n->name, dest);
847  }
848  break;
849 
850  case T_DiscardStmt:
851  /* should we allow DISCARD PLANS? */
852  CheckRestrictedOperation("DISCARD");
853  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
854  break;
855 
857  /* no event triggers on event triggers */
859  break;
860 
862  /* no event triggers on event triggers */
863  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
864  break;
865 
866  /*
867  * ******************************** ROLE statements ****
868  */
869  case T_CreateRoleStmt:
870  /* no event triggers for global objects */
871  CreateRole(pstate, (CreateRoleStmt *) parsetree);
872  break;
873 
874  case T_AlterRoleStmt:
875  /* no event triggers for global objects */
876  AlterRole((AlterRoleStmt *) parsetree);
877  break;
878 
879  case T_AlterRoleSetStmt:
880  /* no event triggers for global objects */
881  AlterRoleSet((AlterRoleSetStmt *) parsetree);
882  break;
883 
884  case T_DropRoleStmt:
885  /* no event triggers for global objects */
886  DropRole((DropRoleStmt *) parsetree);
887  break;
888 
889  case T_ReassignOwnedStmt:
890  /* no event triggers for global objects */
892  break;
893 
894  case T_LockStmt:
895 
896  /*
897  * Since the lock would just get dropped immediately, LOCK TABLE
898  * outside a transaction block is presumed to be user error.
899  */
900  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
901  LockTableCommand((LockStmt *) parsetree);
902  break;
903 
905  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
907  break;
908 
909  case T_CheckPointStmt:
910  if (!superuser())
911  ereport(ERROR,
912  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
913  errmsg("must be superuser to do CHECKPOINT")));
914 
917  break;
918 
919  case T_ReindexStmt:
920  ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
921  break;
922 
923  /*
924  * The following statements are supported by Event Triggers only
925  * in some cases, so we "fast path" them in the other cases.
926  */
927 
928  case T_GrantStmt:
929  {
930  GrantStmt *stmt = (GrantStmt *) parsetree;
931 
933  ProcessUtilitySlow(pstate, pstmt, queryString,
934  context, params, queryEnv,
935  dest, qc);
936  else
937  ExecuteGrantStmt(stmt);
938  }
939  break;
940 
941  case T_DropStmt:
942  {
943  DropStmt *stmt = (DropStmt *) parsetree;
944 
946  ProcessUtilitySlow(pstate, pstmt, queryString,
947  context, params, queryEnv,
948  dest, qc);
949  else
950  ExecDropStmt(stmt, isTopLevel);
951  }
952  break;
953 
954  case T_RenameStmt:
955  {
956  RenameStmt *stmt = (RenameStmt *) parsetree;
957 
959  ProcessUtilitySlow(pstate, pstmt, queryString,
960  context, params, queryEnv,
961  dest, qc);
962  else
963  ExecRenameStmt(stmt);
964  }
965  break;
966 
968  {
969  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
970 
972  ProcessUtilitySlow(pstate, pstmt, queryString,
973  context, params, queryEnv,
974  dest, qc);
975  else
976  ExecAlterObjectDependsStmt(stmt, NULL);
977  }
978  break;
979 
981  {
982  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
983 
985  ProcessUtilitySlow(pstate, pstmt, queryString,
986  context, params, queryEnv,
987  dest, qc);
988  else
989  ExecAlterObjectSchemaStmt(stmt, NULL);
990  }
991  break;
992 
993  case T_AlterOwnerStmt:
994  {
995  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
996 
998  ProcessUtilitySlow(pstate, pstmt, queryString,
999  context, params, queryEnv,
1000  dest, qc);
1001  else
1002  ExecAlterOwnerStmt(stmt);
1003  }
1004  break;
1005 
1006  case T_CommentStmt:
1007  {
1008  CommentStmt *stmt = (CommentStmt *) parsetree;
1009 
1011  ProcessUtilitySlow(pstate, pstmt, queryString,
1012  context, params, queryEnv,
1013  dest, qc);
1014  else
1015  CommentObject(stmt);
1016  break;
1017  }
1018 
1019  case T_SecLabelStmt:
1020  {
1021  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1022 
1024  ProcessUtilitySlow(pstate, pstmt, queryString,
1025  context, params, queryEnv,
1026  dest, qc);
1027  else
1028  ExecSecLabelStmt(stmt);
1029  break;
1030  }
1031 
1032  default:
1033  /* All other statement types have event trigger support */
1034  ProcessUtilitySlow(pstate, pstmt, queryString,
1035  context, params, queryEnv,
1036  dest, qc);
1037  break;
1038  }
1039 
1040  free_parsestate(pstate);
1041 
1042  /*
1043  * Make effects of commands visible, for instance so that
1044  * PreCommit_on_commit_actions() can see them (see for example bug
1045  * #15631).
1046  */
1048 }
ObjectType objtype
Definition: parsenodes.h:2724
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:161
CommandTag
Definition: cmdtag.h:20
void closeAllVfds(void)
Definition: fd.c:2792
ObjectType objtype
Definition: parsenodes.h:2736
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1885
void PerformPortalClose(const char *name)
Definition: portalcmds.c:220
bool EndTransactionBlock(bool chain)
Definition: xact.c:3757
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:426
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:103
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectType renameType
Definition: parsenodes.h:2961
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:113
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3439
#define castNode(_type_, nodeptr)
Definition: nodes.h:599
QueryEnvironment * p_queryEnv
Definition: parse_node.h:204
void ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel)
Definition: indexcmds.c:2480
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1650
ObjectType objectType
Definition: parsenodes.h:3007
void DefineSavepoint(const char *name)
Definition: xact.c:4086
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5028
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:463
Definition: nodes.h:530
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3705
int errcode(int sqlerrcode)
Definition: elog.c:704
bool superuser(void)
Definition: superuser.c:46
char * filename
Definition: parsenodes.h:3187
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
Definition: prepare.c:58
void Async_Listen(const char *channel)
Definition: async.c:765
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: