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:579
#define WARNING
Definition: elog.h:40
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:78
#define Assert(condition)
Definition: c.h:746
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:2293

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

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

◆ 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:579
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:746

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

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

1893 {
1894  PlannedStmt *wrapper;
1895 
1896  /*
1897  * For event triggers, we must "close" the current complex-command set,
1898  * and start a new one afterwards; this is needed to ensure the ordering
1899  * of command events is consistent with the way they were executed.
1900  */
1902 
1903  /* Create a suitable wrapper */
1904  wrapper = makeNode(PlannedStmt);
1905  wrapper->commandType = CMD_UTILITY;
1906  wrapper->canSetTag = false;
1907  wrapper->utilityStmt = stmt;
1908  wrapper->stmt_location = context->pstmt->stmt_location;
1909  wrapper->stmt_len = context->pstmt->stmt_len;
1910 
1911  ProcessUtility(wrapper,
1912  context->queryString,
1914  context->params,
1915  context->queryEnv,
1916  None_Receiver,
1917  NULL);
1918 
1921 }
PlannedStmt * pstmt
Definition: utility.h:32
DestReceiver * None_Receiver
Definition: dest.c:96
int stmt_len
Definition: plannodes.h:90
void EventTriggerAlterTableStart(Node *parsetree)
int stmt_location
Definition: plannodes.h:89
Node * utilityStmt
Definition: plannodes.h:86
const char * queryString
Definition: utility.h:33
QueryEnvironment * queryEnv
Definition: utility.h:36
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define makeNode(_type_)
Definition: nodes.h:576
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(), NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), ERRCODE_INSUFFICIENT_PRIVILEGE, errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetCommandTagName(), GetPGVariable(), TransactionStmt::gid, GrantRole(), IsInParallelMode(), IsTransactionBlock(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), VariableShowStmt::name, ReindexStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ReindexStmt::options, ParseState::p_queryEnv, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), REINDEX_OBJECT_DATABASE, REINDEX_OBJECT_INDEX, REINDEX_OBJECT_SCHEMA, REINDEX_OBJECT_SYSTEM, REINDEX_OBJECT_TABLE, ReindexIndex(), ReindexMultipleTables(), REINDEXOPT_CONCURRENTLY, ReindexTable(), ReindexStmt::relation, ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), SetQueryCompletion(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSystemStmt, T_AlterTableSpaceOptionsStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

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

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

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

2111 {
2112  Query *qry;
2113 
2114  switch (nodeTag(parsetree))
2115  {
2116  case T_DeclareCursorStmt:
2117  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2118  if (qry->commandType == CMD_UTILITY)
2119  return UtilityContainsQuery(qry->utilityStmt);
2120  return qry;
2121 
2122  case T_ExplainStmt:
2123  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2124  if (qry->commandType == CMD_UTILITY)
2125  return UtilityContainsQuery(qry->utilityStmt);
2126  return qry;
2127 
2128  case T_CreateTableAsStmt:
2129  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2130  if (qry->commandType == CMD_UTILITY)
2131  return UtilityContainsQuery(qry->utilityStmt);
2132  return qry;
2133 
2134  default:
2135  return NULL;
2136  }
2137 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:597
Node * utilityStmt
Definition: parsenodes.h:120
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2110
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:533

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

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

1961 {
1962  switch (nodeTag(parsetree))
1963  {
1964  case T_CallStmt:
1965  {
1966  CallStmt *stmt = (CallStmt *) parsetree;
1967 
1968  return (stmt->funcexpr->funcresulttype == RECORDOID);
1969  }
1970  case T_FetchStmt:
1971  {
1972  FetchStmt *stmt = (FetchStmt *) parsetree;
1973  Portal portal;
1974 
1975  if (stmt->ismove)
1976  return false;
1977  portal = GetPortalByName(stmt->portalname);
1978  if (!PortalIsValid(portal))
1979  return false; /* not our business to raise error */
1980  return portal->tupDesc ? true : false;
1981  }
1982 
1983  case T_ExecuteStmt:
1984  {
1985  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1986  PreparedStatement *entry;
1987 
1988  entry = FetchPreparedStatement(stmt->name, false);
1989  if (!entry)
1990  return false; /* not our business to raise error */
1991  if (entry->plansource->resultDesc)
1992  return true;
1993  return false;
1994  }
1995 
1996  case T_ExplainStmt:
1997  return true;
1998 
1999  case T_VariableShowStmt:
2000  return true;
2001 
2002  default:
2003  return false;
2004  }
2005 }
Oid funcresulttype
Definition: primnodes.h:470
FuncExpr * funcexpr
Definition: parsenodes.h:2907
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:329
char * portalname
Definition: parsenodes.h:2763
#define PortalIsValid(p)
Definition: portal.h:203
bool ismove
Definition: parsenodes.h:2764
TupleDesc tupDesc
Definition: portal.h:159
#define nodeTag(nodeptr)
Definition: nodes.h:533
char * name
Definition: parsenodes.h:3445
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:469

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

2017 {
2018  switch (nodeTag(parsetree))
2019  {
2020  case T_CallStmt:
2021  return CallStmtResultDesc((CallStmt *) parsetree);
2022 
2023  case T_FetchStmt:
2024  {
2025  FetchStmt *stmt = (FetchStmt *) parsetree;
2026  Portal portal;
2027 
2028  if (stmt->ismove)
2029  return NULL;
2030  portal = GetPortalByName(stmt->portalname);
2031  if (!PortalIsValid(portal))
2032  return NULL; /* not our business to raise error */
2033  return CreateTupleDescCopy(portal->tupDesc);
2034  }
2035 
2036  case T_ExecuteStmt:
2037  {
2038  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2039  PreparedStatement *entry;
2040 
2041  entry = FetchPreparedStatement(stmt->name, false);
2042  if (!entry)
2043  return NULL; /* not our business to raise error */
2044  return FetchPreparedStatementResultDesc(entry);
2045  }
2046 
2047  case T_ExplainStmt:
2048  return ExplainResultDesc((ExplainStmt *) parsetree);
2049 
2050  case T_VariableShowStmt:
2051  {
2052  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2053 
2054  return GetPGVariableResultDesc(n->name);
2055  }
2056 
2057  default:
2058  return NULL;
2059  }
2060 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:9002
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:322
char * portalname
Definition: parsenodes.h:2763
#define PortalIsValid(p)
Definition: portal.h:203
bool ismove
Definition: parsenodes.h:2764
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:501
TupleDesc tupDesc
Definition: portal.h:159
#define nodeTag(nodeptr)
Definition: nodes.h:533
char * name
Definition: parsenodes.h:3445
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().