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

Go to the source code of this file.

Functions

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

Variables

ProcessUtility_hook_type ProcessUtility_hook = NULL
 

Function Documentation

◆ AlterObjectTypeCommandTag()

static CommandTag AlterObjectTypeCommandTag ( ObjectType  objtype)
static

Definition at line 2192 of file utility.c.

2193 {
2194  CommandTag tag;
2195 
2196  switch (objtype)
2197  {
2198  case OBJECT_AGGREGATE:
2199  tag = CMDTAG_ALTER_AGGREGATE;
2200  break;
2201  case OBJECT_ATTRIBUTE:
2202  tag = CMDTAG_ALTER_TYPE;
2203  break;
2204  case OBJECT_CAST:
2205  tag = CMDTAG_ALTER_CAST;
2206  break;
2207  case OBJECT_COLLATION:
2208  tag = CMDTAG_ALTER_COLLATION;
2209  break;
2210  case OBJECT_COLUMN:
2211  tag = CMDTAG_ALTER_TABLE;
2212  break;
2213  case OBJECT_CONVERSION:
2214  tag = CMDTAG_ALTER_CONVERSION;
2215  break;
2216  case OBJECT_DATABASE:
2217  tag = CMDTAG_ALTER_DATABASE;
2218  break;
2219  case OBJECT_DOMAIN:
2220  case OBJECT_DOMCONSTRAINT:
2221  tag = CMDTAG_ALTER_DOMAIN;
2222  break;
2223  case OBJECT_EXTENSION:
2224  tag = CMDTAG_ALTER_EXTENSION;
2225  break;
2226  case OBJECT_FDW:
2227  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2228  break;
2229  case OBJECT_FOREIGN_SERVER:
2230  tag = CMDTAG_ALTER_SERVER;
2231  break;
2232  case OBJECT_FOREIGN_TABLE:
2233  tag = CMDTAG_ALTER_FOREIGN_TABLE;
2234  break;
2235  case OBJECT_FUNCTION:
2236  tag = CMDTAG_ALTER_FUNCTION;
2237  break;
2238  case OBJECT_INDEX:
2239  tag = CMDTAG_ALTER_INDEX;
2240  break;
2241  case OBJECT_LANGUAGE:
2242  tag = CMDTAG_ALTER_LANGUAGE;
2243  break;
2244  case OBJECT_LARGEOBJECT:
2245  tag = CMDTAG_ALTER_LARGE_OBJECT;
2246  break;
2247  case OBJECT_OPCLASS:
2248  tag = CMDTAG_ALTER_OPERATOR_CLASS;
2249  break;
2250  case OBJECT_OPERATOR:
2251  tag = CMDTAG_ALTER_OPERATOR;
2252  break;
2253  case OBJECT_OPFAMILY:
2254  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2255  break;
2256  case OBJECT_POLICY:
2257  tag = CMDTAG_ALTER_POLICY;
2258  break;
2259  case OBJECT_PROCEDURE:
2260  tag = CMDTAG_ALTER_PROCEDURE;
2261  break;
2262  case OBJECT_ROLE:
2263  tag = CMDTAG_ALTER_ROLE;
2264  break;
2265  case OBJECT_ROUTINE:
2266  tag = CMDTAG_ALTER_ROUTINE;
2267  break;
2268  case OBJECT_RULE:
2269  tag = CMDTAG_ALTER_RULE;
2270  break;
2271  case OBJECT_SCHEMA:
2272  tag = CMDTAG_ALTER_SCHEMA;
2273  break;
2274  case OBJECT_SEQUENCE:
2275  tag = CMDTAG_ALTER_SEQUENCE;
2276  break;
2277  case OBJECT_TABLE:
2278  case OBJECT_TABCONSTRAINT:
2279  tag = CMDTAG_ALTER_TABLE;
2280  break;
2281  case OBJECT_TABLESPACE:
2282  tag = CMDTAG_ALTER_TABLESPACE;
2283  break;
2284  case OBJECT_TRIGGER:
2285  tag = CMDTAG_ALTER_TRIGGER;
2286  break;
2287  case OBJECT_EVENT_TRIGGER:
2288  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2289  break;
2291  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2292  break;
2293  case OBJECT_TSDICTIONARY:
2294  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2295  break;
2296  case OBJECT_TSPARSER:
2297  tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2298  break;
2299  case OBJECT_TSTEMPLATE:
2300  tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2301  break;
2302  case OBJECT_TYPE:
2303  tag = CMDTAG_ALTER_TYPE;
2304  break;
2305  case OBJECT_VIEW:
2306  tag = CMDTAG_ALTER_VIEW;
2307  break;
2308  case OBJECT_MATVIEW:
2309  tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2310  break;
2311  case OBJECT_PUBLICATION:
2312  tag = CMDTAG_ALTER_PUBLICATION;
2313  break;
2314  case OBJECT_SUBSCRIPTION:
2315  tag = CMDTAG_ALTER_SUBSCRIPTION;
2316  break;
2317  case OBJECT_STATISTIC_EXT:
2318  tag = CMDTAG_ALTER_STATISTICS;
2319  break;
2320  default:
2321  tag = CMDTAG_UNKNOWN;
2322  break;
2323  }
2324 
2325  return tag;
2326 }
CommandTag
Definition: cmdtag.h:21
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1803
@ OBJECT_FDW
Definition: parsenodes.h:1805
@ OBJECT_TSPARSER
Definition: parsenodes.h:1835
@ OBJECT_COLLATION
Definition: parsenodes.h:1796
@ OBJECT_OPCLASS
Definition: parsenodes.h:1813
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1790
@ OBJECT_MATVIEW
Definition: parsenodes.h:1812
@ OBJECT_SCHEMA
Definition: parsenodes.h:1824
@ OBJECT_POLICY
Definition: parsenodes.h:1816
@ OBJECT_OPERATOR
Definition: parsenodes.h:1814
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1807
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:1833
@ OBJECT_OPFAMILY
Definition: parsenodes.h:1815
@ OBJECT_DOMAIN
Definition: parsenodes.h:1801
@ OBJECT_COLUMN
Definition: parsenodes.h:1795
@ OBJECT_TABLESPACE
Definition: parsenodes.h:1830
@ OBJECT_ROLE
Definition: parsenodes.h:1821
@ OBJECT_ROUTINE
Definition: parsenodes.h:1822
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1811
@ OBJECT_PROCEDURE
Definition: parsenodes.h:1817
@ OBJECT_EXTENSION
Definition: parsenodes.h:1804
@ OBJECT_INDEX
Definition: parsenodes.h:1809
@ OBJECT_DATABASE
Definition: parsenodes.h:1798
@ OBJECT_SEQUENCE
Definition: parsenodes.h:1825
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:1836
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1810
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1806
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:1834
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1793
@ OBJECT_PUBLICATION
Definition: parsenodes.h:1818
@ OBJECT_RULE
Definition: parsenodes.h:1823
@ OBJECT_CONVERSION
Definition: parsenodes.h:1797
@ OBJECT_TABLE
Definition: parsenodes.h:1829
@ OBJECT_VIEW
Definition: parsenodes.h:1839
@ OBJECT_TYPE
Definition: parsenodes.h:1837
@ OBJECT_FUNCTION
Definition: parsenodes.h:1808
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:1828
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1802
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:1826
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:1827
@ OBJECT_CAST
Definition: parsenodes.h:1794
@ OBJECT_TRIGGER
Definition: parsenodes.h:1832

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().

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 464 of file utility.c.

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

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

