PostgreSQL Source Code  git master
utility.h File Reference
#include "tcop/cmdtag.h"
#include "tcop/tcopprot.h"
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AlterTableUtilityContext
 

Macros

#define COMMAND_OK_IN_READ_ONLY_TXN   0x0001
 
#define COMMAND_OK_IN_PARALLEL_MODE   0x0002
 
#define COMMAND_OK_IN_RECOVERY   0x0004
 
#define COMMAND_IS_STRICTLY_READ_ONLY
 
#define COMMAND_IS_NOT_READ_ONLY   0
 

Typedefs

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

Enumerations

enum  ProcessUtilityContext { PROCESS_UTILITY_TOPLEVEL, PROCESS_UTILITY_QUERY, PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_SUBCOMMAND }
 

Functions

void ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
CommandTag CreateCommandTag (Node *parsetree)
 
static const char * CreateCommandName (Node *parsetree)
 
LogStmtLevel GetCommandLogLevel (Node *parsetree)
 
bool CommandIsReadOnly (PlannedStmt *pstmt)
 

Variables

PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
 

Macro Definition Documentation

◆ COMMAND_IS_NOT_READ_ONLY

#define COMMAND_IS_NOT_READ_ONLY   0

Definition at line 68 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly().

◆ COMMAND_IS_STRICTLY_READ_ONLY

#define COMMAND_IS_STRICTLY_READ_ONLY
Value:
COMMAND_OK_IN_PARALLEL_MODE)
#define COMMAND_OK_IN_RECOVERY
Definition: utility.h:58
#define COMMAND_OK_IN_READ_ONLY_TXN
Definition: utility.h:56

Definition at line 65 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

◆ COMMAND_OK_IN_PARALLEL_MODE

#define COMMAND_OK_IN_PARALLEL_MODE   0x0002

Definition at line 57 of file utility.h.

Referenced by standard_ProcessUtility().

◆ COMMAND_OK_IN_READ_ONLY_TXN

#define COMMAND_OK_IN_READ_ONLY_TXN   0x0001

Definition at line 56 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

◆ COMMAND_OK_IN_RECOVERY

#define COMMAND_OK_IN_RECOVERY   0x0004

Definition at line 58 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

Typedef Documentation

◆ AlterTableUtilityContext

◆ ProcessUtility_hook_type

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

Definition at line 71 of file utility.h.

Enumeration Type Documentation

◆ ProcessUtilityContext

Enumerator
PROCESS_UTILITY_TOPLEVEL 
PROCESS_UTILITY_QUERY 
PROCESS_UTILITY_QUERY_NONATOMIC 
PROCESS_UTILITY_SUBCOMMAND 

Definition at line 20 of file utility.h.

