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, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, 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 2174 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().

2175 {
2176  CommandTag tag;
2177 
2178  switch (objtype)
2179  {
2180  case OBJECT_AGGREGATE:
2181  tag = CMDTAG_ALTER_AGGREGATE;
2182  break;
2183  case OBJECT_ATTRIBUTE:
2184  tag = CMDTAG_ALTER_TYPE;
2185  break;
2186  case OBJECT_CAST:
2187  tag = CMDTAG_ALTER_CAST;
2188  break;
2189  case OBJECT_COLLATION:
2190  tag = CMDTAG_ALTER_COLLATION;
2191  break;
2192  case OBJECT_COLUMN:
2193  tag = CMDTAG_ALTER_TABLE;
2194  break;
2195  case OBJECT_CONVERSION:
2196  tag = CMDTAG_ALTER_CONVERSION;
2197  break;
2198  case OBJECT_DATABASE:
2199  tag = CMDTAG_ALTER_DATABASE;
2200  break;
2201  case OBJECT_DOMAIN:
2202  case OBJECT_DOMCONSTRAINT:
2203  tag = CMDTAG_ALTER_DOMAIN;
2204  break;
2205  case OBJECT_EXTENSION:
2206  tag = CMDTAG_ALTER_EXTENSION;
2207  break;
2208  case OBJECT_FDW:
2209  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2210  break;
2211  case OBJECT_FOREIGN_SERVER:
2212  tag = CMDTAG_ALTER_SERVER;
2213  break;
2214  case OBJECT_FOREIGN_TABLE:
2215  tag = CMDTAG_ALTER_FOREIGN_TABLE;
2216  break;
2217  case OBJECT_FUNCTION:
2218  tag = CMDTAG_ALTER_FUNCTION;
2219  break;
2220  case OBJECT_INDEX:
2221  tag = CMDTAG_ALTER_INDEX;
2222  break;
2223  case OBJECT_LANGUAGE:
2224  tag = CMDTAG_ALTER_LANGUAGE;
2225  break;
2226  case OBJECT_LARGEOBJECT:
2227  tag = CMDTAG_ALTER_LARGE_OBJECT;
2228  break;
2229  case OBJECT_OPCLASS:
2230  tag = CMDTAG_ALTER_OPERATOR_CLASS;
2231  break;
2232  case OBJECT_OPERATOR:
2233  tag = CMDTAG_ALTER_OPERATOR;
2234  break;
2235  case OBJECT_OPFAMILY:
2236  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2237  break;
2238  case OBJECT_POLICY:
2239  tag = CMDTAG_ALTER_POLICY;
2240  break;
2241  case OBJECT_PROCEDURE:
2242  tag = CMDTAG_ALTER_PROCEDURE;
2243  break;
2244  case OBJECT_ROLE:
2245  tag = CMDTAG_ALTER_ROLE;
2246  break;
2247  case OBJECT_ROUTINE:
2248  tag = CMDTAG_ALTER_ROUTINE;
2249  break;
2250  case OBJECT_RULE:
2251  tag = CMDTAG_ALTER_RULE;
2252  break;
2253  case OBJECT_SCHEMA:
2254  tag = CMDTAG_ALTER_SCHEMA;
2255  break;
2256  case OBJECT_SEQUENCE:
2257  tag = CMDTAG_ALTER_SEQUENCE;
2258  break;
2259  case OBJECT_TABLE:
2260  case OBJECT_TABCONSTRAINT:
2261  tag = CMDTAG_ALTER_TABLE;
2262  break;
2263  case OBJECT_TABLESPACE:
2264  tag = CMDTAG_ALTER_TABLESPACE;
2265  break;
2266  case OBJECT_TRIGGER:
2267  tag = CMDTAG_ALTER_TRIGGER;
2268  break;
2269  case OBJECT_EVENT_TRIGGER:
2270  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2271  break;
2273  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2274  break;
2275  case OBJECT_TSDICTIONARY:
2276  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2277  break;
2278  case OBJECT_TSPARSER:
2279  tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2280  break;
2281  case OBJECT_TSTEMPLATE:
2282  tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2283  break;
2284  case OBJECT_TYPE:
2285  tag = CMDTAG_ALTER_TYPE;
2286  break;
2287  case OBJECT_VIEW:
2288  tag = CMDTAG_ALTER_VIEW;
2289  break;
2290  case OBJECT_MATVIEW:
2291  tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2292  break;
2293  case OBJECT_PUBLICATION:
2294  tag = CMDTAG_ALTER_PUBLICATION;
2295  break;
2296  case OBJECT_SUBSCRIPTION:
2297  tag = CMDTAG_ALTER_SUBSCRIPTION;
2298  break;
2299  case OBJECT_STATISTIC_EXT:
2300  tag = CMDTAG_ALTER_STATISTICS;
2301  break;
2302  default:
2303  tag = CMDTAG_UNKNOWN;
2304  break;
2305  }
2306 
2307  return tag;
2308 }
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:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:610
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ 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:46
#define RowExclusiveLock
Definition: lockdefs.h:38
#define nodeTag(nodeptr)
Definition: nodes.h:544
#define COMMAND_IS_NOT_READ_ONLY
Definition: utility.h:68
bool is_from
Definition: parsenodes.h:2113
#define elog(elevel,...)
Definition: elog.h:232
#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:3184

◆ 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:590
#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:232

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2320 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_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_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(), interpret_AS_clause(), PrepareQuery(), and standard_ProcessUtility().

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

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1954 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().