Referenced by standard_ProcessUtility().

◆ ClassifyUtilityCommandAsReadOnly()

static int ClassifyUtilityCommandAsReadOnly ( Node parsetree)
static

Definition at line 134 of file utility.c.

135 {
136  switch (nodeTag(parsetree))
137  {
140  case T_AlterDatabaseStmt:
142  case T_AlterDomainStmt:
143  case T_AlterEnumStmt:
147  case T_AlterFdwStmt:
149  case T_AlterFunctionStmt:
152  case T_AlterOpFamilyStmt:
153  case T_AlterOperatorStmt:
154  case T_AlterOwnerStmt:
155  case T_AlterPolicyStmt:
157  case T_AlterRoleSetStmt:
158  case T_AlterRoleStmt:
159  case T_AlterSeqStmt:
160  case T_AlterStatsStmt:
166  case T_AlterTableStmt:
167  case T_AlterTypeStmt:
169  case T_CommentStmt:
170  case T_CompositeTypeStmt:
171  case T_CreateAmStmt:
172  case T_CreateCastStmt:
174  case T_CreateDomainStmt:
175  case T_CreateEnumStmt:
178  case T_CreateFdwStmt:
182  case T_CreateOpClassStmt:
184  case T_CreatePLangStmt:
185  case T_CreatePolicyStmt:
187  case T_CreateRangeStmt:
188  case T_CreateRoleStmt:
189  case T_CreateSchemaStmt:
190  case T_CreateSeqStmt:
191  case T_CreateStatsStmt:
192  case T_CreateStmt:
194  case T_CreateTableAsStmt:
197  case T_CreateTrigStmt:
199  case T_CreatedbStmt:
200  case T_DefineStmt:
201  case T_DropOwnedStmt:
202  case T_DropRoleStmt:
203  case T_DropStmt:
207  case T_DropdbStmt:
208  case T_GrantRoleStmt:
209  case T_GrantStmt:
211  case T_IndexStmt:
212  case T_ReassignOwnedStmt:
214  case T_RenameStmt:
215  case T_RuleStmt:
216  case T_SecLabelStmt:
217  case T_TruncateStmt:
218  case T_ViewStmt:
219  {
220  /* DDL is not read-only, and neither is TRUNCATE. */
222  }
223 
224  case T_AlterSystemStmt:
225  {
226  /*
227  * Surprisingly, ALTER SYSTEM meets all our definitions of
228  * read-only: it changes nothing that affects the output of
229  * pg_dump, it doesn't write WAL or imperil the application of
230  * future WAL, and it doesn't depend on any state that needs
231  * to be synchronized with parallel workers.
232  *
233  * So, despite the fact that it writes to a file, it's read
234  * only!
235  */
237  }
238 
239  case T_CallStmt:
240  case T_DoStmt:
241  {
242  /*
243  * Commands inside the DO block or the called procedure might
244  * not be read only, but they'll be checked separately when we
245  * try to execute them. Here we only need to worry about the
246  * DO or CALL command itself.
247  */
249  }
250 
251  case T_CheckPointStmt:
252  {
253  /*
254  * You might think that this should not be permitted in
255  * recovery, but we interpret a CHECKPOINT command during
256  * recovery as a request for a restartpoint instead. We allow
257  * this since it can be a useful way of reducing switchover
258  * time when using various forms of replication.
259  */
261  }
262 
263  case T_ClosePortalStmt:
265  case T_DeallocateStmt:
266  case T_DeclareCursorStmt:
267  case T_DiscardStmt:
268  case T_ExecuteStmt:
269  case T_FetchStmt:
270  case T_LoadStmt:
271  case T_PrepareStmt:
272  case T_UnlistenStmt:
273  case T_VariableSetStmt:
274  {
275  /*
276  * These modify only backend-local state, so they're OK to run
277  * in a read-only transaction or on a standby. However, they
278  * are disallowed in parallel mode, because they either rely
279  * upon or modify backend-local state that might not be
280  * synchronized among cooperating backends.
281  */
283  }
284 
285  case T_ClusterStmt:
286  case T_ReindexStmt:
287  case T_VacuumStmt:
288  {
289  /*
290  * These commands write WAL, so they're not strictly
291  * read-only, and running them in parallel workers isn't
292  * supported.
293  *
294  * However, they don't change the database state in a way that
295  * would affect pg_dump output, so it's fine to run them in a
296  * read-only transaction. (CLUSTER might change the order of
297  * rows on disk, which could affect the ordering of pg_dump
298  * output, but that's not semantically significant.)
299  */
301  }
302 
303  case T_CopyStmt:
304  {
305  CopyStmt *stmt = (CopyStmt *) parsetree;
306 
307  /*
308  * You might think that COPY FROM is not at all read only, but
309  * it's OK to copy into a temporary table, because that
310  * wouldn't change the output of pg_dump. If the target table
311  * turns out to be non-temporary, DoCopy itself will call
312  * PreventCommandIfReadOnly.
313  */
314  if (stmt->is_from)
316  else
318  }
319 
320  case T_ExplainStmt:
321  case T_VariableShowStmt:
322  {
323  /*
324  * These commands don't modify any data and are safe to run in
325  * a parallel worker.
326  */
328  }
329 
330  case T_ListenStmt:
331  case T_NotifyStmt:
332  {
333  /*
334  * NOTIFY requires an XID assignment, so it can't be permitted
335  * on a standby. Perhaps LISTEN could, since without NOTIFY it
336  * would be OK to just do nothing, at least until promotion,
337  * but we currently prohibit it lest the user get the wrong
338  * idea.
339  *
340  * (We do allow T_UnlistenStmt on a standby, though, because
341  * it's a no-op.)
342  */
344  }
345 
346  case T_LockStmt:
347  {
348  LockStmt *stmt = (LockStmt *) parsetree;
349 
350  /*
351  * Only weaker locker modes are allowed during recovery. The
352  * restrictions here must match those in
353  * LockAcquireExtended().
354  */
355  if (stmt->mode > RowExclusiveLock)
357  else
359  }
360 
361  case T_TransactionStmt:
362  {
363  TransactionStmt *stmt = (TransactionStmt *) parsetree;
364 
365  /*
366  * PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all write
367  * WAL, so they're not read-only in the strict sense; but the
368  * first and third do not change pg_dump output, so they're OK
369  * in a read-only transactions.
370  *
371  * We also consider COMMIT PREPARED to be OK in a read-only
372  * transaction environment, by way of exception.
373  */
374  switch (stmt->kind)
375  {
376  case TRANS_STMT_BEGIN:
377  case TRANS_STMT_START:
378  case TRANS_STMT_COMMIT:
379  case TRANS_STMT_ROLLBACK:
381  case TRANS_STMT_RELEASE:
384 
385  case TRANS_STMT_PREPARE:
389  }
390  elog(ERROR, "unrecognized TransactionStmtKind: %d",
391  (int) stmt->kind);
392  return 0; /* silence stupider compilers */
393  }
394 
395  default:
396  elog(ERROR, "unrecognized node type: %d",
397  (int) nodeTag(parsetree));
398  return 0; /* silence stupider compilers */
399  }
400 }
#define elog(elevel,...)
Definition: elog.h:218
#define RowExclusiveLock
Definition: lockdefs.h:38
#define nodeTag(nodeptr)
Definition: nodes.h:544
@ T_AlterPublicationStmt
Definition: nodes.h:424
@ T_CreateSchemaStmt
Definition: nodes.h:371
@ T_RuleStmt
Definition: nodes.h:344
@ T_CreateRoleStmt
Definition: nodes.h:364
@ T_DoStmt
Definition: nodes.h:342
@ T_CreateStmt
Definition: nodes.h:333
@ T_LoadStmt
Definition: nodes.h:350
@ T_CreateTrigStmt
Definition: nodes.h:362
@ T_ReindexStmt
Definition: nodes.h:369
@ T_AlterEnumStmt
Definition: nodes.h:396
@ T_ExecuteStmt
Definition: nodes.h:381
@ T_CreateFdwStmt
Definition: nodes.h:399
@ T_RenameStmt
Definition: nodes.h:343
@ T_CreateEventTrigStmt
Definition: nodes.h:414
@ T_DiscardStmt
Definition: nodes.h:361
@ T_ImportForeignSchemaStmt
Definition: nodes.h:410
@ T_VacuumStmt
Definition: nodes.h:354
@ T_AlterOperatorStmt
Definition: nodes.h:389
@ T_CreateTableSpaceStmt
Definition: nodes.h:384
@ T_DropRoleStmt
Definition: nodes.h:366
@ T_AlterTableSpaceOptionsStmt
Definition: nodes.h:406
@ T_AlterCollationStmt
Definition: nodes.h:429
@ T_CreateStatsStmt
Definition: nodes.h:428
@ T_CreateFunctionStmt
Definition: nodes.h:340
@ T_AlterDatabaseStmt
Definition: nodes.h:372
@ T_CreateSubscriptionStmt
Definition: nodes.h:425
@ T_AlterRoleStmt
Definition: nodes.h:365
@ T_CreatePublicationStmt
Definition: nodes.h:423
@ T_CreateForeignTableStmt
Definition: nodes.h:409
@ T_AlterObjectDependsStmt
Definition: nodes.h:386
@ T_CreateRangeStmt
Definition: nodes.h:395
@ T_CreateConversionStmt
Definition: nodes.h:375
@ T_ClusterStmt
Definition: nodes.h:331
@ T_DropOwnedStmt
Definition: nodes.h:391
@ T_DropUserMappingStmt
Definition: nodes.h:405
@ T_LockStmt
Definition: nodes.h:367
@ T_ListenStmt
Definition: nodes.h:346
@ T_PrepareStmt
Definition: nodes.h:380
@ T_ReassignOwnedStmt
Definition: nodes.h:392
@ T_AlterTypeStmt
Definition: nodes.h:390
@ T_VariableShowStmt
Definition: nodes.h:360
@ T_TruncateStmt
Definition: nodes.h:336
@ T_ExplainStmt
Definition: nodes.h:355
@ T_CheckPointStmt
Definition: nodes.h:370
@ T_DropdbStmt
Definition: nodes.h:353
@ T_NotifyStmt
Definition: nodes.h:345
@ T_CreateSeqStmt
Definition: nodes.h:357
@ T_AlterForeignServerStmt
Definition: nodes.h:402
@ T_CreateEnumStmt
Definition: nodes.h:394
@ T_UnlistenStmt
Definition: nodes.h:347
@ T_TransactionStmt
Definition: nodes.h:348
@ T_AlterExtensionContentsStmt
Definition: nodes.h:413
@ T_AlterFdwStmt
Definition: nodes.h:400
@ T_AlterStatsStmt
Definition: nodes.h:431
@ T_AlterEventTrigStmt
Definition: nodes.h:415
@ T_AlterOpFamilyStmt
Definition: nodes.h:379
@ T_DropStmt
Definition: nodes.h:335
@ T_CreateTransformStmt
Definition: nodes.h:421
@ T_AlterSeqStmt
Definition: nodes.h:358
@ T_AlterFunctionStmt
Definition: nodes.h:341
@ T_IndexStmt
Definition: nodes.h:339
@ T_AlterObjectSchemaStmt
Definition: nodes.h:387
@ T_CreatePolicyStmt
Definition: nodes.h:419
@ T_AlterPolicyStmt
Definition: nodes.h:420
@ T_DropTableSpaceStmt
Definition: nodes.h:385
@ T_CompositeTypeStmt
Definition: nodes.h:393
@ T_CallStmt
Definition: nodes.h:430
@ T_CreateDomainStmt
Definition: nodes.h:351
@ T_AlterTSConfigurationStmt
Definition: nodes.h:398
@ T_GrantRoleStmt
Definition: nodes.h:328
@ T_CreateForeignServerStmt
Definition: nodes.h:401
@ T_CreateTableAsStmt
Definition: nodes.h:356
@ T_DeclareCursorStmt
Definition: nodes.h:383
@ T_DefineStmt
Definition: nodes.h:334
@ T_CreateOpFamilyStmt
Definition: nodes.h:378
@ T_FetchStmt
Definition: nodes.h:338
@ T_CreatePLangStmt
Definition: nodes.h:363
@ T_DeallocateStmt
Definition: nodes.h:382
@ T_CopyStmt
Definition: nodes.h:332
@ T_DropSubscriptionStmt
Definition: nodes.h:427
@ T_AlterExtensionStmt
Definition: nodes.h:412
@ T_CreateUserMappingStmt
Definition: nodes.h:403
@ T_AlterTSDictionaryStmt
Definition: nodes.h:397
@ T_AlterUserMappingStmt
Definition: nodes.h:404
@ T_AlterOwnerStmt
Definition: nodes.h:388
@ T_AlterSystemStmt
Definition: nodes.h:418
@ T_CreateAmStmt
Definition: nodes.h:422
@ T_AlterDomainStmt
Definition: nodes.h:325
@ T_ConstraintsSetStmt
Definition: nodes.h:368
@ T_AlterDatabaseSetStmt
Definition: nodes.h:373
@ T_CreateExtensionStmt
Definition: nodes.h:411
@ T_CreateCastStmt
Definition: nodes.h:376
@ T_RefreshMatViewStmt
Definition: nodes.h:416
@ T_GrantStmt
Definition: nodes.h:327
@ T_AlterSubscriptionStmt
Definition: nodes.h:426
@ T_CreatedbStmt
Definition: nodes.h:352
@ T_AlterDefaultPrivilegesStmt
Definition: nodes.h:329
@ T_VariableSetStmt
Definition: nodes.h:359
@ T_SecLabelStmt
Definition: nodes.h:408
@ T_AlterTableStmt
Definition: nodes.h:323
@ T_CreateOpClassStmt
Definition: nodes.h:377
@ T_ViewStmt
Definition: nodes.h:349
@ T_AlterTableMoveAllStmt
Definition: nodes.h:407
@ T_ClosePortalStmt
Definition: nodes.h:330
@ T_AlterRoleSetStmt
Definition: nodes.h:374
@ T_CommentStmt
Definition: nodes.h:337
@ TRANS_STMT_ROLLBACK_TO
Definition: parsenodes.h:3190
@ TRANS_STMT_START
Definition: parsenodes.h:3185
@ TRANS_STMT_SAVEPOINT
Definition: parsenodes.h:3188
@ TRANS_STMT_BEGIN
Definition: parsenodes.h:3184
@ TRANS_STMT_ROLLBACK
Definition: parsenodes.h:3187
@ TRANS_STMT_COMMIT_PREPARED
Definition: parsenodes.h:3192
@ TRANS_STMT_COMMIT
Definition: parsenodes.h:3186
@ TRANS_STMT_ROLLBACK_PREPARED
Definition: parsenodes.h:3193
@ TRANS_STMT_PREPARE
Definition: parsenodes.h:3191
@ TRANS_STMT_RELEASE
Definition: parsenodes.h:3189
bool is_from
Definition: parsenodes.h:2127
TransactionStmtKind kind
Definition: parsenodes.h:3199
#define COMMAND_OK_IN_RECOVERY
Definition: utility.h:58
#define COMMAND_IS_STRICTLY_READ_ONLY
Definition: utility.h:65
#define COMMAND_IS_NOT_READ_ONLY
Definition: utility.h:68
#define COMMAND_OK_IN_READ_ONLY_TXN
Definition: utility.h:56

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().

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 101 of file utility.c.

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

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(), init_execution_state(), and SPI_cursor_open_internal().

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2338 of file utility.c.

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

