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, bool readOnlyTree, 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, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
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, bool readOnlyTree, 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 100 of file utility.c.

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

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

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

◆ CreateCommandName()

static const char* CreateCommandName ( Node parsetree)
inlinestatic

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

104 {
105  return GetCommandTagName(CreateCommandTag(parsetree));
106 }
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:45
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2320

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2320 of file utility.c.

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

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3199 of file utility.c.

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

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

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

◆ ProcessUtility()

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

Definition at line 503 of file utility.c.

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

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

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

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1918 of file utility.c.

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

Referenced by ATParseTransformCmd(), and ATRewriteTables().

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

◆ standard_ProcessUtility()

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

Definition at line 544 of file utility.c.

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

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

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

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

2138 {
2139  Query *qry;
2140 
2141  switch (nodeTag(parsetree))
2142  {
2143  case T_DeclareCursorStmt:
2144  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2145  if (qry->commandType == CMD_UTILITY)
2146  return UtilityContainsQuery(qry->utilityStmt);
2147  return qry;
2148 
2149  case T_ExplainStmt:
2150  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2151  if (qry->commandType == CMD_UTILITY)
2152  return UtilityContainsQuery(qry->utilityStmt);
2153  return qry;
2154 
2155  case T_CreateTableAsStmt:
2156  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2157  if (qry->commandType == CMD_UTILITY)
2158  return UtilityContainsQuery(qry->utilityStmt);
2159  return qry;
2160 
2161  default:
2162  return NULL;
2163  }
2164 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
Node * utilityStmt
Definition: parsenodes.h:128
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2137
CmdType commandType
Definition: parsenodes.h:120
#define nodeTag(nodeptr)
Definition: nodes.h:544

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

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

1988 {
1989  switch (nodeTag(parsetree))
1990  {
1991  case T_CallStmt:
1992  {
1993  CallStmt *stmt = (CallStmt *) parsetree;
1994 
1995  return (stmt->funcexpr->funcresulttype == RECORDOID);
1996  }
1997  case T_FetchStmt:
1998  {
1999  FetchStmt *stmt = (FetchStmt *) parsetree;
2000  Portal portal;
2001 
2002  if (stmt->ismove)
2003  return false;
2004  portal = GetPortalByName(stmt->portalname);
2005  if (!PortalIsValid(portal))
2006  return false; /* not our business to raise error */
2007  return portal->tupDesc ? true : false;
2008  }
2009 
2010  case T_ExecuteStmt:
2011  {
2012  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2013  PreparedStatement *entry;
2014 
2015  entry = FetchPreparedStatement(stmt->name, false);
2016  if (!entry)
2017  return false; /* not our business to raise error */
2018  if (entry->plansource->resultDesc)
2019  return true;
2020  return false;
2021  }
2022 
2023  case T_ExplainStmt:
2024  return true;
2025 
2026  case T_VariableShowStmt:
2027  return true;
2028 
2029  default:
2030  return false;
2031  }
2032 }
Oid funcresulttype
Definition: primnodes.h:496
FuncExpr * funcexpr
Definition: parsenodes.h:3026
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:395
char * portalname
Definition: parsenodes.h:2858
#define PortalIsValid(p)
Definition: portal.h:211
bool ismove
Definition: parsenodes.h:2859
TupleDesc tupDesc
Definition: portal.h:159
#define nodeTag(nodeptr)
Definition: nodes.h:544
char * name
Definition: parsenodes.h:3552
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:468

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

2044 {
2045  switch (nodeTag(parsetree))
2046  {
2047  case T_CallStmt:
2048  return CallStmtResultDesc((CallStmt *) parsetree);
2049 
2050  case T_FetchStmt:
2051  {
2052  FetchStmt *stmt = (FetchStmt *) parsetree;
2053  Portal portal;
2054 
2055  if (stmt->ismove)
2056  return NULL;
2057  portal = GetPortalByName(stmt->portalname);
2058  if (!PortalIsValid(portal))
2059  return NULL; /* not our business to raise error */
2060  return CreateTupleDescCopy(portal->tupDesc);
2061  }
2062 
2063  case T_ExecuteStmt:
2064  {
2065  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2066  PreparedStatement *entry;
2067 
2068  entry = FetchPreparedStatement(stmt->name, false);
2069  if (!entry)
2070  return NULL; /* not our business to raise error */
2071  return FetchPreparedStatementResultDesc(entry);
2072  }
2073 
2074  case T_ExplainStmt:
2075  return ExplainResultDesc((ExplainStmt *) parsetree);
2076 
2077  case T_VariableShowStmt:
2078  {
2079  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2080 
2081  return GetPGVariableResultDesc(n->name);
2082  }
2083 
2084  default:
2085  return NULL;
2086  }
2087 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:9325
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:111
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc CallStmtResultDesc(CallStmt *stmt)
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:328
char * portalname
Definition: parsenodes.h:2858
#define PortalIsValid(p)
Definition: portal.h:211
bool ismove
Definition: parsenodes.h:2859
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:500
TupleDesc tupDesc
Definition: portal.h:159
#define nodeTag(nodeptr)
Definition: nodes.h:544
char * name
Definition: parsenodes.h:3552
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:468

Variable Documentation

◆ ProcessUtility_hook

Definition at line 76 of file utility.c.

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