1955 {
1956  switch (stmt->removeType)
1957  {
1958  case OBJECT_INDEX:
1959  if (stmt->concurrent)
1960  PreventInTransactionBlock(isTopLevel,
1961  "DROP INDEX CONCURRENTLY");
1962  /* fall through */
1963 
1964  case OBJECT_TABLE:
1965  case OBJECT_SEQUENCE:
1966  case OBJECT_VIEW:
1967  case OBJECT_MATVIEW:
1968  case OBJECT_FOREIGN_TABLE:
1969  RemoveRelations(stmt);
1970  break;
1971  default:
1972  RemoveObjects(stmt);
1973  break;
1974  }
1975 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:57
ObjectType removeType
Definition: parsenodes.h:2754
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1306
bool concurrent
Definition: parsenodes.h:2757
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3379

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3199 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_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_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().

3200 {
3201  LogStmtLevel lev;
3202 
3203  switch (nodeTag(parsetree))
3204  {
3205  /* recurse if we're given a RawStmt */
3206  case T_RawStmt:
3207  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
3208  break;
3209 
3210  /* raw plannable queries */
3211  case T_InsertStmt:
3212  case T_DeleteStmt:
3213  case T_UpdateStmt:
3214  lev = LOGSTMT_MOD;
3215  break;
3216 
3217  case T_SelectStmt:
3218  if (((SelectStmt *) parsetree)->intoClause)
3219  lev = LOGSTMT_DDL; /* SELECT INTO */
3220  else
3221  lev = LOGSTMT_ALL;
3222  break;
3223 
3224  case T_PLAssignStmt:
3225  lev = LOGSTMT_ALL;
3226  break;
3227 
3228  /* utility statements --- same whether raw or cooked */
3229  case T_TransactionStmt:
3230  lev = LOGSTMT_ALL;
3231  break;
3232 
3233  case T_DeclareCursorStmt:
3234  lev = LOGSTMT_ALL;
3235  break;
3236 
3237  case T_ClosePortalStmt:
3238  lev = LOGSTMT_ALL;
3239  break;
3240 
3241  case T_FetchStmt:
3242  lev = LOGSTMT_ALL;
3243  break;
3244 
3245  case T_CreateSchemaStmt:
3246  lev = LOGSTMT_DDL;
3247  break;
3248 
3249  case T_CreateStmt:
3251  lev = LOGSTMT_DDL;
3252  break;
3253 
3255  case T_DropTableSpaceStmt:
3257  lev = LOGSTMT_DDL;
3258  break;
3259 
3260  case T_CreateExtensionStmt:
3261  case T_AlterExtensionStmt:
3263  lev = LOGSTMT_DDL;
3264  break;
3265 
3266  case T_CreateFdwStmt:
3267  case T_AlterFdwStmt:
3272  case T_DropUserMappingStmt:
3274  lev = LOGSTMT_DDL;
3275  break;
3276 
3277  case T_DropStmt:
3278  lev = LOGSTMT_DDL;
3279  break;
3280 
3281  case T_TruncateStmt:
3282  lev = LOGSTMT_MOD;
3283  break;
3284 
3285  case T_CommentStmt:
3286  lev = LOGSTMT_DDL;
3287  break;
3288 
3289  case T_SecLabelStmt:
3290  lev = LOGSTMT_DDL;
3291  break;
3292 
3293  case T_CopyStmt:
3294  if (((CopyStmt *) parsetree)->is_from)
3295  lev = LOGSTMT_MOD;
3296  else
3297  lev = LOGSTMT_ALL;
3298  break;
3299 
3300  case T_PrepareStmt:
3301  {
3302  PrepareStmt *stmt = (PrepareStmt *) parsetree;
3303 
3304  /* Look through a PREPARE to the contained stmt */
3305  lev = GetCommandLogLevel(stmt->query);
3306  }
3307  break;
3308 
3309  case T_ExecuteStmt:
3310  {
3311  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3312  PreparedStatement *ps;
3313 
3314  /* Look through an EXECUTE to the referenced stmt */
3315  ps = FetchPreparedStatement(stmt->name, false);
3316  if (ps && ps->plansource->raw_parse_tree)
3318  else
3319  lev = LOGSTMT_ALL;
3320  }
3321  break;
3322 
3323  case T_DeallocateStmt:
3324  lev = LOGSTMT_ALL;
3325  break;
3326 
3327  case T_RenameStmt:
3328  lev = LOGSTMT_DDL;
3329  break;
3330 
3332  lev = LOGSTMT_DDL;
3333  break;
3334 
3336  lev = LOGSTMT_DDL;
3337  break;
3338 
3339  case T_AlterOwnerStmt:
3340  lev = LOGSTMT_DDL;
3341  break;
3342 
3343  case T_AlterOperatorStmt:
3344  lev = LOGSTMT_DDL;
3345  break;
3346 
3347  case T_AlterTypeStmt:
3348  lev = LOGSTMT_DDL;
3349  break;
3350 
3352  case T_AlterTableStmt:
3353  lev = LOGSTMT_DDL;
3354  break;
3355 
3356  case T_AlterDomainStmt:
3357  lev = LOGSTMT_DDL;
3358  break;
3359 
3360  case T_GrantStmt:
3361  lev = LOGSTMT_DDL;
3362  break;
3363 
3364  case T_GrantRoleStmt:
3365  lev = LOGSTMT_DDL;
3366  break;
3367 
3369  lev = LOGSTMT_DDL;
3370  break;
3371 
3372  case T_DefineStmt:
3373  lev = LOGSTMT_DDL;
3374  break;
3375 
3376  case T_CompositeTypeStmt:
3377  lev = LOGSTMT_DDL;
3378  break;
3379 
3380  case T_CreateEnumStmt:
3381  lev = LOGSTMT_DDL;
3382  break;
3383 
3384  case T_CreateRangeStmt:
3385  lev = LOGSTMT_DDL;
3386  break;
3387 
3388  case T_AlterEnumStmt:
3389  lev = LOGSTMT_DDL;
3390  break;
3391 
3392  case T_ViewStmt:
3393  lev = LOGSTMT_DDL;
3394  break;
3395 
3396  case T_CreateFunctionStmt:
3397  lev = LOGSTMT_DDL;
3398  break;
3399 
3400  case T_AlterFunctionStmt:
3401  lev = LOGSTMT_DDL;
3402  break;
3403 
3404  case T_IndexStmt:
3405  lev = LOGSTMT_DDL;
3406  break;
3407 
3408  case T_RuleStmt:
3409  lev = LOGSTMT_DDL;
3410  break;
3411 
3412  case T_CreateSeqStmt:
3413  lev = LOGSTMT_DDL;
3414  break;
3415 
3416  case T_AlterSeqStmt:
3417  lev = LOGSTMT_DDL;
3418  break;
3419 
3420  case T_DoStmt:
3421  lev = LOGSTMT_ALL;
3422  break;
3423 
3424  case T_CreatedbStmt:
3425  lev = LOGSTMT_DDL;
3426  break;
3427 
3428  case T_AlterDatabaseStmt:
3429  lev = LOGSTMT_DDL;
3430  break;
3431 
3433  lev = LOGSTMT_DDL;
3434  break;
3435 
3436  case T_DropdbStmt:
3437  lev = LOGSTMT_DDL;
3438  break;
3439 
3440  case T_NotifyStmt:
3441  lev = LOGSTMT_ALL;
3442  break;
3443 
3444  case T_ListenStmt:
3445  lev = LOGSTMT_ALL;
3446  break;
3447 
3448  case T_UnlistenStmt:
3449  lev = LOGSTMT_ALL;
3450  break;
3451 
3452  case T_LoadStmt:
3453  lev = LOGSTMT_ALL;
3454  break;
3455 
3456  case T_CallStmt:
3457  lev = LOGSTMT_ALL;
3458  break;
3459 
3460  case T_ClusterStmt:
3461  lev = LOGSTMT_DDL;
3462  break;
3463 
3464  case T_VacuumStmt:
3465  lev = LOGSTMT_ALL;
3466  break;
3467 
3468  case T_ExplainStmt:
3469  {
3470  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3471  bool analyze = false;
3472  ListCell *lc;
3473 
3474  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3475  foreach(lc, stmt->options)
3476  {
3477  DefElem *opt = (DefElem *) lfirst(lc);
3478 
3479  if (strcmp(opt->defname, "analyze") == 0)
3480  analyze = defGetBoolean(opt);
3481  /* don't "break", as explain.c will use the last value */
3482  }
3483  if (analyze)
3484  return GetCommandLogLevel(stmt->query);
3485 
3486  /* Plain EXPLAIN isn't so interesting */
3487  lev = LOGSTMT_ALL;
3488  }
3489  break;
3490 
3491  case T_CreateTableAsStmt:
3492  lev = LOGSTMT_DDL;
3493  break;
3494 
3495  case T_RefreshMatViewStmt:
3496  lev = LOGSTMT_DDL;
3497  break;
3498 
3499  case T_AlterSystemStmt:
3500  lev = LOGSTMT_DDL;
3501  break;
3502 
3503  case T_VariableSetStmt:
3504  lev = LOGSTMT_ALL;
3505  break;
3506 
3507  case T_VariableShowStmt:
3508  lev = LOGSTMT_ALL;
3509  break;
3510 
3511  case T_DiscardStmt:
3512  lev = LOGSTMT_ALL;
3513  break;
3514 
3515  case T_CreateTrigStmt:
3516  lev = LOGSTMT_DDL;
3517  break;
3518 
3519  case T_CreateEventTrigStmt:
3520  lev = LOGSTMT_DDL;
3521  break;
3522 
3523  case T_AlterEventTrigStmt:
3524  lev = LOGSTMT_DDL;
3525  break;
3526 
3527  case T_CreatePLangStmt:
3528  lev = LOGSTMT_DDL;
3529  break;
3530 
3531  case T_CreateDomainStmt:
3532  lev = LOGSTMT_DDL;
3533  break;
3534 
3535  case T_CreateRoleStmt:
3536  lev = LOGSTMT_DDL;
3537  break;
3538 
3539  case T_AlterRoleStmt:
3540  lev = LOGSTMT_DDL;
3541  break;
3542 
3543  case T_AlterRoleSetStmt:
3544  lev = LOGSTMT_DDL;
3545  break;
3546 
3547  case T_DropRoleStmt:
3548  lev = LOGSTMT_DDL;
3549  break;
3550 
3551  case T_DropOwnedStmt:
3552  lev = LOGSTMT_DDL;
3553  break;
3554 
3555  case T_ReassignOwnedStmt:
3556  lev = LOGSTMT_DDL;
3557  break;
3558 
3559  case T_LockStmt:
3560  lev = LOGSTMT_ALL;
3561  break;
3562 
3563  case T_ConstraintsSetStmt:
3564  lev = LOGSTMT_ALL;
3565  break;
3566 
3567  case T_CheckPointStmt:
3568  lev = LOGSTMT_ALL;
3569  break;
3570 
3571  case T_ReindexStmt:
3572  lev = LOGSTMT_ALL; /* should this be DDL? */
3573  break;
3574 
3576  lev = LOGSTMT_DDL;
3577  break;
3578 
3579  case T_CreateCastStmt:
3580  lev = LOGSTMT_DDL;
3581  break;
3582 
3583  case T_CreateOpClassStmt:
3584  lev = LOGSTMT_DDL;
3585  break;
3586 
3587  case T_CreateOpFamilyStmt:
3588  lev = LOGSTMT_DDL;
3589  break;
3590 
3591  case T_CreateTransformStmt:
3592  lev = LOGSTMT_DDL;
3593  break;
3594 
3595  case T_AlterOpFamilyStmt:
3596  lev = LOGSTMT_DDL;
3597  break;
3598 
3599  case T_CreatePolicyStmt:
3600  lev = LOGSTMT_DDL;
3601  break;
3602 
3603  case T_AlterPolicyStmt:
3604  lev = LOGSTMT_DDL;
3605  break;
3606 
3608  lev = LOGSTMT_DDL;
3609  break;
3610 
3612  lev = LOGSTMT_DDL;
3613  break;
3614 
3615  case T_CreateAmStmt:
3616  lev = LOGSTMT_DDL;
3617  break;
3618 
3620  lev = LOGSTMT_DDL;
3621  break;
3622 
3624  lev = LOGSTMT_DDL;
3625  break;
3626 
3628  lev = LOGSTMT_DDL;
3629  break;
3630 
3632  lev = LOGSTMT_DDL;
3633  break;
3634 
3636  lev = LOGSTMT_DDL;
3637  break;
3638 
3639  case T_CreateStatsStmt:
3640  lev = LOGSTMT_DDL;
3641  break;
3642 
3643  case T_AlterStatsStmt:
3644  lev = LOGSTMT_DDL;
3645  break;
3646 
3647  case T_AlterCollationStmt:
3648  lev = LOGSTMT_DDL;
3649  break;
3650 
3651  /* already-planned queries */
3652  case T_PlannedStmt:
3653  {
3654  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3655 
3656  switch (stmt->commandType)
3657  {
3658  case CMD_SELECT:
3659  lev = LOGSTMT_ALL;
3660  break;
3661 
3662  case CMD_UPDATE:
3663  case CMD_INSERT:
3664  case CMD_DELETE:
3665  lev = LOGSTMT_MOD;
3666  break;
3667 
3668  case CMD_UTILITY:
3669  lev = GetCommandLogLevel(stmt->utilityStmt);
3670  break;
3671 
3672  default:
3673  elog(WARNING, "unrecognized commandType: %d",
3674  (int) stmt->commandType);
3675  lev = LOGSTMT_ALL;
3676  break;
3677  }
3678  }
3679  break;
3680 
3681  /* parsed-and-rewritten-but-not-planned queries */
3682  case T_Query:
3683  {
3684  Query *stmt = (Query *) parsetree;
3685 
3686  switch (stmt->commandType)
3687  {
3688  case CMD_SELECT:
3689  lev = LOGSTMT_ALL;
3690  break;
3691 
3692  case CMD_UPDATE:
3693  case CMD_INSERT:
3694  case CMD_DELETE:
3695  lev = LOGSTMT_MOD;
3696  break;
3697 
3698  case CMD_UTILITY:
3699  lev = GetCommandLogLevel(stmt->utilityStmt);
3700  break;
3701 
3702  default:
3703  elog(WARNING, "unrecognized commandType: %d",
3704  (int) stmt->commandType);
3705  lev = LOGSTMT_ALL;
3706  break;
3707  }
3708 
3709  }
3710  break;
3711 
3712  default:
3713  elog(WARNING, "unrecognized node type: %d",
3714  (int) nodeTag(parsetree));
3715  lev = LOGSTMT_ALL;
3716  break;
3717  }
3718 
3719  return lev;
3720 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:36
List * options
Definition: parsenodes.h:3376
Node * utilityStmt
Definition: parsenodes.h:128
Node * query
Definition: parsenodes.h:3375
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1560
Node * utilityStmt
Definition: plannodes.h:86
#define WARNING
Definition: elog.h:40
Definition: nodes.h:318
CmdType commandType
Definition: plannodes.h:46
CmdType commandType
Definition: parsenodes.h:120
#define lfirst(lc)
Definition: pg_list.h:169
Node * query
Definition: parsenodes.h:3539
struct RawStmt * raw_parse_tree
Definition: plancache.h:99
#define nodeTag(nodeptr)
Definition: nodes.h:544
#define elog(elevel,...)
Definition: elog.h:232
char * name
Definition: parsenodes.h:3551
char * defname
Definition: parsenodes.h:746
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:468
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2987
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3199

◆ 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:698
bool RecoveryInProgress(void)
Definition: xlog.c:8248
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ 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:698
bool IsInParallelMode(void)
Definition: xact.c:1012
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ 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:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
bool XactReadOnly
Definition: xact.c:78
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ ProcessUtility()

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

Definition at line 503 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().

511 {
512  Assert(IsA(pstmt, PlannedStmt));
513  Assert(pstmt->commandType == CMD_UTILITY);
514  Assert(queryString != NULL); /* required as of 8.4 */
515  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
516 
517  /*
518  * We provide a function hook variable that lets loadable plugins get
519  * control when ProcessUtility is called. Such a plugin would normally
520  * call standard_ProcessUtility().
521  */
523  (*ProcessUtility_hook) (pstmt, queryString, readOnlyTree,
524  context, params, queryEnv,
525  dest, qc);
526  else
527  standard_ProcessUtility(pstmt, queryString, readOnlyTree,
528  context, params, queryEnv,
529  dest, qc);
530 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:76
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:544
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 1918 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().

1919 {
1920  PlannedStmt *wrapper;
1921 
1922  /*
1923  * For event triggers, we must "close" the current complex-command set,
1924  * and start a new one afterwards; this is needed to ensure the ordering
1925  * of command events is consistent with the way they were executed.
1926  */
1928 
1929  /* Create a suitable wrapper */
1930  wrapper = makeNode(PlannedStmt);
1931  wrapper->commandType = CMD_UTILITY;
1932  wrapper->canSetTag = false;
1933  wrapper->utilityStmt = stmt;
1934  wrapper->stmt_location = context->pstmt->stmt_location;
1935  wrapper->stmt_len = context->pstmt->stmt_len;
1936 
1937  ProcessUtility(wrapper,
1938  context->queryString,
1939  false,
1941  context->params,
1942  context->queryEnv,
1943  None_Receiver,
1944  NULL);
1945 
1948 }
PlannedStmt * pstmt
Definition: utility.h:32
DestReceiver * None_Receiver
Definition: dest.c:96
int stmt_len
Definition: plannodes.h:90
void EventTriggerAlterTableStart(Node *parsetree)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:503
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:587
void EventTriggerAlterTableRelid(Oid objectId)
ParamListInfo params
Definition: utility.h:35
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 1071 of file utility.c.

References AlterCollation(), 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, AT_DetachPartition, 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(), AlterTableCmd::def, 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, 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(), RangeVarGetRelid, RangeVarGetRelidExtended(), AlterTableStmt::relation, CreateStmt::relation, IndexStmt::relation, CreateStatsStmt::relations, AlterTableUtilityContext::relid, RangeVar::relname, RemoveUserMapping(), DefineStmt::replace, ShareLock, ShareUpdateExclusiveLock, PlannedStmt::stmt_len, PlannedStmt::stmt_location, AlterTableCmd::subtype, AlterDomainStmt::subtype, T_AlterCollationStmt, 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(), transformStatsStmt(), AlterDomainStmt::typeName, CompositeTypeStmt::typevar, IndexStmt::unique, and PlannedStmt::utilityStmt.

Referenced by standard_ProcessUtility().

1079 {
1080  Node *parsetree = pstmt->utilityStmt;
1081  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
1082  bool isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
1083  bool needCleanup;
1084  bool commandCollected = false;
1085  ObjectAddress address;
1086  ObjectAddress secondaryObject = InvalidObjectAddress;
1087 
1088  /* All event trigger calls are done only when isCompleteQuery is true */
1089  needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
1090 
1091  /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
1092  PG_TRY();
1093  {
1094  if (isCompleteQuery)
1095  EventTriggerDDLCommandStart(parsetree);
1096 
1097  switch (nodeTag(parsetree))
1098  {
1099  /*
1100  * relation and attribute manipulation
1101  */
1102  case T_CreateSchemaStmt:
1103  CreateSchemaCommand((CreateSchemaStmt *) parsetree,
1104  queryString,
1105  pstmt->stmt_location,
1106  pstmt->stmt_len);
1107 
1108  /*
1109  * EventTriggerCollectSimpleCommand called by
1110  * CreateSchemaCommand
1111  */
1112  commandCollected = true;
1113  break;
1114 
1115  case T_CreateStmt:
1117  {
1118  List *stmts;
1119  RangeVar *table_rv = NULL;
1120 
1121  /* Run parse analysis ... */
1122  stmts = transformCreateStmt((CreateStmt *) parsetree,
1123  queryString);
1124 
1125  /*
1126  * ... and do it. We can't use foreach() because we may
1127  * modify the list midway through, so pick off the
1128  * elements one at a time, the hard way.
1129  */
1130  while (stmts != NIL)
1131  {
1132  Node *stmt = (Node *) linitial(stmts);
1133 
1134  stmts = list_delete_first(stmts);
1135 
1136  if (IsA(stmt, CreateStmt))
1137  {
1138  CreateStmt *cstmt = (CreateStmt *) stmt;
1139  Datum toast_options;
1140  static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
1141 
1142  /* Remember transformed RangeVar for LIKE */
1143  table_rv = cstmt->relation;
1144 
1145  /* Create the table itself */
1146  address = DefineRelation(cstmt,
1147  RELKIND_RELATION,
1148  InvalidOid, NULL,
1149  queryString);
1151  secondaryObject,
1152  stmt);
1153 
1154  /*
1155  * Let NewRelationCreateToastTable decide if this
1156  * one needs a secondary relation too.
1157  */
1159 
1160  /*
1161  * parse and validate reloptions for the toast
1162  * table
1163  */
1164  toast_options = transformRelOptions((Datum) 0,
1165  cstmt->options,
1166  "toast",
1167  validnsps,
1168  true,
1169  false);
1170  (void) heap_reloptions(RELKIND_TOASTVALUE,
1171  toast_options,
1172  true);
1173 
1175  toast_options);
1176  }
1177  else if (IsA(stmt, CreateForeignTableStmt))
1178  {
1180 
1181  /* Remember transformed RangeVar for LIKE */
1182  table_rv = cstmt->base.relation;
1183 
1184  /* Create the table itself */
1185  address = DefineRelation(&cstmt->base,
1186  RELKIND_FOREIGN_TABLE,
1187  InvalidOid, NULL,
1188  queryString);
1189  CreateForeignTable(cstmt,
1190  address.objectId);
1192  secondaryObject,
1193  stmt);
1194  }
1195  else if (IsA(stmt, TableLikeClause))
1196  {
1197  /*
1198  * Do delayed processing of LIKE options. This
1199  * will result in additional sub-statements for us
1200  * to process. Those should get done before any
1201  * remaining actions, so prepend them to "stmts".
1202  */
1203  TableLikeClause *like = (TableLikeClause *) stmt;
1204  List *morestmts;
1205 
1206  Assert(table_rv != NULL);
1207 
1208  morestmts = expandTableLikeClause(table_rv, like);
1209  stmts = list_concat(morestmts, stmts);
1210  }
1211  else
1212  {
1213  /*
1214  * Recurse for anything else. Note the recursive
1215  * call will stash the objects so created into our
1216  * event trigger context.
1217  */
1218  PlannedStmt *wrapper;
1219 
1220  wrapper = makeNode(PlannedStmt);
1221  wrapper->commandType = CMD_UTILITY;
1222  wrapper->canSetTag = false;
1223  wrapper->utilityStmt = stmt;
1224  wrapper->stmt_location = pstmt->stmt_location;
1225  wrapper->stmt_len = pstmt->stmt_len;
1226 
1227  ProcessUtility(wrapper,
1228  queryString,
1229  false,
1231  params,
1232  NULL,
1233  None_Receiver,
1234  NULL);
1235  }
1236 
1237  /* Need CCI between commands */
1238  if (stmts != NIL)
1240  }
1241 
1242  /*
1243  * The multiple commands generated here are stashed
1244  * individually, so disable collection below.
1245  */
1246  commandCollected = true;
1247  }
1248  break;
1249 
1250  case T_AlterTableStmt:
1251  {
1252  AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1253  Oid relid;
1254  LOCKMODE lockmode;
1255  ListCell *cell;
1256 
1257  /*
1258  * Disallow ALTER TABLE .. DETACH CONCURRENTLY in a
1259  * transaction block or function. (Perhaps it could be
1260  * allowed in a procedure, but don't hold your breath.)
1261  */
1262  foreach(cell, atstmt->cmds)
1263  {
1264  AlterTableCmd *cmd = (AlterTableCmd *) lfirst(cell);
1265 
1266  /* Disallow DETACH CONCURRENTLY in a transaction block */
1267  if (cmd->subtype == AT_DetachPartition)
1268  {
1269  if (((PartitionCmd *) cmd->def)->concurrent)
1270  PreventInTransactionBlock(isTopLevel,
1271  "ALTER TABLE ... DETACH CONCURRENTLY");
1272  }
1273  }
1274 
1275  /*
1276  * Figure out lock mode, and acquire lock. This also does
1277  * basic permissions checks, so that we won't wait for a
1278  * lock on (for example) a relation on which we have no
1279  * permissions.
1280  */
1281  lockmode = AlterTableGetLockLevel(atstmt->cmds);
1282  relid = AlterTableLookupRelation(atstmt, lockmode);
1283 
1284  if (OidIsValid(relid))
1285  {
1286  AlterTableUtilityContext atcontext;
1287 
1288  /* Set up info needed for recursive callbacks ... */
1289  atcontext.pstmt = pstmt;
1290  atcontext.queryString = queryString;
1291  atcontext.relid = relid;
1292  atcontext.params = params;
1293  atcontext.queryEnv = queryEnv;
1294 
1295  /* ... ensure we have an event trigger context ... */
1296  EventTriggerAlterTableStart(parsetree);
1298 
1299  /* ... and do it */
1300  AlterTable(atstmt, lockmode, &atcontext);
1301 
1302  /* done */
1304  }
1305  else
1306  ereport(NOTICE,
1307  (errmsg("relation \"%s\" does not exist, skipping",
1308  atstmt->relation->relname)));
1309  }
1310 
1311  /* ALTER TABLE stashes commands internally */
1312  commandCollected = true;
1313  break;
1314 
1315  case T_AlterDomainStmt:
1316  {
1317  AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
1318 
1319  /*
1320  * Some or all of these functions are recursive to cover
1321  * inherited things, so permission checks are done there.
1322  */
1323  switch (stmt->subtype)
1324  {
1325  case 'T': /* ALTER DOMAIN DEFAULT */
1326 
1327  /*
1328  * Recursively alter column default for table and,
1329  * if requested, for descendants
1330  */
1331  address =
1333  stmt->def);
1334  break;
1335  case 'N': /* ALTER DOMAIN DROP NOT NULL */
1336  address =
1338  false);
1339  break;
1340  case 'O': /* ALTER DOMAIN SET NOT NULL */
1341  address =
1343  true);
1344  break;
1345  case 'C': /* ADD CONSTRAINT */
1346  address =
1348  stmt->def,
1349  &secondaryObject);
1350  break;
1351  case 'X': /* DROP CONSTRAINT */
1352  address =
1354  stmt->name,
1355  stmt->behavior,
1356  stmt->missing_ok);
1357  break;
1358  case 'V': /* VALIDATE CONSTRAINT */
1359  address =
1361  stmt->name);
1362  break;
1363  default: /* oops */
1364  elog(ERROR, "unrecognized alter domain type: %d",
1365  (int) stmt->subtype);
1366  break;
1367  }
1368  }
1369  break;
1370 
1371  /*
1372  * ************* object creation / destruction **************
1373  */
1374  case T_DefineStmt:
1375  {
1376  DefineStmt *stmt = (DefineStmt *) parsetree;
1377 
1378  switch (stmt->kind)
1379  {
1380  case OBJECT_AGGREGATE:
1381  address =
1382  DefineAggregate(pstate, stmt->defnames, stmt->args,
1383  stmt->oldstyle,
1384  stmt->definition,
1385  stmt->replace);
1386  break;
1387  case OBJECT_OPERATOR:
1388  Assert(stmt->args == NIL);
1389  address = DefineOperator(stmt->defnames,
1390  stmt->definition);
1391  break;
1392  case OBJECT_TYPE:
1393  Assert(stmt->args == NIL);
1394  address = DefineType(pstate,
1395  stmt->defnames,
1396  stmt->definition);
1397  break;
1398  case OBJECT_TSPARSER:
1399  Assert(stmt->args == NIL);
1400  address = DefineTSParser(stmt->defnames,
1401  stmt->definition);
1402  break;
1403  case OBJECT_TSDICTIONARY:
1404  Assert(stmt->args == NIL);
1405  address = DefineTSDictionary(stmt->defnames,
1406  stmt->definition);
1407  break;
1408  case OBJECT_TSTEMPLATE:
1409  Assert(stmt->args == NIL);
1410  address = DefineTSTemplate(stmt->defnames,
1411  stmt->definition);
1412  break;
1414  Assert(stmt->args == NIL);
1415  address = DefineTSConfiguration(stmt->defnames,
1416  stmt->definition,
1417  &secondaryObject);
1418  break;
1419  case OBJECT_COLLATION:
1420  Assert(stmt->args == NIL);
1421  address = DefineCollation(pstate,
1422  stmt->defnames,
1423  stmt->definition,
1424  stmt->if_not_exists);
1425  break;
1426  default:
1427  elog(ERROR, "unrecognized define stmt type: %d",
1428  (int) stmt->kind);
1429  break;
1430  }
1431  }
1432  break;
1433 
1434  case T_IndexStmt: /* CREATE INDEX */
1435  {
1436  IndexStmt *stmt = (IndexStmt *) parsetree;
1437  Oid relid;
1438  LOCKMODE lockmode;
1439  bool is_alter_table;
1440 
1441  if (stmt->concurrent)
1442  PreventInTransactionBlock(isTopLevel,
1443  "CREATE INDEX CONCURRENTLY");
1444 
1445  /*
1446  * Look up the relation OID just once, right here at the
1447  * beginning, so that we don't end up repeating the name
1448  * lookup later and latching onto a different relation
1449  * partway through. To avoid lock upgrade hazards, it's
1450  * important that we take the strongest lock that will
1451  * eventually be needed here, so the lockmode calculation
1452  * needs to match what DefineIndex() does.
1453  */
1454  lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1455  : ShareLock;
1456  relid =
1457  RangeVarGetRelidExtended(stmt->relation, lockmode,
1458  0,
1460  NULL);
1461 
1462  /*
1463  * CREATE INDEX on partitioned tables (but not regular
1464  * inherited tables) recurses to partitions, so we must
1465  * acquire locks early to avoid deadlocks.
1466  *
1467  * We also take the opportunity to verify that all
1468  * partitions are something we can put an index on, to
1469  * avoid building some indexes only to fail later.
1470  */
1471  if (stmt->relation->inh &&
1472  get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
1473  {
1474  ListCell *lc;
1475  List *inheritors = NIL;
1476 
1477  inheritors = find_all_inheritors(relid, lockmode, NULL);
1478  foreach(lc, inheritors)
1479  {
1480  char relkind = get_rel_relkind(lfirst_oid(lc));
1481 
1482  if (relkind != RELKIND_RELATION &&
1483  relkind != RELKIND_MATVIEW &&
1484  relkind != RELKIND_PARTITIONED_TABLE &&
1485  relkind != RELKIND_FOREIGN_TABLE)
1486  elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
1487  relkind, stmt->relation->relname);
1488 
1489  if (relkind == RELKIND_FOREIGN_TABLE &&
1490  (stmt->unique || stmt->primary))
1491  ereport(ERROR,
1492  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1493  errmsg("cannot create unique index on partitioned table \"%s\"",
1494  stmt->relation->relname),
1495  errdetail("Table \"%s\" contains partitions that are foreign tables.",
1496  stmt->relation->relname)));
1497  }
1498  list_free(inheritors);
1499  }
1500 
1501  /*
1502  * If the IndexStmt is already transformed, it must have
1503  * come from generateClonedIndexStmt, which in current
1504  * usage means it came from expandTableLikeClause rather
1505  * than from original parse analysis. And that means we
1506  * must treat it like ALTER TABLE ADD INDEX, not CREATE.
1507  * (This is a bit grotty, but currently it doesn't seem
1508  * worth adding a separate bool field for the purpose.)
1509  */
1510  is_alter_table = stmt->transformed;
1511 
1512  /* Run parse analysis ... */
1513  stmt = transformIndexStmt(relid, stmt, queryString);
1514 
1515  /* ... and do it */
1516  EventTriggerAlterTableStart(parsetree);
1517  address =
1518  DefineIndex(relid, /* OID of heap relation */
1519  stmt,
1520  InvalidOid, /* no predefined OID */
1521  InvalidOid, /* no parent index */
1522  InvalidOid, /* no parent constraint */
1523  is_alter_table,
1524  true, /* check_rights */
1525  true, /* check_not_in_use */
1526  false, /* skip_build */
1527  false); /* quiet */
1528 
1529  /*
1530  * Add the CREATE INDEX node itself to stash right away;
1531  * if there were any commands stashed in the ALTER TABLE
1532  * code, we need them to appear after this one.
1533  */
1534  EventTriggerCollectSimpleCommand(address, secondaryObject,
1535  parsetree);
1536  commandCollected = true;
1538  }
1539  break;
1540 
1541  case T_CreateExtensionStmt:
1542  address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1543  break;
1544 
1545  case T_AlterExtensionStmt:
1546  address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1547  break;
1548 
1551  &secondaryObject);
1552  break;
1553 
1554  case T_CreateFdwStmt:
1555  address = CreateForeignDataWrapper(pstate, (CreateFdwStmt *) parsetree);
1556  break;
1557 
1558  case T_AlterFdwStmt:
1559  address = AlterForeignDataWrapper(pstate, (AlterFdwStmt *) parsetree);
1560  break;
1561 
1563  address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1564  break;
1565 
1567  address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1568  break;
1569 
1571  address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1572  break;
1573 
1575  address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1576  break;
1577 
1578  case T_DropUserMappingStmt:
1579  RemoveUserMapping((DropUserMappingStmt *) parsetree);
1580  /* no commands stashed for DROP */
1581  commandCollected = true;
1582  break;
1583 
1586  /* commands are stashed inside ImportForeignSchema */
1587  commandCollected = true;
1588  break;
1589 
1590  case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1591  {
1592  CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1593 
1594  address = DefineCompositeType(stmt->typevar,
1595  stmt->coldeflist);
1596  }
1597  break;
1598 
1599  case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1600  address = DefineEnum((CreateEnumStmt *) parsetree);
1601  break;
1602 
1603  case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1604  address = DefineRange(pstate, (CreateRangeStmt *) parsetree);
1605  break;
1606 
1607  case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1608  address = AlterEnum((AlterEnumStmt *) parsetree);
1609  break;
1610 
1611  case T_ViewStmt: /* CREATE VIEW */
1612  EventTriggerAlterTableStart(parsetree);
1613  address = DefineView((ViewStmt *) parsetree, queryString,
1614  pstmt->stmt_location, pstmt->stmt_len);
1615  EventTriggerCollectSimpleCommand(address, secondaryObject,
1616  parsetree);
1617  /* stashed internally */
1618  commandCollected = true;
1620  break;
1621 
1622  case T_CreateFunctionStmt: /* CREATE FUNCTION */
1623  address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1624  break;
1625 
1626  case T_AlterFunctionStmt: /* ALTER FUNCTION */
1627  address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1628  break;
1629 
1630  case T_RuleStmt: /* CREATE RULE */
1631  address = DefineRule((RuleStmt *) parsetree, queryString);
1632  break;
1633 
1634  case T_CreateSeqStmt:
1635  address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1636  break;
1637 
1638  case T_AlterSeqStmt:
1639  address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1640  break;
1641 
1642  case T_CreateTableAsStmt:
1643  address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
1644  params, queryEnv, qc);
1645  break;
1646 
1647  case T_RefreshMatViewStmt:
1648 
1649  /*
1650  * REFRESH CONCURRENTLY executes some DDL commands internally.
1651  * Inhibit DDL command collection here to avoid those commands
1652  * from showing up in the deparsed command queue. The refresh
1653  * command itself is queued, which is enough.
1654  */
1656  PG_TRY();
1657  {
1658  address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1659  queryString, params, qc);
1660  }
1661  PG_FINALLY();
1662  {
1664  }
1665  PG_END_TRY();
1666  break;
1667 
1668  case T_CreateTrigStmt:
1669  address = CreateTrigger((CreateTrigStmt *) parsetree,
1670  queryString, InvalidOid, InvalidOid,
1672  InvalidOid, NULL, false, false);
1673  break;
1674 
1675  case T_CreatePLangStmt:
1676  address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1677  break;
1678 
1679  case T_CreateDomainStmt:
1680  address = DefineDomain((CreateDomainStmt *) parsetree);
1681  break;
1682 
1684  address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1685  break;
1686 
1687  case T_CreateCastStmt:
1688  address = CreateCast((CreateCastStmt *) parsetree);
1689  break;
1690 
1691  case T_CreateOpClassStmt:
1692  DefineOpClass((CreateOpClassStmt *) parsetree);
1693  /* command is stashed in DefineOpClass */
1694  commandCollected = true;
1695  break;
1696 
1697  case T_CreateOpFamilyStmt:
1698  address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1699  break;
1700 
1701  case T_CreateTransformStmt:
1702  address = CreateTransform((CreateTransformStmt *) parsetree);
1703  break;
1704 
1705  case T_AlterOpFamilyStmt:
1706  AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1707  /* commands are stashed in AlterOpFamily */
1708  commandCollected = true;
1709  break;
1710 
1712  address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1713  break;
1714 
1717 
1718  /*
1719  * Commands are stashed in MakeConfigurationMapping and
1720  * DropConfigurationMapping, which are called from
1721  * AlterTSConfiguration
1722  */
1723  commandCollected = true;
1724  break;
1725 
1728  /* commands are stashed in AlterTableMoveAll */
1729  commandCollected = true;
1730  break;
1731 
1732  case T_DropStmt:
1733  ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1734  /* no commands stashed for DROP */
1735  commandCollected = true;
1736  break;
1737 
1738  case T_RenameStmt:
1739  address = ExecRenameStmt((RenameStmt *) parsetree);
1740  break;
1741 
1743  address =
1745  &secondaryObject);
1746  break;
1747 
1749  address =
1751  &secondaryObject);
1752  break;
1753 
1754  case T_AlterOwnerStmt:
1755  address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1756  break;
1757 
1758  case T_AlterOperatorStmt:
1759  address = AlterOperator((AlterOperatorStmt *) parsetree);
1760  break;
1761 
1762  case T_AlterTypeStmt:
1763  address = AlterType((AlterTypeStmt *) parsetree);
1764  break;
1765 
1766  case T_CommentStmt:
1767  address = CommentObject((CommentStmt *) parsetree);
1768  break;
1769 
1770  case T_GrantStmt:
1771  ExecuteGrantStmt((GrantStmt *) parsetree);
1772  /* commands are stashed in ExecGrantStmt_oids */
1773  commandCollected = true;
1774  break;
1775 
1776  case T_DropOwnedStmt:
1777  DropOwnedObjects((DropOwnedStmt *) parsetree);
1778  /* no commands stashed for DROP */
1779  commandCollected = true;
1780  break;
1781 
1785  commandCollected = true;
1786  break;
1787 
1788  case T_CreatePolicyStmt: /* CREATE POLICY */
1789  address = CreatePolicy((CreatePolicyStmt *) parsetree);
1790  break;
1791 
1792  case T_AlterPolicyStmt: /* ALTER POLICY */
1793  address = AlterPolicy((AlterPolicyStmt *) parsetree);
1794  break;
1795 
1796  case T_SecLabelStmt:
1797  address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1798  break;
1799 
1800  case T_CreateAmStmt:
1801  address = CreateAccessMethod((CreateAmStmt *) parsetree);
1802  break;
1803 
1805  address = CreatePublication(pstate, (CreatePublicationStmt *) parsetree);
1806  break;
1807 
1809  AlterPublication(pstate, (AlterPublicationStmt *) parsetree);
1810 
1811  /*
1812  * AlterPublication calls EventTriggerCollectSimpleCommand
1813  * directly
1814  */
1815  commandCollected = true;
1816  break;
1817 
1819  address = CreateSubscription(pstate,
1820  (CreateSubscriptionStmt *) parsetree,
1821  isTopLevel);
1822  break;
1823 
1825  address = AlterSubscription(pstate,
1826  (AlterSubscriptionStmt *) parsetree,
1827  isTopLevel);
1828  break;
1829 
1831  DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1832  /* no commands stashed for DROP */
1833  commandCollected = true;
1834  break;
1835 
1836  case T_CreateStatsStmt:
1837  {
1838  Oid relid;
1839  CreateStatsStmt *stmt = (CreateStatsStmt *) parsetree;
1840  RangeVar *rel = (RangeVar *) linitial(stmt->relations);
1841 
1842  if (!IsA(rel, RangeVar))
1843  ereport(ERROR,
1844  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1845  errmsg("only a single relation is allowed in CREATE STATISTICS")));
1846 
1847  /*
1848  * CREATE STATISTICS will influence future execution plans
1849  * but does not interfere with currently executing plans.
1850  * So it should be enough to take ShareUpdateExclusiveLock
1851  * on relation, conflicting with ANALYZE and other DDL
1852  * that sets statistical information, but not with normal
1853  * queries.
1854  *
1855  * XXX RangeVarCallbackOwnsRelation not needed here, to
1856  * keep the same behavior as before.
1857  */
1858  relid = RangeVarGetRelid(rel, ShareUpdateExclusiveLock, false);
1859 
1860  /* Run parse analysis ... */
1861  stmt = transformStatsStmt(relid, stmt, queryString);
1862 
1863  address = CreateStatistics(stmt);
1864  }
1865  break;
1866 
1867  case T_AlterStatsStmt:
1868  address = AlterStatistics((AlterStatsStmt *) parsetree);
1869  break;
1870 
1871  case T_AlterCollationStmt:
1872  address = AlterCollation((AlterCollationStmt *) parsetree);
1873  break;
1874 
1875  default:
1876  elog(ERROR, "unrecognized node type: %d",
1877  (int) nodeTag(parsetree));
1878  break;
1879  }
1880 
1881  /*
1882  * Remember the object so that ddl_command_end event triggers have
1883  * access to it.
1884  */
1885  if (!commandCollected)
1886  EventTriggerCollectSimpleCommand(address, secondaryObject,
1887  parsetree);
1888 
1889  if (isCompleteQuery)
1890  {
1891  EventTriggerSQLDrop(parsetree);
1892  EventTriggerDDLCommandEnd(parsetree);
1893  }
1894  }
1895  PG_FINALLY();
1896  {
1897  if (needCleanup)
1899  }
1900  PG_END_TRY();
1901 }
RangeVar * relation
Definition: parsenodes.h:2170
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:2012
#define NIL
Definition: pg_list.h:65
bool primary
Definition: parsenodes.h:2892
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:965
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1391
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
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:1954
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 CreateForeignDataWrapper(ParseState *pstate, CreateFdwStmt *stmt)
Definition: foreigncmds.c:558
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2918
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:1149
DropBehavior behavior
Definition: parsenodes.h:1994
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
int LOCKMODE
Definition: lockdefs.h:26
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:113
ObjectAddress CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
PlannedStmt * pstmt
Definition: utility.h:32
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:79
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:3949
ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName)
Definition: typecmds.c:3034
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:1261
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1313
RangeVar * typevar
Definition: parsenodes.h:3198
void EventTriggerDDLCommandEnd(Node *parsetree)
Definition: nodes.h:539
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3266
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
int errcode(int sqlerrcode)
Definition: elog.c:698
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:39
AlterTableType subtype
Definition: parsenodes.h:1949
void EventTriggerInhibitCommandCollection(void)
ObjectAddress DefineDomain(CreateDomainStmt *stmt)
Definition: typecmds.c:693
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2510
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:328
DestReceiver * None_Receiver
Definition: dest.c:96
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition: toasting.c:70
#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:4005
RangeVar * relation
Definition: parsenodes.h:2876
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:773
ObjectAddress AlterStatistics(AlterStatsStmt *stmt)
Definition: statscmds.c:579
#define linitial(l)
Definition: pg_list.h:174
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:16460
List * args
Definition: parsenodes.h:2670
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:503
#define ERROR
Definition: elog.h:46
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2568
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:409
void EventTriggerDDLCommandStart(Node *parsetree)
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:573
void EventTriggerSQLDrop(Node *parsetree)
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1109
ObjectAddress AlterType(AlterTypeStmt *stmt)
Definition: typecmds.c:4098
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2699
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1311
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1091
int stmt_location
Definition: plannodes.h:89
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:487
bool transformed
Definition: parsenodes.h:2896
int errdetail(const char *fmt,...)
Definition: elog.c:1042
Node * utilityStmt
Definition: plannodes.h:86
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3379
const char * queryString
Definition: utility.h:33
List * options
Definition: parsenodes.h:2178
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:237
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1137
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:1213
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:626
QueryEnvironment * queryEnv
Definition: utility.h:36
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:905
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:148
bool inh
Definition: primnodes.h:69
ObjectAddress AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt)
Definition: foreigncmds.c:674
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1681
void EventTriggerEndCompleteQuery(void)
ObjectAddress AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt, bool isTopLevel)
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:4079
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:838
bool replace
Definition: parsenodes.h:2673
#define PG_FINALLY()
Definition: elog.h:330
bool canSetTag
Definition: plannodes.h:54
void EventTriggerUndoInhibitCommandCollection(void)
uintptr_t Datum
Definition: postgres.h:411
CmdType commandType
Definition: plannodes.h:46
void CommandCounterIncrement(void)
Definition: xact.c:1021
ObjectAddress DefineRange(ParseState *pstate, CreateRangeStmt *stmt)
Definition: typecmds.c:1336
bool unique
Definition: parsenodes.h:2891
ObjectType kind
Definition: parsenodes.h:2667
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:2669
#define ereport(elevel,...)
Definition: elog.h:157
#define NOTICE
Definition: elog.h:37
ObjectAddress CreateCast(CreateCastStmt *stmt)
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:2961
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:495
#define makeNode(_type_)
Definition: nodes.h:587
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:391
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
ObjectAddress CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt, bool isTopLevel)
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:13983
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:544
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:2819
bool concurrent
Definition: parsenodes.h:2897
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:256
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
const ObjectAddress InvalidObjectAddress
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
Definition: foreigncmds.c:1471
int errmsg(const char *fmt,...)
Definition: elog.c:909
RangeVar * relation
Definition: parsenodes.h:1859
void list_free(List *list)
Definition: list.c:1391
#define elog(elevel,...)
Definition: elog.h:232
ObjectAddress AlterCollation(AlterCollationStmt *stmt)
#define ShareLock
Definition: lockdefs.h:41
ObjectAddress DefineTSTemplate(List *names, List *parameters)
Definition: tsearchcmds.c:684
bool if_not_exists
Definition: parsenodes.h:2672
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:156
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:43
List * definition
Definition: parsenodes.h:2671
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define PG_TRY()
Definition: elog.h:313
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 AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
bool oldstyle
Definition: parsenodes.h:2668
#define PG_END_TRY()
Definition: elog.h:338
#define lfirst_oid(lc)
Definition: pg_list.h:171
List * list_delete_first(List *list)
Definition: list.c:875
bool EventTriggerBeginCompleteQuery(void)
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:360
void EventTriggerAlterTableEnd(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:64

◆ standard_ProcessUtility()

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

Definition at line 544 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, copyObject, 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().

552 {
553  Node *parsetree;
554  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
555  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
556  ParseState *pstate;
557  int readonly_flags;
558 
559  /* This can recurse, so check for excessive recursion */
561 
562  /*
563  * If the given node tree is read-only, make a copy to ensure that parse
564  * transformations don't damage the original tree. This could be
565  * refactored to avoid making unnecessary copies in more cases, but it's
566  * not clear that it's worth a great deal of trouble over. Statements
567  * that are complex enough to be expensive to copy are exactly the ones
568  * we'd need to copy, so that only marginal savings seem possible.
569  */
570  if (readOnlyTree)
571  pstmt = copyObject(pstmt);
572  parsetree = pstmt->utilityStmt;
573 
574  /* Prohibit read/write commands in read-only states. */
575  readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
576  if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
578  {
579  CommandTag commandtag = CreateCommandTag(parsetree);
580 
581  if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
583  if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
585  if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
587  }
588 
589  pstate = make_parsestate(NULL);
590  pstate->p_sourcetext = queryString;
591  pstate->p_queryEnv = queryEnv;
592 
593  switch (nodeTag(parsetree))
594  {
595  /*
596  * ******************** transactions ********************
597  */
598  case T_TransactionStmt:
599  {
600  TransactionStmt *stmt = (TransactionStmt *) parsetree;
601 
602  switch (stmt->kind)
603  {
604  /*
605  * START TRANSACTION, as defined by SQL99: Identical
606  * to BEGIN. Same code for both.
607  */
608  case TRANS_STMT_BEGIN:
609  case TRANS_STMT_START:
610  {
611  ListCell *lc;
612 
614  foreach(lc, stmt->options)
615  {
616  DefElem *item = (DefElem *) lfirst(lc);
617 
618  if (strcmp(item->defname, "transaction_isolation") == 0)
619  SetPGVariable("transaction_isolation",
620  list_make1(item->arg),
621  true);
622  else if (strcmp(item->defname, "transaction_read_only") == 0)
623  SetPGVariable("transaction_read_only",
624  list_make1(item->arg),
625  true);
626  else if (strcmp(item->defname, "transaction_deferrable") == 0)
627  SetPGVariable("transaction_deferrable",
628  list_make1(item->arg),
629  true);
630  }
631  }
632  break;
633 
634  case TRANS_STMT_COMMIT:
635  if (!EndTransactionBlock(stmt->chain))
636  {
637  /* report unsuccessful commit in qc */
638  if (qc)
639  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
640  }
641  break;
642 
643  case TRANS_STMT_PREPARE:
644  if (!PrepareTransactionBlock(stmt->gid))
645  {
646  /* report unsuccessful commit in qc */
647  if (qc)
648  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
649  }
650  break;
651 
653  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
654  FinishPreparedTransaction(stmt->gid, true);
655  break;
656 
658  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
659  FinishPreparedTransaction(stmt->gid, false);
660  break;
661 
662  case TRANS_STMT_ROLLBACK:
664  break;
665 
667  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
669  break;
670 
671  case TRANS_STMT_RELEASE:
672  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
674  break;
675 
677  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
679 
680  /*
681  * CommitTransactionCommand is in charge of
682  * re-defining the savepoint again
683  */
684  break;
685  }
686  }
687  break;
688 
689  /*
690  * Portal (cursor) manipulation
691  */
692  case T_DeclareCursorStmt:
693  PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
694  isTopLevel);
695  break;
696 
697  case T_ClosePortalStmt:
698  {
699  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
700 
701  CheckRestrictedOperation("CLOSE");
703  }
704  break;
705 
706  case T_FetchStmt:
707  PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
708  break;
709 
710  case T_DoStmt:
711  ExecuteDoStmt(pstate, (DoStmt *) parsetree, isAtomicContext);
712  break;
713 
715  /* no event triggers for global objects */
716  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
717  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
718  break;
719 
721  /* no event triggers for global objects */
722  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
723  DropTableSpace((DropTableSpaceStmt *) parsetree);
724  break;
725 
727  /* no event triggers for global objects */
729  break;
730 
731  case T_TruncateStmt:
732  ExecuteTruncate((TruncateStmt *) parsetree);
733  break;
734 
735  case T_CopyStmt:
736  {
737  uint64 processed;
738 
739  DoCopy(pstate, (CopyStmt *) parsetree,
740  pstmt->stmt_location, pstmt->stmt_len,
741  &processed);
742  if (qc)
743  SetQueryCompletion(qc, CMDTAG_COPY, processed);
744  }
745  break;
746 
747  case T_PrepareStmt:
748  CheckRestrictedOperation("PREPARE");
749  PrepareQuery(pstate, (PrepareStmt *) parsetree,
750  pstmt->stmt_location, pstmt->stmt_len);
751  break;
752 
753  case T_ExecuteStmt:
754  ExecuteQuery(pstate,
755  (ExecuteStmt *) parsetree, NULL,
756  params,
757  dest, qc);
758  break;
759 
760  case T_DeallocateStmt:
761  CheckRestrictedOperation("DEALLOCATE");
762  DeallocateQuery((DeallocateStmt *) parsetree);
763  break;
764 
765  case T_GrantRoleStmt:
766  /* no event triggers for global objects */
767  GrantRole((GrantRoleStmt *) parsetree);
768  break;
769 
770  case T_CreatedbStmt:
771  /* no event triggers for global objects */
772  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
773  createdb(pstate, (CreatedbStmt *) parsetree);
774  break;
775 
776  case T_AlterDatabaseStmt:
777  /* no event triggers for global objects */
778  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
779  break;
780 
782  /* no event triggers for global objects */
783  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
784  break;
785 
786  case T_DropdbStmt:
787  /* no event triggers for global objects */
788  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
789  DropDatabase(pstate, (DropdbStmt *) parsetree);
790  break;
791 
792  /* Query-level asynchronous notification */
793  case T_NotifyStmt:
794  {
795  NotifyStmt *stmt = (NotifyStmt *) parsetree;
796 
797  Async_Notify(stmt->conditionname, stmt->payload);
798  }
799  break;
800 
801  case T_ListenStmt:
802  {
803  ListenStmt *stmt = (ListenStmt *) parsetree;
804 
805  CheckRestrictedOperation("LISTEN");
807  }
808  break;
809 
810  case T_UnlistenStmt:
811  {
812  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
813 
814  CheckRestrictedOperation("UNLISTEN");
815  if (stmt->conditionname)
817  else
819  }
820  break;
821 
822  case T_LoadStmt:
823  {
824  LoadStmt *stmt = (LoadStmt *) parsetree;
825 
826  closeAllVfds(); /* probably not necessary... */
827  /* Allowed names are restricted if you're not superuser */
828  load_file(stmt->filename, !superuser());
829  }
830  break;
831 
832  case T_CallStmt:
833  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
834  break;
835 
836  case T_ClusterStmt:
837  cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
838  break;
839 
840  case T_VacuumStmt:
841  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
842  break;
843 
844  case T_ExplainStmt:
845  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
846  break;
847 
848  case T_AlterSystemStmt:
849  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
851  break;
852 
853  case T_VariableSetStmt:
854  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
855  break;
856 
857  case T_VariableShowStmt:
858  {
859  VariableShowStmt *n = (VariableShowStmt *) parsetree;
860 
861  GetPGVariable(n->name, dest);
862  }
863  break;
864 
865  case T_DiscardStmt:
866  /* should we allow DISCARD PLANS? */
867  CheckRestrictedOperation("DISCARD");
868  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
869  break;
870 
872  /* no event triggers on event triggers */
874  break;
875 
877  /* no event triggers on event triggers */
878  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
879  break;
880 
881  /*
882  * ******************************** ROLE statements ****
883  */
884  case T_CreateRoleStmt:
885  /* no event triggers for global objects */
886  CreateRole(pstate, (CreateRoleStmt *) parsetree);
887  break;
888 
889  case T_AlterRoleStmt:
890  /* no event triggers for global objects */
891  AlterRole(pstate, (AlterRoleStmt *) parsetree);
892  break;
893 
894  case T_AlterRoleSetStmt:
895  /* no event triggers for global objects */
896  AlterRoleSet((AlterRoleSetStmt *) parsetree);
897  break;
898 
899  case T_DropRoleStmt:
900  /* no event triggers for global objects */
901  DropRole((DropRoleStmt *) parsetree);
902  break;
903 
904  case T_ReassignOwnedStmt:
905  /* no event triggers for global objects */
907  break;
908 
909  case T_LockStmt:
910 
911  /*
912  * Since the lock would just get dropped immediately, LOCK TABLE
913  * outside a transaction block is presumed to be user error.
914  */
915  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
916  LockTableCommand((LockStmt *) parsetree);
917  break;
918 
920  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
922  break;
923 
924  case T_CheckPointStmt:
925  if (!superuser())
926  ereport(ERROR,
927  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
928  errmsg("must be superuser to do CHECKPOINT")));
929 
932  break;
933 
934  case T_ReindexStmt:
935  ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
936  break;
937 
938  /*
939  * The following statements are supported by Event Triggers only
940  * in some cases, so we "fast path" them in the other cases.
941  */
942 
943  case T_GrantStmt:
944  {
945  GrantStmt *stmt = (GrantStmt *) parsetree;
946 
948  ProcessUtilitySlow(pstate, pstmt, queryString,
949  context, params, queryEnv,
950  dest, qc);
951  else
952  ExecuteGrantStmt(stmt);
953  }
954  break;
955 
956  case T_DropStmt:
957  {
958  DropStmt *stmt = (DropStmt *) parsetree;
959 
961  ProcessUtilitySlow(pstate, pstmt, queryString,
962  context, params, queryEnv,
963  dest, qc);
964  else
965  ExecDropStmt(stmt, isTopLevel);
966  }
967  break;
968 
969  case T_RenameStmt:
970  {
971  RenameStmt *stmt = (RenameStmt *) parsetree;
972 
974  ProcessUtilitySlow(pstate, pstmt, queryString,
975  context, params, queryEnv,
976  dest, qc);
977  else
978  ExecRenameStmt(stmt);
979  }
980  break;
981 
983  {
984  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
985 
987  ProcessUtilitySlow(pstate, pstmt, queryString,
988  context, params, queryEnv,
989  dest, qc);
990  else
991  ExecAlterObjectDependsStmt(stmt, NULL);
992  }
993  break;
994 
996  {
997  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
998 
1000  ProcessUtilitySlow(pstate, pstmt, queryString,
1001  context, params, queryEnv,
1002  dest, qc);
1003  else
1004  ExecAlterObjectSchemaStmt(stmt, NULL);
1005  }
1006  break;
1007 
1008  case T_AlterOwnerStmt:
1009  {
1010  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1011 
1013  ProcessUtilitySlow(pstate, pstmt, queryString,
1014  context, params, queryEnv,
1015  dest, qc);
1016  else
1017  ExecAlterOwnerStmt(stmt);
1018  }
1019  break;
1020 
1021  case T_CommentStmt:
1022  {
1023  CommentStmt *stmt = (CommentStmt *) parsetree;
1024 
1026  ProcessUtilitySlow(pstate, pstmt, queryString,
1027  context, params, queryEnv,
1028  dest, qc);
1029  else
1030  CommentObject(stmt);
1031  break;
1032  }
1033 
1034  case T_SecLabelStmt:
1035  {
1036  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1037 
1039  ProcessUtilitySlow(pstate, pstmt, queryString,
1040  context, params, queryEnv,
1041  dest, qc);
1042  else
1043  ExecSecLabelStmt(stmt);
1044  break;
1045  }
1046 
1047  default:
1048  /* All other statement types have event trigger support */
1049  ProcessUtilitySlow(pstate, pstmt, queryString,
1050  context, params, queryEnv,
1051  dest, qc);
1052  break;
1053  }
1054 
1055  free_parsestate(pstate);
1056 
1057  /*
1058  * Make effects of commands visible, for instance so that
1059  * PreCommit_on_commit_actions() can see them (see for example bug
1060  * #15631).
1061  */
1063 }
ObjectType objtype
Definition: parsenodes.h:2779
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:164</