21 {
22  PROCESS_UTILITY_TOPLEVEL, /* toplevel interactive command */
23  PROCESS_UTILITY_QUERY, /* a complete query, but not toplevel */
24  PROCESS_UTILITY_QUERY_NONATOMIC, /* a complete query, nonatomic
25  * execution context */
26  PROCESS_UTILITY_SUBCOMMAND /* a portion of a query */
ProcessUtilityContext
Definition: utility.h:20

Function Documentation

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 99 of file utility.c.

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

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

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

◆ CreateCommandName()

static const char* CreateCommandName ( Node parsetree)
inlinestatic

Definition at line 99 of file utility.h.

References CommandIsReadOnly(), CreateCommandTag(), GetCommandLogLevel(), GetCommandTagName(), and AlterTableUtilityContext::pstmt.

Referenced by _SPI_execute_plan(), ExecCheckXactReadOnly(), get_command_tag(), init_execution_state(), pg_event_trigger_ddl_commands(), and SPI_cursor_open_internal().

100 {
101  return GetCommandTagName(CreateCommandTag(parsetree));
102 }
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:45
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2246

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2246 of file utility.c.

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

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3121 of file utility.c.

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

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

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

◆ ProcessUtility()

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

Definition at line 501 of file utility.c.

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

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

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

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1845 of file utility.c.

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

Referenced by ATParseTransformCmd(), and ATRewriteTables().

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

◆ standard_ProcessUtility()

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

Definition at line 541 of file utility.c.

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

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

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

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

Definition at line 2063 of file utility.c.

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

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

2064 {
2065  Query *qry;
2066 
2067  switch (nodeTag(parsetree))
2068  {
2069  case T_DeclareCursorStmt:
2070  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2071  if (qry->commandType == CMD_UTILITY)
2072  return UtilityContainsQuery(qry->utilityStmt);
2073  return qry;
2074 
2075  case T_ExplainStmt:
2076  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2077  if (qry->commandType == CMD_UTILITY)
2078  return UtilityContainsQuery(qry->utilityStmt);
2079  return qry;
2080 
2081  case T_CreateTableAsStmt:
2082  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2083  if (qry->commandType == CMD_UTILITY)
2084  return UtilityContainsQuery(qry->utilityStmt);
2085  return qry;
2086 
2087  default:
2088  return NULL;
2089  }
2090 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:598
Node * utilityStmt
Definition: parsenodes.h:120
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2063
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:534

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 1913 of file utility.c.

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

1914 {
1915  switch (nodeTag(parsetree))
1916  {
1917  case T_CallStmt:
1918  {
1919  CallStmt *stmt = (CallStmt *) parsetree;
1920 
1921  return (stmt->funcexpr->funcresulttype == RECORDOID);
1922  }
1923  case T_FetchStmt:
1924  {
1925  FetchStmt *stmt = (FetchStmt *) parsetree;
1926  Portal portal;
1927 
1928  if (stmt->ismove)
1929  return false;
1930  portal = GetPortalByName(stmt->portalname);
1931  if (!PortalIsValid(portal))
1932  return false; /* not our business to raise error */
1933  return portal->tupDesc ? true : false;
1934  }
1935 
1936  case T_ExecuteStmt:
1937  {
1938  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1939  PreparedStatement *entry;
1940 
1941  entry = FetchPreparedStatement(stmt->name, false);
1942  if (!entry)
1943  return false; /* not our business to raise error */
1944  if (entry->plansource->resultDesc)
1945  return true;
1946  return false;
1947  }
1948 
1949  case T_ExplainStmt:
1950  return true;
1951 
1952  case T_VariableShowStmt:
1953  return true;
1954 
1955  default:
1956  return false;
1957  }
1958 }
Oid funcresulttype
Definition: primnodes.h:470
FuncExpr * funcexpr
Definition: parsenodes.h:2901
CachedPlanSource * plansource
Definition: prepare.h:31
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc resultDesc
Definition: plancache.h:108
#define true
Definition: c.h:321
char * portalname
Definition: parsenodes.h:2757
#define PortalIsValid(p)
Definition: portal.h:203
bool ismove
Definition: parsenodes.h:2758
TupleDesc tupDesc
Definition: portal.h:159
#define nodeTag(nodeptr)
Definition: nodes.h:534
char * name
Definition: parsenodes.h:3438
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:469

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 1969 of file utility.c.

References CallStmtResultDesc(), CMD_DELETE, CMD_INSERT, CMD_NOTHING, CMD_SELECT, CMD_UNKNOWN, CMD_UPDATE, CMD_UTILITY, Query::commandType, CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), FetchStmt::ismove, VariableShowStmt::name, ExecuteStmt::name, nodeTag, PortalIsValid, FetchStmt::portalname, Query::returningList, T_CallStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, PortalData::tupDesc, UtilityReturnsTuples(), and Query::utilityStmt.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

1970 {
1971  switch (nodeTag(parsetree))
1972  {
1973  case T_CallStmt:
1974  return CallStmtResultDesc((CallStmt *) parsetree);
1975 
1976  case T_FetchStmt:
1977  {
1978  FetchStmt *stmt = (FetchStmt *) parsetree;
1979  Portal portal;
1980 
1981  if (stmt->ismove)
1982  return NULL;
1983  portal = GetPortalByName(stmt->portalname);
1984  if (!PortalIsValid(portal))
1985  return NULL; /* not our business to raise error */
1986  return CreateTupleDescCopy(portal->tupDesc);
1987  }
1988 
1989  case T_ExecuteStmt:
1990  {
1991  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1992  PreparedStatement *entry;
1993 
1994  entry = FetchPreparedStatement(stmt->name, false);
1995  if (!entry)
1996  return NULL; /* not our business to raise error */
1997  return FetchPreparedStatementResultDesc(entry);
1998  }
1999 
2000  case T_ExplainStmt:
2001  return ExplainResultDesc((ExplainStmt *) parsetree);
2002 
2003  case T_VariableShowStmt:
2004  {
2005  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2006 
2007  return GetPGVariableResultDesc(n->name);
2008  }
2009 
2010  default:
2011  return NULL;
2012  }
2013 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:8966
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:110
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc CallStmtResultDesc(CallStmt *stmt)
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:326
char * portalname
Definition: parsenodes.h:2757
#define PortalIsValid(p)
Definition: portal.h:203
bool ismove
Definition: parsenodes.h:2758
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:501
TupleDesc tupDesc
Definition: portal.h:159
#define nodeTag(nodeptr)
Definition: nodes.h:534
char * name
Definition: parsenodes.h:3438
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:469

Variable Documentation

◆ ProcessUtility_hook

Definition at line 75 of file utility.c.

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