References AlterObjectTypeCommandTag(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, Query::commandType, PlannedStmt::commandType, 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, Query::rowMarks, PlannedStmt::rowMarks, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PLAssignStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, Query::utilityStmt, PlannedStmt::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(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), interpret_AS_clause(), PrepareQuery(), and standard_ProcessUtility().

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1972 of file utility.c.

1973 {
1974  switch (stmt->removeType)
1975  {
1976  case OBJECT_INDEX:
1977  if (stmt->concurrent)
1978  PreventInTransactionBlock(isTopLevel,
1979  "DROP INDEX CONCURRENTLY");
1980  /* fall through */
1981 
1982  case OBJECT_TABLE:
1983  case OBJECT_SEQUENCE:
1984  case OBJECT_VIEW:
1985  case OBJECT_MATVIEW:
1986  case OBJECT_FOREIGN_TABLE:
1987  RemoveRelations(stmt);
1988  break;
1989  default:
1990  RemoveObjects(stmt);
1991  break;
1992  }
1993 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:57
ObjectType removeType
Definition: parsenodes.h:2769
bool concurrent
Definition: parsenodes.h:2772
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1327
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3450

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().

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3217 of file utility.c.

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

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

Referenced by check_log_statement().

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 446 of file utility.c.

447 {
448  if (RecoveryInProgress())
449  ereport(ERROR,
450  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
451  /* translator: %s is name of a SQL command, eg CREATE */
452  errmsg("cannot execute %s during recovery",
453  cmdname)));
454 }
bool RecoveryInProgress(void)
Definition: xlog.c:8404

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

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

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 427 of file utility.c.

428 {
429  if (IsInParallelMode())
430  ereport(ERROR,
431  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
432  /* translator: %s is name of a SQL command, eg CREATE */
433  errmsg("cannot execute %s during a parallel operation",
434  cmdname)));
435 }
bool IsInParallelMode(void)
Definition: xact.c:1064

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

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

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 409 of file utility.c.

