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/namespace.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/collationcmds.h"
#include "commands/comment.h"
#include "commands/conversioncmds.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/discard.h"
#include "commands/event_trigger.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/lockcmds.h"
#include "commands/matview.h"
#include "commands/policy.h"
#include "commands/portalcmds.h"
#include "commands/prepare.h"
#include "commands/proclang.h"
#include "commands/publicationcmds.h"
#include "commands/schemacmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/subscriptioncmds.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/view.h"
#include "miscadmin.h"
#include "parser/parse_utilcmd.h"
#include "postmaster/bgwriter.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteRemove.h"
#include "storage/fd.h"
#include "tcop/pquery.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

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

Variables

ProcessUtility_hook_type ProcessUtility_hook = NULL
 

Function Documentation

◆ AlterObjectTypeCommandTag()

static CommandTag AlterObjectTypeCommandTag ( ObjectType  objtype)
static

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

2142 {
2143  CommandTag tag;
2144 
2145  switch (objtype)
2146  {
2147  case OBJECT_AGGREGATE:
2148  tag = CMDTAG_ALTER_AGGREGATE;
2149  break;
2150  case OBJECT_ATTRIBUTE:
2151  tag = CMDTAG_ALTER_TYPE;
2152  break;
2153  case OBJECT_CAST:
2154  tag = CMDTAG_ALTER_CAST;
2155  break;
2156  case OBJECT_COLLATION:
2157  tag = CMDTAG_ALTER_COLLATION;
2158  break;
2159  case OBJECT_COLUMN:
2160  tag = CMDTAG_ALTER_TABLE;
2161  break;
2162  case OBJECT_CONVERSION:
2163  tag = CMDTAG_ALTER_CONVERSION;
2164  break;
2165  case OBJECT_DATABASE:
2166  tag = CMDTAG_ALTER_DATABASE;
2167  break;
2168  case OBJECT_DOMAIN:
2169  case OBJECT_DOMCONSTRAINT:
2170  tag = CMDTAG_ALTER_DOMAIN;
2171  break;
2172  case OBJECT_EXTENSION:
2173  tag = CMDTAG_ALTER_EXTENSION;
2174  break;
2175  case OBJECT_FDW:
2176  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2177  break;
2178  case OBJECT_FOREIGN_SERVER:
2179  tag = CMDTAG_ALTER_SERVER;
2180  break;
2181  case OBJECT_FOREIGN_TABLE:
2182  tag = CMDTAG_ALTER_FOREIGN_TABLE;
2183  break;
2184  case OBJECT_FUNCTION:
2185  tag = CMDTAG_ALTER_FUNCTION;
2186  break;
2187  case OBJECT_INDEX:
2188  tag = CMDTAG_ALTER_INDEX;
2189  break;
2190  case OBJECT_LANGUAGE:
2191  tag = CMDTAG_ALTER_LANGUAGE;
2192  break;
2193  case OBJECT_LARGEOBJECT:
2194  tag = CMDTAG_ALTER_LARGE_OBJECT;
2195  break;
2196  case OBJECT_OPCLASS:
2197  tag = CMDTAG_ALTER_OPERATOR_CLASS;
2198  break;
2199  case OBJECT_OPERATOR:
2200  tag = CMDTAG_ALTER_OPERATOR;
2201  break;
2202  case OBJECT_OPFAMILY:
2203  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2204  break;
2205  case OBJECT_POLICY:
2206  tag = CMDTAG_ALTER_POLICY;
2207  break;
2208  case OBJECT_PROCEDURE:
2209  tag = CMDTAG_ALTER_PROCEDURE;
2210  break;
2211  case OBJECT_ROLE:
2212  tag = CMDTAG_ALTER_ROLE;
2213  break;
2214  case OBJECT_ROUTINE:
2215  tag = CMDTAG_ALTER_ROUTINE;
2216  break;
2217  case OBJECT_RULE:
2218  tag = CMDTAG_ALTER_RULE;
2219  break;
2220  case OBJECT_SCHEMA:
2221  tag = CMDTAG_ALTER_SCHEMA;
2222  break;
2223  case OBJECT_SEQUENCE:
2224  tag = CMDTAG_ALTER_SEQUENCE;
2225  break;
2226  case OBJECT_TABLE:
2227  case OBJECT_TABCONSTRAINT:
2228  tag = CMDTAG_ALTER_TABLE;
2229  break;
2230  case OBJECT_TABLESPACE:
2231  tag = CMDTAG_ALTER_TABLESPACE;
2232  break;
2233  case OBJECT_TRIGGER:
2234  tag = CMDTAG_ALTER_TRIGGER;
2235  break;
2236  case OBJECT_EVENT_TRIGGER:
2237  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2238  break;
2240  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2241  break;
2242  case OBJECT_TSDICTIONARY:
2243  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2244  break;
2245  case OBJECT_TSPARSER:
2246  tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2247  break;
2248  case OBJECT_TSTEMPLATE:
2249  tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2250  break;
2251  case OBJECT_TYPE:
2252  tag = CMDTAG_ALTER_TYPE;
2253  break;
2254  case OBJECT_VIEW:
2255  tag = CMDTAG_ALTER_VIEW;
2256  break;
2257  case OBJECT_MATVIEW:
2258  tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2259  break;
2260  case OBJECT_PUBLICATION:
2261  tag = CMDTAG_ALTER_PUBLICATION;
2262  break;
2263  case OBJECT_SUBSCRIPTION:
2264  tag = CMDTAG_ALTER_SUBSCRIPTION;
2265  break;
2266  case OBJECT_STATISTIC_EXT:
2267  tag = CMDTAG_ALTER_STATISTICS;
2268  break;
2269  default:
2270  tag = CMDTAG_UNKNOWN;
2271  break;
2272  }
2273 
2274  return tag;
2275 }
CommandTag
Definition: cmdtag.h:20

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 462 of file utility.c.

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

