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

Go to the source code of this file.

Data Structures

struct  AlterTableUtilityContext
 

Macros

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

Typedefs

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

Enumerations

enum  ProcessUtilityContext { PROCESS_UTILITY_TOPLEVEL, PROCESS_UTILITY_QUERY, PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_SUBCOMMAND }
 

Functions

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

Variables

PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
 

Macro Definition Documentation

◆ COMMAND_IS_NOT_READ_ONLY

#define COMMAND_IS_NOT_READ_ONLY   0

Definition at line 68 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly().

◆ COMMAND_IS_STRICTLY_READ_ONLY

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

Definition at line 65 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

◆ COMMAND_OK_IN_PARALLEL_MODE

#define COMMAND_OK_IN_PARALLEL_MODE   0x0002

Definition at line 57 of file utility.h.

Referenced by standard_ProcessUtility().

◆ COMMAND_OK_IN_READ_ONLY_TXN

#define COMMAND_OK_IN_READ_ONLY_TXN   0x0001

Definition at line 56 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

◆ COMMAND_OK_IN_RECOVERY

#define COMMAND_OK_IN_RECOVERY   0x0004

Definition at line 58 of file utility.h.

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

Typedef Documentation

◆ AlterTableUtilityContext

◆ ProcessUtility_hook_type

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

Definition at line 71 of file utility.h.

Enumeration Type Documentation

◆ ProcessUtilityContext

Enumerator
PROCESS_UTILITY_TOPLEVEL 
PROCESS_UTILITY_QUERY 
PROCESS_UTILITY_QUERY_NONATOMIC 
PROCESS_UTILITY_SUBCOMMAND 

Definition at line 20 of file utility.h.

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

Function Documentation

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 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 99 of file utility.h.

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

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

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

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

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

◆ ProcessUtility()

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

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

509 {
510  Assert(IsA(pstmt, PlannedStmt));
511  Assert(pstmt->commandType == CMD_UTILITY);
512  Assert(queryString != NULL); /* required as of 8.4 */
513  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
514 
515  /*
516  * We provide a function hook variable that lets loadable plugins get
517  * control when ProcessUtility is called. Such a plugin would normally
518  * call standard_ProcessUtility().
519  */
521  (*ProcessUtility_hook) (pstmt, queryString,
522  context, params, queryEnv,
523  dest, qc);
524  else
525  standard_ProcessUtility(pstmt, queryString,
526  context, params, queryEnv,
527  dest, qc);
528 }
#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, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:542
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 1896 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().

1897 {
1898  PlannedStmt *wrapper;
1899 
1900  /*
1901  * For event triggers, we must "close" the current complex-command set,
1902  * and start a new one afterwards; this is needed to ensure the ordering
1903  * of command events is consistent with the way they were executed.
1904  */
1906 
1907  /* Create a suitable wrapper */
1908  wrapper = makeNode(PlannedStmt);
1909  wrapper->commandType = CMD_UTILITY;
1910  wrapper->canSetTag = false;
1911  wrapper->utilityStmt = stmt;
1912  wrapper->stmt_location = context->pstmt->stmt_location;
1913  wrapper->stmt_len = context->pstmt->stmt_len;
1914 
1915  ProcessUtility(wrapper,
1916  context->queryString,
1918  context->params,
1919  context->queryEnv,
1920  None_Receiver,
1921  NULL);
1922 
1925 }
PlannedStmt * pstmt
Definition: utility.h:32
DestReceiver * None_Receiver
Definition: dest.c:96
int stmt_len
Definition: plannodes.h:90
void EventTriggerAlterTableStart(Node *parsetree)
int stmt_location
Definition: plannodes.h:89
Node * utilityStmt
Definition: plannodes.h:86
const char * queryString
Definition: utility.h:33
QueryEnvironment * queryEnv
Definition: utility.h:36
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define makeNode(_type_)
Definition: nodes.h:587
void EventTriggerAlterTableRelid(Oid objectId)
ParamListInfo params
Definition: utility.h:35
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:502
void EventTriggerAlterTableEnd(void)

◆ standard_ProcessUtility()

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

Definition at line 542 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, TransactionStmt::chain, check_stack_depth(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), ClassifyUtilityCommandAsReadOnly(), closeAllVfds(), cluster(), COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_PARALLEL_MODE, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, CommandCounterIncrement(), CommentObject(), NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), 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().