410 {
411  if (XactReadOnly)
412  ereport(ERROR,
413  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
414  /* translator: %s is name of a SQL command, eg CREATE */
415  errmsg("cannot execute %s in a read-only transaction",
416  cmdname)));
417 }
bool XactReadOnly
Definition: xact.c:80

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

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

◆ ProcessUtility()

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

Definition at line 504 of file utility.c.

512 {
513  Assert(IsA(pstmt, PlannedStmt));
514  Assert(pstmt->commandType == CMD_UTILITY);
515  Assert(queryString != NULL); /* required as of 8.4 */
516  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
517 
518  /*
519  * We provide a function hook variable that lets loadable plugins get
520  * control when ProcessUtility is called. Such a plugin would normally
521  * call standard_ProcessUtility().
522  */
524  (*ProcessUtility_hook) (pstmt, queryString, readOnlyTree,
525  context, params, queryEnv,
526  dest, qc);
527  else
528  standard_ProcessUtility(pstmt, queryString, readOnlyTree,
529  context, params, queryEnv,
530  dest, qc);
531 }
CommandTag commandTag
Definition: cmdtag.h:30
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:545
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:77

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().

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1936 of file utility.c.

1937 {
1938  PlannedStmt *wrapper;
1939 
1940  /*
1941  * For event triggers, we must "close" the current complex-command set,
1942  * and start a new one afterwards; this is needed to ensure the ordering
1943  * of command events is consistent with the way they were executed.
1944  */
1946 
1947  /* Create a suitable wrapper */
1948  wrapper = makeNode(PlannedStmt);
1949  wrapper->commandType = CMD_UTILITY;
1950  wrapper->canSetTag = false;
1951  wrapper->utilityStmt = stmt;
1952  wrapper->stmt_location = context->pstmt->stmt_location;
1953  wrapper->stmt_len = context->pstmt->stmt_len;
1954 
1955  ProcessUtility(wrapper,
1956  context->queryString,
1957  false,
1959  context->params,
1960  context->queryEnv,
1961  None_Receiver,
1962  NULL);
1963 
1966 }
DestReceiver * None_Receiver
Definition: dest.c:96
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerAlterTableEnd(void)
#define makeNode(_type_)
Definition: nodes.h:587
ParamListInfo params
Definition: utility.h:35
QueryEnvironment * queryEnv
Definition: utility.h:36
PlannedStmt * pstmt
Definition: utility.h:32
const char * queryString
Definition: utility.h:33
bool canSetTag
Definition: plannodes.h:54
int stmt_location
Definition: plannodes.h:89
int stmt_len
Definition: plannodes.h:90
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:504
@ PROCESS_UTILITY_SUBCOMMAND
Definition: utility.h:26

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().