Referenced by standard_ProcessUtility().

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

◆ ClassifyUtilityCommandAsReadOnly()

static int ClassifyUtilityCommandAsReadOnly ( Node parsetree)
static

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

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

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

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

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

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2287 of file utility.c.

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

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

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

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

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

1922 {
1923  switch (stmt->removeType)
1924  {
1925  case OBJECT_INDEX:
1926  if (stmt->concurrent)
1927  PreventInTransactionBlock(isTopLevel,
1928  "DROP INDEX CONCURRENTLY");
1929  /* fall through */
1930 
1931  case OBJECT_TABLE:
1932  case OBJECT_SEQUENCE:
1933  case OBJECT_VIEW:
1934  case OBJECT_MATVIEW:
1935  case OBJECT_FOREIGN_TABLE:
1936  RemoveRelations(stmt);
1937  break;
1938  default:
1939  RemoveObjects(stmt);
1940  break;
1941  }
1942 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:57
ObjectType removeType
Definition: parsenodes.h:2653
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1260
bool concurrent
Definition: parsenodes.h:2656
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3381

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3158 of file utility.c.

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

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

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 444 of file utility.c.

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

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

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

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 425 of file utility.c.

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

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

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

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 407 of file utility.c.

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

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

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

◆ ProcessUtility()

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

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

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

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

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

1887 {
1888  PlannedStmt *wrapper;
1889 
1890  /*
1891  * For event triggers, we must "close" the current complex-command set,
1892  * and start a new one afterwards; this is needed to ensure the ordering
1893  * of command events is consistent with the way they were executed.
1894  */
1896 
1897  /* Create a suitable wrapper */
1898  wrapper = makeNode(PlannedStmt);
1899  wrapper->commandType = CMD_UTILITY;
1900  wrapper->canSetTag = false;
1901  wrapper->utilityStmt = stmt;
1902  wrapper->stmt_location = context->pstmt->stmt_location;
1903  wrapper->stmt_len = context->pstmt->stmt_len;
1904 
1905  ProcessUtility(wrapper,
1906  context->queryString,
1908  context->params,
1909  context->queryEnv,
1910  None_Receiver,
1911  NULL);
1912 
1915 }
PlannedStmt * pstmt
Definition: utility.h:32
DestReceiver * None_Receiver
Definition: dest.c:96
int stmt_len
Definition: plannodes.h:90
void EventTriggerAlterTableStart(Node *parsetree)
int stmt_location
Definition: plannodes.h:89
Node * utilityStmt
Definition: plannodes.h:86
const char * queryString
Definition: utility.h:33
QueryEnvironment * queryEnv
Definition: utility.h:36
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define makeNode(_type_)
Definition: nodes.h:575
void EventTriggerAlterTableRelid(Oid objectId)
ParamListInfo params
Definition: utility.h:35
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:501
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 1093 of file utility.c.

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

Referenced by standard_ProcessUtility().

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

◆ standard_ProcessUtility()

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

Definition at line 541 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, TransactionStmt::chain, check_stack_depth(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), ClassifyUtilityCommandAsReadOnly(), closeAllVfds(), cluster(), COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_PARALLEL_MODE, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, CommandCounterIncrement(), CommentObject(), NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetCommandTagName(), GetPGVariable(), TransactionStmt::gid, GrantRole(), IsInParallelMode(), IsTransactionBlock(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), VariableShowStmt::name, ReindexStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ReindexStmt::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(), REINDEX_OBJECT_DATABASE, REINDEX_OBJECT_INDEX, REINDEX_OBJECT_SCHEMA, REINDEX_OBJECT_SYSTEM, REINDEX_OBJECT_TABLE, ReindexIndex(), ReindexMultipleTables(), REINDEXOPT_CONCURRENTLY, ReindexTable(), ReindexStmt::relation, 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().

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