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:588
#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:2337

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

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

◆ 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:588
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 1935 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().

1936 {
1937  PlannedStmt *wrapper;
1938 
1939  /*
1940  * For event triggers, we must "close" the current complex-command set,
1941  * and start a new one afterwards; this is needed to ensure the ordering
1942  * of command events is consistent with the way they were executed.
1943  */
1945 
1946  /* Create a suitable wrapper */
1947  wrapper = makeNode(PlannedStmt);
1948  wrapper->commandType = CMD_UTILITY;
1949  wrapper->canSetTag = false;
1950  wrapper->utilityStmt = stmt;
1951  wrapper->stmt_location = context->pstmt->stmt_location;
1952  wrapper->stmt_len = context->pstmt->stmt_len;
1953 
1954  ProcessUtility(wrapper,
1955  context->queryString,
1956  false,
1958  context->params,
1959  context->queryEnv,
1960  None_Receiver,
1961  NULL);
1962 
1965 }
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:585
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(), B_BACKEND, BeginTransactionBlock(), castNode, TransactionStmt::chain, check_stack_depth(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), ClassifyUtilityCommandAsReadOnly(), closeAllVfds(), cluster(), COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_PARALLEL_MODE, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, CommandCounterIncrement(), CommentObject(), NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, copyObject, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, 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(), MyBackendType, VariableShowStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ParseState::p_queryEnv, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), SetQueryCompletion(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSystemStmt, T_AlterTableSpaceOptionsStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

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

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");
806 
807  /*
808  * We don't allow LISTEN in background processes, as there is
809  * no mechanism for them to collect NOTIFY messages, so they'd
810  * just block cleanout of the async SLRU indefinitely.
811  * (Authors of custom background workers could bypass this
812  * restriction by calling Async_Listen directly, but then it's
813  * on them to provide some mechanism to process the message
814  * queue.) Note there seems no reason to forbid UNLISTEN.
815  */
816  if (MyBackendType != B_BACKEND)
817  ereport(ERROR,
818  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
819  /* translator: %s is name of a SQL command, eg LISTEN */
820  errmsg("cannot execute %s within a background process",
821  "LISTEN")));
822 
824  }
825  break;
826 
827  case T_UnlistenStmt:
828  {
829  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
830 
831  CheckRestrictedOperation("UNLISTEN");
832  if (stmt->conditionname)
834  else
836  }
837  break;
838 
839  case T_LoadStmt:
840  {
841  LoadStmt *stmt = (LoadStmt *) parsetree;
842 
843  closeAllVfds(); /* probably not necessary... */
844  /* Allowed names are restricted if you're not superuser */
845  load_file(stmt->filename, !superuser());
846  }
847  break;
848 
849  case T_CallStmt:
850  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
851  break;
852 
853  case T_ClusterStmt:
854  cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
855  break;
856 
857  case T_VacuumStmt:
858  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
859  break;
860 
861  case T_ExplainStmt:
862  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
863  break;
864 
865  case T_AlterSystemStmt:
866  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
868  break;
869 
870  case T_VariableSetStmt:
871  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
872  break;
873 
874  case T_VariableShowStmt:
875  {
876  VariableShowStmt *n = (VariableShowStmt *) parsetree;
877 
878  GetPGVariable(n->name, dest);
879  }
880  break;
881 
882  case T_DiscardStmt:
883  /* should we allow DISCARD PLANS? */
884  CheckRestrictedOperation("DISCARD");
885  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
886  break;
887 
889  /* no event triggers on event triggers */
891  break;
892 
894  /* no event triggers on event triggers */
895  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
896  break;
897 
898  /*
899  * ******************************** ROLE statements ****
900  */
901  case T_CreateRoleStmt:
902  /* no event triggers for global objects */
903  CreateRole(pstate, (CreateRoleStmt *) parsetree);
904  break;
905 
906  case T_AlterRoleStmt:
907  /* no event triggers for global objects */
908  AlterRole(pstate, (AlterRoleStmt *) parsetree);
909  break;
910 
911  case T_AlterRoleSetStmt:
912  /* no event triggers for global objects */
913  AlterRoleSet((AlterRoleSetStmt *) parsetree);
914  break;
915 
916  case T_DropRoleStmt:
917  /* no event triggers for global objects */
918  DropRole((DropRoleStmt *) parsetree);
919  break;
920 
921  case T_ReassignOwnedStmt:
922  /* no event triggers for global objects */
924  break;
925 
926  case T_LockStmt:
927 
928  /*
929  * Since the lock would just get dropped immediately, LOCK TABLE
930  * outside a transaction block is presumed to be user error.
931  */
932  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
933  LockTableCommand((LockStmt *) parsetree);
934  break;
935 
937  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
939  break;
940 
941  case T_CheckPointStmt:
942  if (!superuser())
943  ereport(ERROR,
944  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
945  errmsg("must be superuser to do CHECKPOINT")));
946 
949  break;
950 
951  case T_ReindexStmt:
952  ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
953  break;
954 
955  /*
956  * The following statements are supported by Event Triggers only
957  * in some cases, so we "fast path" them in the other cases.
958  */
959 
960  case T_GrantStmt:
961  {
962  GrantStmt *stmt = (GrantStmt *) parsetree;
963 
965  ProcessUtilitySlow(pstate, pstmt, queryString,
966  context, params, queryEnv,
967  dest, qc);
968  else
969  ExecuteGrantStmt(stmt);
970  }
971  break;
972 
973  case T_DropStmt:
974  {
975  DropStmt *stmt = (DropStmt *) parsetree;
976 
978  ProcessUtilitySlow(pstate, pstmt, queryString,
979  context, params, queryEnv,
980  dest, qc);
981  else
982  ExecDropStmt(stmt, isTopLevel);
983  }
984  break;
985 
986  case T_RenameStmt:
987  {
988  RenameStmt *stmt = (RenameStmt *) parsetree;
989 
991  ProcessUtilitySlow(pstate, pstmt, queryString,
992  context, params, queryEnv,
993  dest, qc);
994  else
995  ExecRenameStmt(stmt);
996  }
997  break;
998 
1000  {
1001  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
1002 
1004  ProcessUtilitySlow(pstate, pstmt, queryString,
1005  context, params, queryEnv,
1006  dest, qc);
1007  else
1008  ExecAlterObjectDependsStmt(stmt, NULL);
1009  }
1010  break;
1011 
1013  {
1014  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
1015 
1017  ProcessUtilitySlow(pstate, pstmt, queryString,
1018  context, params, queryEnv,
1019  dest, qc);
1020  else
1021  ExecAlterObjectSchemaStmt(stmt, NULL);
1022  }
1023  break;
1024 
1025  case T_AlterOwnerStmt:
1026  {
1027  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1028 
1030  ProcessUtilitySlow(pstate, pstmt, queryString,
1031  context, params, queryEnv,
1032  dest, qc);
1033  else
1034  ExecAlterOwnerStmt(stmt);
1035  }
1036  break;
1037 
1038  case T_CommentStmt:
1039  {
1040  CommentStmt *stmt = (CommentStmt *) parsetree;
1041 
1043  ProcessUtilitySlow(pstate, pstmt, queryString,
1044  context, params, queryEnv,
1045  dest, qc);
1046  else
1047  CommentObject(stmt);
1048  break;
1049  }
1050 
1051  case T_SecLabelStmt:
1052  {
1053  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1054 
1056  ProcessUtilitySlow(pstate, pstmt, queryString,
1057  context, params, queryEnv,
1058  dest, qc);
1059  else
1060  ExecSecLabelStmt(stmt);
1061  break;
1062  }
1063 
1064  default:
1065  /* All other statement types have event trigger support */
1066  ProcessUtilitySlow(pstate, pstmt, queryString,
1067  context, params, queryEnv,
1068  dest, qc);
1069  break;
1070  }
1071 
1072  free_parsestate(pstate);
1073 
1074  /*
1075  * Make effects of commands visible, for instance so that
1076  * PreCommit_on_commit_actions() can see them (see for example bug
1077  * #15631).
1078  */
1080 }
ObjectType objtype
Definition: parsenodes.h:2792
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:2898
ObjectType objtype
Definition: parsenodes.h:2804
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1971
void PerformPortalClose(const char *name)
Definition: portalcmds.c:214
bool EndTransactionBlock(bool chain)
Definition: xact.c:3777
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:3055
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:113
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3459
#define castNode(_type_, nodeptr)
Definition: nodes.h:606
BackendType MyBackendType
Definition: miscinit.c:62
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:3101
void DefineSavepoint(const char *name)
Definition: xact.c:4106
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:537
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3725
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
char * filename
Definition: parsenodes.h:3281
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:772
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:233
bool RecoveryInProgress(void)
Definition: xlog.c:8341
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree)
Definition: utility.c:133
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1611
int stmt_len
Definition: plannodes.h:90
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
ObjectType removeType
Definition: parsenodes.h:2767
void RollbackToSavepoint(const char *name)
Definition: xact.c:4300
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:9352
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:4703
static void ProcessUtilitySlow(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:1088
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:539
#define COMMAND_OK_IN_RECOVERY
Definition: utility.h:58
bool IsInParallelMode(void)
Definition: xact.c:1013
#define ERROR
Definition: elog.h:46
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:445
char * savepoint_name
Definition: parsenodes.h:3199
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:8735
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:3399
const char * p_sourcetext
Definition: parse_node.h:181
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:413
char * conditionname
Definition: parsenodes.h:3163
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:759
void BeginTransactionBlock(void)
Definition: xact.c:3657
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:8525
void CommandCounterIncrement(void)
Definition: xact.c:1022
void ReleaseSavepoint(const char *name)
Definition: xact.c:4191
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:855
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:3152
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:79
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1441
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1466
#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:2337
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:804
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:833
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:408
#define nodeTag(nodeptr)
Definition: nodes.h:542
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:625
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:2028
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:199
void DropRole(DropRoleStmt *stmt)
Definition: user.c:936
char * defname
Definition: parsenodes.h:758
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:3937
#define copyObject(obj)
Definition: nodes.h:653
#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:3465
void Async_Unlisten(const char *channel)
Definition: async.c:786
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8878
void RequestCheckpoint(int flags)
Definition: checkpointer.c:920
char * payload
Definition: parsenodes.h:3153
TransactionStmtKind kind
Definition: parsenodes.h:3197
void ExecuteDoStmt(ParseState *pstate, DoStmt *stmt, bool atomic)
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:360
char * conditionname
Definition: parsenodes.h:3173
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1016

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

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

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

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

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

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

2061 {
2062  switch (nodeTag(parsetree))
2063  {
2064  case T_CallStmt:
2065  return CallStmtResultDesc((CallStmt *) parsetree);
2066 
2067  case T_FetchStmt:
2068  {
2069  FetchStmt *stmt = (FetchStmt *) parsetree;
2070  Portal portal;
2071 
2072  if (stmt->ismove)
2073  return NULL;
2074  portal = GetPortalByName(stmt->portalname);
2075  if (!PortalIsValid(portal))
2076  return NULL; /* not our business to raise error */
2077  return CreateTupleDescCopy(portal->tupDesc);
2078  }
2079 
2080  case T_ExecuteStmt:
2081  {
2082  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2083  PreparedStatement *entry;
2084 
2085  entry = FetchPreparedStatement(stmt->name, false);
2086  if (!entry)
2087  return NULL; /* not our business to raise error */
2088  return FetchPreparedStatementResultDesc(entry);
2089  }
2090 
2091  case T_ExplainStmt:
2092  return ExplainResultDesc((ExplainStmt *) parsetree);
2093 
2094  case T_VariableShowStmt:
2095  {
2096  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2097 
2098  return GetPGVariableResultDesc(n->name);
2099  }
2100 
2101  default:
2102  return NULL;
2103  }
2104 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:9361
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:2870
#define PortalIsValid(p)
Definition: portal.h:212
bool ismove
Definition: parsenodes.h:2871
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:500
TupleDesc tupDesc
Definition: portal.h:160
#define nodeTag(nodeptr)
Definition: nodes.h:542
char * name
Definition: parsenodes.h:3564
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().