◆ 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 1089 of file utility.c.

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

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

Referenced by standard_ProcessUtility().

◆ standard_ProcessUtility()

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

Definition at line 545 of file utility.c.

553 {
554  Node *parsetree;
555  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
556  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
557  ParseState *pstate;
558  int readonly_flags;
559 
560  /* This can recurse, so check for excessive recursion */
562 
563  /*
564  * If the given node tree is read-only, make a copy to ensure that parse
565  * transformations don't damage the original tree. This could be
566  * refactored to avoid making unnecessary copies in more cases, but it's
567  * not clear that it's worth a great deal of trouble over. Statements
568  * that are complex enough to be expensive to copy are exactly the ones
569  * we'd need to copy, so that only marginal savings seem possible.
570  */
571  if (readOnlyTree)
572  pstmt = copyObject(pstmt);
573  parsetree = pstmt->utilityStmt;
574 
575  /* Prohibit read/write commands in read-only states. */
576  readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
577  if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
579  {
580  CommandTag commandtag = CreateCommandTag(parsetree);
581 
582  if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
584  if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
586  if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
588  }
589 
590  pstate = make_parsestate(NULL);
591  pstate->p_sourcetext = queryString;
592  pstate->p_queryEnv = queryEnv;
593 
594  switch (nodeTag(parsetree))
595  {
596  /*
597  * ******************** transactions ********************
598  */
599  case T_TransactionStmt:
600  {
601  TransactionStmt *stmt = (TransactionStmt *) parsetree;
602 
603  switch (stmt->kind)
604  {
605  /*
606  * START TRANSACTION, as defined by SQL99: Identical
607  * to BEGIN. Same code for both.
608  */
609  case TRANS_STMT_BEGIN:
610  case TRANS_STMT_START:
611  {
612  ListCell *lc;
613 
615  foreach(lc, stmt->options)
616  {
617  DefElem *item = (DefElem *) lfirst(lc);
618 
619  if (strcmp(item->defname, "transaction_isolation") == 0)
620  SetPGVariable("transaction_isolation",
621  list_make1(item->arg),
622  true);
623  else if (strcmp(item->defname, "transaction_read_only") == 0)
624  SetPGVariable("transaction_read_only",
625  list_make1(item->arg),
626  true);
627  else if (strcmp(item->defname, "transaction_deferrable") == 0)
628  SetPGVariable("transaction_deferrable",
629  list_make1(item->arg),
630  true);
631  }
632  }
633  break;
634 
635  case TRANS_STMT_COMMIT:
636  if (!EndTransactionBlock(stmt->chain))
637  {
638  /* report unsuccessful commit in qc */
639  if (qc)
640  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
641  }
642  break;
643 
644  case TRANS_STMT_PREPARE:
645  if (!PrepareTransactionBlock(stmt->gid))
646  {
647  /* report unsuccessful commit in qc */
648  if (qc)
649  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
650  }
651  break;
652 
654  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
655  FinishPreparedTransaction(stmt->gid, true);
656  break;
657 
659  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
660  FinishPreparedTransaction(stmt->gid, false);
661  break;
662 
663  case TRANS_STMT_ROLLBACK:
665  break;
666 
668  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
670  break;
671 
672  case TRANS_STMT_RELEASE:
673  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
675  break;
676 
678  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
680 
681  /*
682  * CommitTransactionCommand is in charge of
683  * re-defining the savepoint again
684  */
685  break;
686  }
687  }
688  break;
689 
690  /*
691  * Portal (cursor) manipulation
692  */
693  case T_DeclareCursorStmt:
694  PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
695  isTopLevel);
696  break;
697 
698  case T_ClosePortalStmt:
699  {
700  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
701 
702  CheckRestrictedOperation("CLOSE");
704  }
705  break;
706 
707  case T_FetchStmt:
708  PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
709  break;
710 
711  case T_DoStmt:
712  ExecuteDoStmt(pstate, (DoStmt *) parsetree, isAtomicContext);
713  break;
714 
716  /* no event triggers for global objects */
717  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
718  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
719  break;
720 
722  /* no event triggers for global objects */
723  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
724  DropTableSpace((DropTableSpaceStmt *) parsetree);
725  break;
726 
728  /* no event triggers for global objects */
730  break;
731 
732  case T_TruncateStmt:
733  ExecuteTruncate((TruncateStmt *) parsetree);
734  break;
735 
736  case T_CopyStmt:
737  {
738  uint64 processed;
739 
740  DoCopy(pstate, (CopyStmt *) parsetree,
741  pstmt->stmt_location, pstmt->stmt_len,
742  &processed);
743  if (qc)
744  SetQueryCompletion(qc, CMDTAG_COPY, processed);
745  }
746  break;
747 
748  case T_PrepareStmt:
749  CheckRestrictedOperation("PREPARE");
750  PrepareQuery(pstate, (PrepareStmt *) parsetree,
751  pstmt->stmt_location, pstmt->stmt_len);
752  break;
753 
754  case T_ExecuteStmt:
755  ExecuteQuery(pstate,
756  (ExecuteStmt *) parsetree, NULL,
757  params,
758  dest, qc);
759  break;
760 
761  case T_DeallocateStmt:
762  CheckRestrictedOperation("DEALLOCATE");
763  DeallocateQuery((DeallocateStmt *) parsetree);
764  break;
765 
766  case T_GrantRoleStmt:
767  /* no event triggers for global objects */
768  GrantRole((GrantRoleStmt *) parsetree);
769  break;
770 
771  case T_CreatedbStmt:
772  /* no event triggers for global objects */
773  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
774  createdb(pstate, (CreatedbStmt *) parsetree);
775  break;
776 
777  case T_AlterDatabaseStmt:
778  /* no event triggers for global objects */
779  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
780  break;
781 
783  /* no event triggers for global objects */
784  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
785  break;
786 
787  case T_DropdbStmt:
788  /* no event triggers for global objects */
789  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
790  DropDatabase(pstate, (DropdbStmt *) parsetree);
791  break;
792 
793  /* Query-level asynchronous notification */
794  case T_NotifyStmt:
795  {
796  NotifyStmt *stmt = (NotifyStmt *) parsetree;
797 
798  Async_Notify(stmt->conditionname, stmt->payload);
799  }
800  break;
801 
802  case T_ListenStmt:
803  {
804  ListenStmt *stmt = (ListenStmt *) parsetree;
805 
806  CheckRestrictedOperation("LISTEN");
807 
808  /*
809  * We don't allow LISTEN in background processes, as there is
810  * no mechanism for them to collect NOTIFY messages, so they'd
811  * just block cleanout of the async SLRU indefinitely.
812  * (Authors of custom background workers could bypass this
813  * restriction by calling Async_Listen directly, but then it's
814  * on them to provide some mechanism to process the message
815  * queue.) Note there seems no reason to forbid UNLISTEN.
816  */
817  if (MyBackendType != B_BACKEND)
818  ereport(ERROR,
819  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
820  /* translator: %s is name of a SQL command, eg LISTEN */
821  errmsg("cannot execute %s within a background process",
822  "LISTEN")));
823 
825  }
826  break;
827 
828  case T_UnlistenStmt:
829  {
830  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
831 
832  CheckRestrictedOperation("UNLISTEN");
833  if (stmt->conditionname)
835  else
837  }
838  break;
839 
840  case T_LoadStmt:
841  {
842  LoadStmt *stmt = (LoadStmt *) parsetree;
843 
844  closeAllVfds(); /* probably not necessary... */
845  /* Allowed names are restricted if you're not superuser */
846  load_file(stmt->filename, !superuser());
847  }
848  break;
849 
850  case T_CallStmt:
851  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
852  break;
853 
854  case T_ClusterStmt:
855  cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
856  break;
857 
858  case T_VacuumStmt:
859  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
860  break;
861 
862  case T_ExplainStmt:
863  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
864  break;
865 
866  case T_AlterSystemStmt:
867  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
869  break;
870 
871  case T_VariableSetStmt:
872  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
873  break;
874 
875  case T_VariableShowStmt:
876  {
877  VariableShowStmt *n = (VariableShowStmt *) parsetree;
878 
879  GetPGVariable(n->name, dest);
880  }
881  break;
882 
883  case T_DiscardStmt:
884  /* should we allow DISCARD PLANS? */
885  CheckRestrictedOperation("DISCARD");
886  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
887  break;
888 
890  /* no event triggers on event triggers */
892  break;
893 
895  /* no event triggers on event triggers */
896  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
897  break;
898 
899  /*
900  * ******************************** ROLE statements ****
901  */
902  case T_CreateRoleStmt:
903  /* no event triggers for global objects */
904  CreateRole(pstate, (CreateRoleStmt *) parsetree);
905  break;
906 
907  case T_AlterRoleStmt:
908  /* no event triggers for global objects */
909  AlterRole(pstate, (AlterRoleStmt *) parsetree);
910  break;
911 
912  case T_AlterRoleSetStmt:
913  /* no event triggers for global objects */
914  AlterRoleSet((AlterRoleSetStmt *) parsetree);
915  break;
916 
917  case T_DropRoleStmt:
918  /* no event triggers for global objects */
919  DropRole((DropRoleStmt *) parsetree);
920  break;
921 
922  case T_ReassignOwnedStmt:
923  /* no event triggers for global objects */
925  break;
926 
927  case T_LockStmt:
928 
929  /*
930  * Since the lock would just get dropped immediately, LOCK TABLE
931  * outside a transaction block is presumed to be user error.
932  */
933  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
934  LockTableCommand((LockStmt *) parsetree);
935  break;
936 
938  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
940  break;
941 
942  case T_CheckPointStmt:
943  if (!has_privs_of_role(GetUserId(), ROLE_PG_CHECKPOINTER))
944  ereport(ERROR,
945  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
946  errmsg("must be superuser or have privileges of pg_checkpointer to do CHECKPOINT")));
947 
950  break;
951 
952  case T_ReindexStmt:
953  ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
954  break;
955 
956  /*
957  * The following statements are supported by Event Triggers only
958  * in some cases, so we "fast path" them in the other cases.
959  */
960 
961  case T_GrantStmt:
962  {
963  GrantStmt *stmt = (GrantStmt *) parsetree;
964 
966  ProcessUtilitySlow(pstate, pstmt, queryString,
967  context, params, queryEnv,
968  dest, qc);
969  else
970  ExecuteGrantStmt(stmt);
971  }
972  break;
973 
974  case T_DropStmt:
975  {
976  DropStmt *stmt = (DropStmt *) parsetree;
977 
979  ProcessUtilitySlow(pstate, pstmt, queryString,
980  context, params, queryEnv,
981  dest, qc);
982  else
983  ExecDropStmt(stmt, isTopLevel);
984  }
985  break;
986 
987  case T_RenameStmt:
988  {
989  RenameStmt *stmt = (RenameStmt *) parsetree;
990 
992  ProcessUtilitySlow(pstate, pstmt, queryString,
993  context, params, queryEnv,
994  dest, qc);
995  else
996  ExecRenameStmt(stmt);
997  }
998  break;
999 
1001  {
1002  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
1003 
1005  ProcessUtilitySlow(pstate, pstmt, queryString,
1006  context, params, queryEnv,
1007  dest, qc);
1008  else
1009  ExecAlterObjectDependsStmt(stmt, NULL);
1010  }
1011  break;
1012 
1014  {
1015  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
1016 
1018  ProcessUtilitySlow(pstate, pstmt, queryString,
1019  context, params, queryEnv,
1020  dest, qc);
1021  else
1022  ExecAlterObjectSchemaStmt(stmt, NULL);
1023  }
1024  break;
1025 
1026  case T_AlterOwnerStmt:
1027  {
1028  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1029 
1031  ProcessUtilitySlow(pstate, pstmt, queryString,
1032  context, params, queryEnv,
1033  dest, qc);
1034  else
1035  ExecAlterOwnerStmt(stmt);
1036  }
1037  break;
1038 
1039  case T_CommentStmt:
1040  {
1041  CommentStmt *stmt = (CommentStmt *) parsetree;
1042 
1044  ProcessUtilitySlow(pstate, pstmt, queryString,
1045  context, params, queryEnv,
1046  dest, qc);
1047  else
1048  CommentObject(stmt);
1049  break;
1050  }
1051 
1052  case T_SecLabelStmt:
1053  {
1054  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1055 
1057  ProcessUtilitySlow(pstate, pstmt, queryString,
1058  context, params, queryEnv,
1059  dest, qc);
1060  else
1061  ExecSecLabelStmt(stmt);
1062  break;
1063  }
1064 
1065  default:
1066  /* All other statement types have event trigger support */
1067  ProcessUtilitySlow(pstate, pstmt, queryString,
1068  context, params, queryEnv,
1069  dest, qc);
1070  break;
1071  }
1072 
1073  free_parsestate(pstate);
1074 
1075  /*
1076  * Make effects of commands visible, for instance so that
1077  * PreCommit_on_commit_actions() can see them (see for example bug
1078  * #15631).
1079  */
1081 }
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4843
void Async_UnlistenAll(void)
Definition: async.c:804
void Async_Unlisten(const char *channel)
Definition: async.c:786
void Async_Listen(const char *channel)
Definition: async.c:772
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:625
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:64
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
Definition: prepare.c:58
void ExecuteQuery(ParseState *pstate, ExecuteStmt *stmt, IntoClause *intoClause, ParamListInfo params, DestReceiver *dest, QueryCompletion *qc)
Definition: prepare.c:184
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:539
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1054
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:431
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:235
void RequestCheckpoint(int flags)
Definition: checkpointer.c:920
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:103
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:45
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
Definition: cmdtag.h:36
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:100
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1441
void DropDatabase(ParseState *pstate, DropdbStmt *stmt)
Definition: dbcommands.c:1416
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1608
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:164
void closeAllVfds(void)
Definition: fd.c:2899
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
void ExecuteDoStmt(ParseState *pstate, DoStmt *stmt, bool atomic)
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:9377
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:8543
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8896
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:8753
void ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel)
Definition: indexcmds.c:2470
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:42
@ B_BACKEND
Definition: miscadmin.h:328
Oid GetUserId(void)
Definition: miscinit.c:495
BackendType MyBackendType
Definition: miscinit.c:62
#define copyObject(obj)
Definition: nodes.h:655
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:77
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:44
#define list_make1(x1)
Definition: pg_list.h:206
void PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo params, bool isTopLevel)
Definition: portalcmds.c:43
void PerformPortalClose(const char *name)
Definition: portalcmds.c:214
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, QueryCompletion *qc)
Definition: portalcmds.c:167
void check_stack_depth(void)
Definition: postgres.c:3470
ObjectType objectType
Definition: parsenodes.h:3103
ObjectType objtype
Definition: parsenodes.h:2794
Node * arg
Definition: parsenodes.h:759
ObjectType objtype
Definition: parsenodes.h:2029
char * conditionname
Definition: parsenodes.h:3165
char * filename
Definition: parsenodes.h:3283
char * payload
Definition: parsenodes.h:3155
char * conditionname
Definition: parsenodes.h:3154
QueryEnvironment * p_queryEnv
Definition: parse_node.h:205
const char * p_sourcetext
Definition: parse_node.h:181
ObjectType renameType
Definition: parsenodes.h:3057
ObjectType objtype
Definition: parsenodes.h:2806
char * savepoint_name
Definition: parsenodes.h:3201
char * conditionname
Definition: parsenodes.h:3175
bool superuser(void)
Definition: superuser.c:46
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1631
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5293
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1461
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1312
Oid AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
Definition: user.c:493
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:828
void DropRole(DropRoleStmt *stmt)
Definition: user.c:909
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1227
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree)
Definition: utility.c:134
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:409
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:427
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:464
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:446
static void ProcessUtilitySlow(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:1089
#define COMMAND_OK_IN_PARALLEL_MODE
Definition: utility.h:57
@ PROCESS_UTILITY_QUERY_NONATOMIC
Definition: utility.h:24
void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:107
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3510
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:3988
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3776
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3516
void DefineSavepoint(const char *name)
Definition: xact.c:4157
void ReleaseSavepoint(const char *name)
Definition: xact.c:4242
bool IsTransactionBlock(void)
Definition: xact.c:4754
void BeginTransactionBlock(void)
Definition: xact.c:3708
void RollbackToSavepoint(const char *name)
Definition: xact.c:4351
bool EndTransactionBlock(bool chain)
Definition: xact.c:3828
#define CHECKPOINT_FORCE
Definition: xlog.h:197
#define CHECKPOINT_WAIT
Definition: xlog.h:200
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:196

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

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

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

Definition at line 2155 of file utility.c.

2156 {
2157  Query *qry;
2158 
2159  switch (nodeTag(parsetree))
2160  {
2161  case T_DeclareCursorStmt:
2162  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2163  if (qry->commandType == CMD_UTILITY)
2164  return UtilityContainsQuery(qry->utilityStmt);
2165  return qry;
2166 
2167  case T_ExplainStmt:
2168  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2169  if (qry->commandType == CMD_UTILITY)
2170  return UtilityContainsQuery(qry->utilityStmt);
2171  return qry;
2172 
2173  case T_CreateTableAsStmt:
2174  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2175  if (qry->commandType == CMD_UTILITY)
2176  return UtilityContainsQuery(qry->utilityStmt);
2177  return qry;
2178 
2179  default:
2180  return NULL;
2181  }
2182 }
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2155

References castNode, CMD_UTILITY, Query::commandType, nodeTag, T_CreateTableAsStmt, T_DeclareCursorStmt, T_ExplainStmt, and Query::utilityStmt.

Referenced by AcquireExecutorLocks(), AcquirePlannerLocks(), extract_query_dependencies_walker(), and ResetPlanCache().

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 2005 of file utility.c.

2006 {
2007  switch (nodeTag(parsetree))
2008  {
2009  case T_CallStmt:
2010  {
2011  CallStmt *stmt = (CallStmt *) parsetree;
2012 
2013  return (stmt->funcexpr->funcresulttype == RECORDOID);
2014  }
2015  case T_FetchStmt:
2016  {
2017  FetchStmt *stmt = (FetchStmt *) parsetree;
2018  Portal portal;
2019 
2020  if (stmt->ismove)
2021  return false;
2022  portal = GetPortalByName(stmt->portalname);
2023  if (!PortalIsValid(portal))
2024  return false; /* not our business to raise error */
2025  return portal->tupDesc ? true : false;
2026  }
2027 
2028  case T_ExecuteStmt:
2029  {
2030  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2031  PreparedStatement *entry;
2032 
2033  entry = FetchPreparedStatement(stmt->name, false);
2034  if (!entry)
2035  return false; /* not our business to raise error */
2036  if (entry->plansource->resultDesc)
2037  return true;
2038  return false;
2039  }
2040 
2041  case T_ExplainStmt:
2042  return true;
2043 
2044  case T_VariableShowStmt:
2045  return true;
2046 
2047  default:
2048  return false;
2049  }
2050 }
return true
Definition: isn.c:126
#define PortalIsValid(p)
Definition: portal.h:212
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc resultDesc
Definition: plancache.h:108
FuncExpr * funcexpr
Definition: parsenodes.h:3040
char * portalname
Definition: parsenodes.h:2872
Oid funcresulttype
Definition: primnodes.h:496
TupleDesc tupDesc
Definition: portal.h:160

References FetchPreparedStatement(), CallStmt::funcexpr, FuncExpr::funcresulttype, GetPortalByName(), FetchStmt::ismove, ExecuteStmt::name, nodeTag, PreparedStatement::plansource, PortalIsValid, FetchStmt::portalname, CachedPlanSource::resultDesc, T_CallStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, true, and PortalData::tupDesc.

Referenced by ChoosePortalStrategy().

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 2061 of file utility.c.

2062 {
2063  switch (nodeTag(parsetree))
2064  {
2065  case T_CallStmt:
2066  return CallStmtResultDesc((CallStmt *) parsetree);
2067 
2068  case T_FetchStmt:
2069  {
2070  FetchStmt *stmt = (FetchStmt *) parsetree;
2071  Portal portal;
2072 
2073  if (stmt->ismove)
2074  return NULL;
2075  portal = GetPortalByName(stmt->portalname);
2076  if (!PortalIsValid(portal))
2077  return NULL; /* not our business to raise error */
2078  return CreateTupleDescCopy(portal->tupDesc);
2079  }
2080 
2081  case T_ExecuteStmt:
2082  {
2083  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2084  PreparedStatement *entry;
2085 
2086  entry = FetchPreparedStatement(stmt->name, false);
2087  if (!entry)
2088  return NULL; /* not our business to raise error */
2089  return FetchPreparedStatementResultDesc(entry);
2090  }
2091 
2092  case T_ExplainStmt:
2093  return ExplainResultDesc((ExplainStmt *) parsetree);
2094 
2095  case T_VariableShowStmt:
2096  {
2097  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2098 
2099  return GetPGVariableResultDesc(n->name);
2100  }
2101 
2102  default:
2103  return NULL;
2104  }
2105 }
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:500
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:328
TupleDesc CallStmtResultDesc(CallStmt *stmt)
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:9386
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111

References CallStmtResultDesc(), CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), FetchStmt::ismove, VariableShowStmt::name, ExecuteStmt::name, nodeTag, PortalIsValid, FetchStmt::portalname, T_CallStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, and PortalData::tupDesc.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

Variable Documentation

◆ ProcessUtility_hook

ProcessUtility_hook_type ProcessUtility_hook = NULL

Definition at line 77 of file utility.c.

Referenced by _PG_fini(), _PG_init(), and ProcessUtility().