549 {
550  Node *parsetree = pstmt->utilityStmt;
551  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
552  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
553  ParseState *pstate;
554  int readonly_flags;
555 
556  /* This can recurse, so check for excessive recursion */
558 
559  /* Prohibit read/write commands in read-only states. */
560  readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
561  if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
563  {
564  CommandTag commandtag = CreateCommandTag(parsetree);
565 
566  if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
568  if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
570  if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
572  }
573 
574  pstate = make_parsestate(NULL);
575  pstate->p_sourcetext = queryString;
576  pstate->p_queryEnv = queryEnv;
577 
578  switch (nodeTag(parsetree))
579  {
580  /*
581  * ******************** transactions ********************
582  */
583  case T_TransactionStmt:
584  {
585  TransactionStmt *stmt = (TransactionStmt *) parsetree;
586 
587  switch (stmt->kind)
588  {
589  /*
590  * START TRANSACTION, as defined by SQL99: Identical
591  * to BEGIN. Same code for both.
592  */
593  case TRANS_STMT_BEGIN:
594  case TRANS_STMT_START:
595  {
596  ListCell *lc;
597 
599  foreach(lc, stmt->options)
600  {
601  DefElem *item = (DefElem *) lfirst(lc);
602 
603  if (strcmp(item->defname, "transaction_isolation") == 0)
604  SetPGVariable("transaction_isolation",
605  list_make1(item->arg),
606  true);
607  else if (strcmp(item->defname, "transaction_read_only") == 0)
608  SetPGVariable("transaction_read_only",
609  list_make1(item->arg),
610  true);
611  else if (strcmp(item->defname, "transaction_deferrable") == 0)
612  SetPGVariable("transaction_deferrable",
613  list_make1(item->arg),
614  true);
615  }
616  }
617  break;
618 
619  case TRANS_STMT_COMMIT:
620  if (!EndTransactionBlock(stmt->chain))
621  {
622  /* report unsuccessful commit in qc */
623  if (qc)
624  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
625  }
626  break;
627 
628  case TRANS_STMT_PREPARE:
629  if (!PrepareTransactionBlock(stmt->gid))
630  {
631  /* report unsuccessful commit in qc */
632  if (qc)
633  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
634  }
635  break;
636 
638  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
639  FinishPreparedTransaction(stmt->gid, true);
640  break;
641 
643  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
644  FinishPreparedTransaction(stmt->gid, false);
645  break;
646 
647  case TRANS_STMT_ROLLBACK:
649  break;
650 
652  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
654  break;
655 
656  case TRANS_STMT_RELEASE:
657  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
659  break;
660 
662  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
664 
665  /*
666  * CommitTransactionCommand is in charge of
667  * re-defining the savepoint again
668  */
669  break;
670  }
671  }
672  break;
673 
674  /*
675  * Portal (cursor) manipulation
676  */
677  case T_DeclareCursorStmt:
678  PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
679  isTopLevel);
680  break;
681 
682  case T_ClosePortalStmt:
683  {
684  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
685 
686  CheckRestrictedOperation("CLOSE");
688  }
689  break;
690 
691  case T_FetchStmt:
692  PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
693  break;
694 
695  case T_DoStmt:
696  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
697  break;
698 
700  /* no event triggers for global objects */
701  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
702  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
703  break;
704 
706  /* no event triggers for global objects */
707  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
708  DropTableSpace((DropTableSpaceStmt *) parsetree);
709  break;
710 
712  /* no event triggers for global objects */
714  break;
715 
716  case T_TruncateStmt:
717  ExecuteTruncate((TruncateStmt *) parsetree);
718  break;
719 
720  case T_CopyStmt:
721  {
722  uint64 processed;
723 
724  DoCopy(pstate, (CopyStmt *) parsetree,
725  pstmt->stmt_location, pstmt->stmt_len,
726  &processed);
727  if (qc)
728  SetQueryCompletion(qc, CMDTAG_COPY, processed);
729  }
730  break;
731 
732  case T_PrepareStmt:
733  CheckRestrictedOperation("PREPARE");
734  PrepareQuery(pstate, (PrepareStmt *) parsetree,
735  pstmt->stmt_location, pstmt->stmt_len);
736  break;
737 
738  case T_ExecuteStmt:
739  ExecuteQuery(pstate,
740  (ExecuteStmt *) parsetree, NULL,
741  params,
742  dest, qc);
743  break;
744 
745  case T_DeallocateStmt:
746  CheckRestrictedOperation("DEALLOCATE");
747  DeallocateQuery((DeallocateStmt *) parsetree);
748  break;
749 
750  case T_GrantRoleStmt:
751  /* no event triggers for global objects */
752  GrantRole((GrantRoleStmt *) parsetree);
753  break;
754 
755  case T_CreatedbStmt:
756  /* no event triggers for global objects */
757  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
758  createdb(pstate, (CreatedbStmt *) parsetree);
759  break;
760 
761  case T_AlterDatabaseStmt:
762  /* no event triggers for global objects */
763  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
764  break;
765 
767  /* no event triggers for global objects */
768  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
769  break;
770 
771  case T_DropdbStmt:
772  /* no event triggers for global objects */
773  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
774  DropDatabase(pstate, (DropdbStmt *) parsetree);
775  break;
776 
777  /* Query-level asynchronous notification */
778  case T_NotifyStmt:
779  {
780  NotifyStmt *stmt = (NotifyStmt *) parsetree;
781 
782  Async_Notify(stmt->conditionname, stmt->payload);
783  }
784  break;
785 
786  case T_ListenStmt:
787  {
788  ListenStmt *stmt = (ListenStmt *) parsetree;
789 
790  CheckRestrictedOperation("LISTEN");
792  }
793  break;
794 
795  case T_UnlistenStmt:
796  {
797  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
798 
799  CheckRestrictedOperation("UNLISTEN");
800  if (stmt->conditionname)
802  else
804  }
805  break;
806 
807  case T_LoadStmt:
808  {
809  LoadStmt *stmt = (LoadStmt *) parsetree;
810 
811  closeAllVfds(); /* probably not necessary... */
812  /* Allowed names are restricted if you're not superuser */
813  load_file(stmt->filename, !superuser());
814  }
815  break;
816 
817  case T_CallStmt:
818  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
819  break;
820 
821  case T_ClusterStmt:
822  cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
823  break;
824 
825  case T_VacuumStmt:
826  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
827  break;
828 
829  case T_ExplainStmt:
830  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
831  break;
832 
833  case T_AlterSystemStmt:
834  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
836  break;
837 
838  case T_VariableSetStmt:
839  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
840  break;
841 
842  case T_VariableShowStmt:
843  {
844  VariableShowStmt *n = (VariableShowStmt *) parsetree;
845 
846  GetPGVariable(n->name, dest);
847  }
848  break;
849 
850  case T_DiscardStmt:
851  /* should we allow DISCARD PLANS? */
852  CheckRestrictedOperation("DISCARD");
853  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
854  break;
855 
857  /* no event triggers on event triggers */
859  break;
860 
862  /* no event triggers on event triggers */
863  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
864  break;
865 
866  /*
867  * ******************************** ROLE statements ****
868  */
869  case T_CreateRoleStmt:
870  /* no event triggers for global objects */
871  CreateRole(pstate, (CreateRoleStmt *) parsetree);
872  break;
873 
874  case T_AlterRoleStmt:
875  /* no event triggers for global objects */
876  AlterRole((AlterRoleStmt *) parsetree);
877  break;
878 
879  case T_AlterRoleSetStmt:
880  /* no event triggers for global objects */
881  AlterRoleSet((AlterRoleSetStmt *) parsetree);
882  break;
883 
884  case T_DropRoleStmt:
885  /* no event triggers for global objects */
886  DropRole((DropRoleStmt *) parsetree);
887  break;
888 
889  case T_ReassignOwnedStmt:
890  /* no event triggers for global objects */
892  break;
893 
894  case T_LockStmt:
895 
896  /*
897  * Since the lock would just get dropped immediately, LOCK TABLE
898  * outside a transaction block is presumed to be user error.
899  */
900  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
901  LockTableCommand((LockStmt *) parsetree);
902  break;
903 
905  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
907  break;
908 
909  case T_CheckPointStmt:
910  if (!superuser())
911  ereport(ERROR,
912  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
913  errmsg("must be superuser to do CHECKPOINT")));
914 
917  break;
918 
919  case T_ReindexStmt:
920  ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
921  break;
922 
923  /*
924  * The following statements are supported by Event Triggers only
925  * in some cases, so we "fast path" them in the other cases.
926  */
927 
928  case T_GrantStmt:
929  {
930  GrantStmt *stmt = (GrantStmt *) parsetree;
931 
933  ProcessUtilitySlow(pstate, pstmt, queryString,
934  context, params, queryEnv,
935  dest, qc);
936  else
937  ExecuteGrantStmt(stmt);
938  }
939  break;
940 
941  case T_DropStmt:
942  {
943  DropStmt *stmt = (DropStmt *) parsetree;
944 
946  ProcessUtilitySlow(pstate, pstmt, queryString,
947  context, params, queryEnv,
948  dest, qc);
949  else
950  ExecDropStmt(stmt, isTopLevel);
951  }
952  break;
953 
954  case T_RenameStmt:
955  {
956  RenameStmt *stmt = (RenameStmt *) parsetree;
957 
959  ProcessUtilitySlow(pstate, pstmt, queryString,
960  context, params, queryEnv,
961  dest, qc);
962  else
963  ExecRenameStmt(stmt);
964  }
965  break;
966 
968  {
969  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
970 
972  ProcessUtilitySlow(pstate, pstmt, queryString,
973  context, params, queryEnv,
974  dest, qc);
975  else
976  ExecAlterObjectDependsStmt(stmt, NULL);
977  }
978  break;
979 
981  {
982  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
983 
985  ProcessUtilitySlow(pstate, pstmt, queryString,
986  context, params, queryEnv,
987  dest, qc);
988  else
989  ExecAlterObjectSchemaStmt(stmt, NULL);
990  }
991  break;
992 
993  case T_AlterOwnerStmt:
994  {
995  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
996 
998  ProcessUtilitySlow(pstate, pstmt, queryString,
999  context, params, queryEnv,
1000  dest, qc);
1001  else
1002  ExecAlterOwnerStmt(stmt);
1003  }
1004  break;
1005 
1006  case T_CommentStmt:
1007  {
1008  CommentStmt *stmt = (CommentStmt *) parsetree;
1009 
1011  ProcessUtilitySlow(pstate, pstmt, queryString,
1012  context, params, queryEnv,
1013  dest, qc);
1014  else
1015  CommentObject(stmt);
1016  break;
1017  }
1018 
1019  case T_SecLabelStmt:
1020  {
1021  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1022 
1024  ProcessUtilitySlow(pstate, pstmt, queryString,
1025  context, params, queryEnv,
1026  dest, qc);
1027  else
1028  ExecSecLabelStmt(stmt);
1029  break;
1030  }
1031 
1032  default:
1033  /* All other statement types have event trigger support */
1034  ProcessUtilitySlow(pstate, pstmt, queryString,
1035  context, params, queryEnv,
1036  dest, qc);
1037  break;
1038  }
1039 
1040  free_parsestate(pstate);
1041 
1042  /*
1043  * Make effects of commands visible, for instance so that
1044  * PreCommit_on_commit_actions() can see them (see for example bug
1045  * #15631).
1046  */
1048 }
ObjectType objtype
Definition: parsenodes.h:2759
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:2811
ObjectType objtype
Definition: parsenodes.h:2771
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1931
void PerformPortalClose(const char *name)
Definition: portalcmds.c:220
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:3014
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:2480
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1650
ObjectType objectType
Definition: parsenodes.h:3060
void DefineSavepoint(const char *name)
Definition: xact.c:4086
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5062
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:3240
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:8237
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree)
Definition: utility.c:133
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1619
int stmt_len
Definition: plannodes.h:90
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:71
ObjectType removeType
Definition: parsenodes.h:2734
void RollbackToSavepoint(const char *name)
Definition: xact.c:4280
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:9333
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:1056
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:538
#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:3158
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1314
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:173
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:8715
int stmt_location
Definition: plannodes.h:89
void check_stack_depth(void)
Definition: postgres.c:3441
void ExecuteQuery(ParseState *pstate, ExecuteStmt *stmt, IntoClause *intoClause, ParamListInfo params, DestReceiver *dest, QueryCompletion *qc)
Definition: prepare.c:187
Node * utilityStmt
Definition: plannodes.h:86
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3379
void ExecuteDoStmt(DoStmt *stmt, bool atomic)
const char * p_sourcetext
Definition: parse_node.h:181
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:413
char * conditionname
Definition: parsenodes.h:3122
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:331
#define CHECKPOINT_FORCE
Definition: xlog.h:235
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
Node * arg
Definition: parsenodes.h:747
void BeginTransactionBlock(void)
Definition: xact.c:3637
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:531
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:8505
void CommandCounterIncrement(void)
Definition: xact.c:1021
void ReleaseSavepoint(const char *name)
Definition: xact.c:4171
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:915
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:3111
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:1471
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1411
#define CHECKPOINT_WAIT
Definition: xlog.h:239
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:2297
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:1399
#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:2006
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:234
void DropRole(DropRoleStmt *stmt)
Definition: user.c:996
char * defname
Definition: parsenodes.h:746
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:3917
#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:1446
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:8859
void RequestCheckpoint(int flags)
Definition: checkpointer.c:927
char * payload
Definition: parsenodes.h:3112
TransactionStmtKind kind
Definition: parsenodes.h:3156
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:359
char * conditionname
Definition: parsenodes.h:3132
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1022

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

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

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

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

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

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

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

Variable Documentation

◆ ProcessUtility_hook

Definition at line 76 of file utility.c.

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