PostgreSQL Source Code  git master
utility.h File Reference
#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, char *completionTag)
 

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, char *completionTag)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
const char * CreateCommandTag (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 67 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:57
#define COMMAND_OK_IN_READ_ONLY_TXN
Definition: utility.h:55

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

Referenced by ClassifyUtilityCommandAsReadOnly(), and standard_ProcessUtility().

◆ COMMAND_OK_IN_RECOVERY

#define COMMAND_OK_IN_RECOVERY   0x0004

Definition at line 57 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, char *completionTag)

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

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

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(), 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:576
#define WARNING
Definition: elog.h:40
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:84
#define Assert(condition)
Definition: c.h:739
bool hasModifyingCTE
Definition: plannodes.h:52
#define elog(elevel,...)
Definition: elog.h:228

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2252 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, relkind, 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_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, PlannedStmt::utilityStmt, Query::utilityStmt, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WARNING.

Referenced by _SPI_execute_plan(), _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), CreateCommandTag(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), ExecCheckXactReadOnly(), get_command_tag(), init_execution_state(), pg_event_trigger_ddl_commands(), PrepareQuery(), SPI_cursor_open_internal(), and standard_ProcessUtility().

2253 {
2254  const char *tag;
2255 
2256  switch (nodeTag(parsetree))
2257  {
2258  /* recurse if we're given a RawStmt */
2259  case T_RawStmt:
2260  tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2261  break;
2262 
2263  /* raw plannable queries */
2264  case T_InsertStmt:
2265  tag = "INSERT";
2266  break;
2267 
2268  case T_DeleteStmt:
2269  tag = "DELETE";
2270  break;
2271 
2272  case T_UpdateStmt:
2273  tag = "UPDATE";
2274  break;
2275 
2276  case T_SelectStmt:
2277  tag = "SELECT";
2278  break;
2279 
2280  /* utility statements --- same whether raw or cooked */
2281  case T_TransactionStmt:
2282  {
2283  TransactionStmt *stmt = (TransactionStmt *) parsetree;
2284 
2285  switch (stmt->kind)
2286  {
2287  case TRANS_STMT_BEGIN:
2288  tag = "BEGIN";
2289  break;
2290 
2291  case TRANS_STMT_START:
2292  tag = "START TRANSACTION";
2293  break;
2294 
2295  case TRANS_STMT_COMMIT:
2296  tag = "COMMIT";
2297  break;
2298 
2299  case TRANS_STMT_ROLLBACK:
2301  tag = "ROLLBACK";
2302  break;
2303 
2304  case TRANS_STMT_SAVEPOINT:
2305  tag = "SAVEPOINT";
2306  break;
2307 
2308  case TRANS_STMT_RELEASE:
2309  tag = "RELEASE";
2310  break;
2311 
2312  case TRANS_STMT_PREPARE:
2313  tag = "PREPARE TRANSACTION";
2314  break;
2315 
2317  tag = "COMMIT PREPARED";
2318  break;
2319 
2321  tag = "ROLLBACK PREPARED";
2322  break;
2323 
2324  default:
2325  tag = "???";
2326  break;
2327  }
2328  }
2329  break;
2330 
2331  case T_DeclareCursorStmt:
2332  tag = "DECLARE CURSOR";
2333  break;
2334 
2335  case T_ClosePortalStmt:
2336  {
2337  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2338 
2339  if (stmt->portalname == NULL)
2340  tag = "CLOSE CURSOR ALL";
2341  else
2342  tag = "CLOSE CURSOR";
2343  }
2344  break;
2345 
2346  case T_FetchStmt:
2347  {
2348  FetchStmt *stmt = (FetchStmt *) parsetree;
2349 
2350  tag = (stmt->ismove) ? "MOVE" : "FETCH";
2351  }
2352  break;
2353 
2354  case T_CreateDomainStmt:
2355  tag = "CREATE DOMAIN";
2356  break;
2357 
2358  case T_CreateSchemaStmt:
2359  tag = "CREATE SCHEMA";
2360  break;
2361 
2362  case T_CreateStmt:
2363  tag = "CREATE TABLE";
2364  break;
2365 
2367  tag = "CREATE TABLESPACE";
2368  break;
2369 
2370  case T_DropTableSpaceStmt:
2371  tag = "DROP TABLESPACE";
2372  break;
2373 
2375  tag = "ALTER TABLESPACE";
2376  break;
2377 
2378  case T_CreateExtensionStmt:
2379  tag = "CREATE EXTENSION";
2380  break;
2381 
2382  case T_AlterExtensionStmt:
2383  tag = "ALTER EXTENSION";
2384  break;
2385 
2387  tag = "ALTER EXTENSION";
2388  break;
2389 
2390  case T_CreateFdwStmt:
2391  tag = "CREATE FOREIGN DATA WRAPPER";
2392  break;
2393 
2394  case T_AlterFdwStmt:
2395  tag = "ALTER FOREIGN DATA WRAPPER";
2396  break;
2397 
2399  tag = "CREATE SERVER";
2400  break;
2401 
2403  tag = "ALTER SERVER";
2404  break;
2405 
2407  tag = "CREATE USER MAPPING";
2408  break;
2409 
2411  tag = "ALTER USER MAPPING";
2412  break;
2413 
2414  case T_DropUserMappingStmt:
2415  tag = "DROP USER MAPPING";
2416  break;
2417 
2419  tag = "CREATE FOREIGN TABLE";
2420  break;
2421 
2423  tag = "IMPORT FOREIGN SCHEMA";
2424  break;
2425 
2426  case T_DropStmt:
2427  switch (((DropStmt *) parsetree)->removeType)
2428  {
2429  case OBJECT_TABLE:
2430  tag = "DROP TABLE";
2431  break;
2432  case OBJECT_SEQUENCE:
2433  tag = "DROP SEQUENCE";
2434  break;
2435  case OBJECT_VIEW:
2436  tag = "DROP VIEW";
2437  break;
2438  case OBJECT_MATVIEW:
2439  tag = "DROP MATERIALIZED VIEW";
2440  break;
2441  case OBJECT_INDEX:
2442  tag = "DROP INDEX";
2443  break;
2444  case OBJECT_TYPE:
2445  tag = "DROP TYPE";
2446  break;
2447  case OBJECT_DOMAIN:
2448  tag = "DROP DOMAIN";
2449  break;
2450  case OBJECT_COLLATION:
2451  tag = "DROP COLLATION";
2452  break;
2453  case OBJECT_CONVERSION:
2454  tag = "DROP CONVERSION";
2455  break;
2456  case OBJECT_SCHEMA:
2457  tag = "DROP SCHEMA";
2458  break;
2459  case OBJECT_TSPARSER:
2460  tag = "DROP TEXT SEARCH PARSER";
2461  break;
2462  case OBJECT_TSDICTIONARY:
2463  tag = "DROP TEXT SEARCH DICTIONARY";
2464  break;
2465  case OBJECT_TSTEMPLATE:
2466  tag = "DROP TEXT SEARCH TEMPLATE";
2467  break;
2469  tag = "DROP TEXT SEARCH CONFIGURATION";
2470  break;
2471  case OBJECT_FOREIGN_TABLE:
2472  tag = "DROP FOREIGN TABLE";
2473  break;
2474  case OBJECT_EXTENSION:
2475  tag = "DROP EXTENSION";
2476  break;
2477  case OBJECT_FUNCTION:
2478  tag = "DROP FUNCTION";
2479  break;
2480  case OBJECT_PROCEDURE:
2481  tag = "DROP PROCEDURE";
2482  break;
2483  case OBJECT_ROUTINE:
2484  tag = "DROP ROUTINE";
2485  break;
2486  case OBJECT_AGGREGATE:
2487  tag = "DROP AGGREGATE";
2488  break;
2489  case OBJECT_OPERATOR:
2490  tag = "DROP OPERATOR";
2491  break;
2492  case OBJECT_LANGUAGE:
2493  tag = "DROP LANGUAGE";
2494  break;
2495  case OBJECT_CAST:
2496  tag = "DROP CAST";
2497  break;
2498  case OBJECT_TRIGGER:
2499  tag = "DROP TRIGGER";
2500  break;
2501  case OBJECT_EVENT_TRIGGER:
2502  tag = "DROP EVENT TRIGGER";
2503  break;
2504  case OBJECT_RULE:
2505  tag = "DROP RULE";
2506  break;
2507  case OBJECT_FDW:
2508  tag = "DROP FOREIGN DATA WRAPPER";
2509  break;
2510  case OBJECT_FOREIGN_SERVER:
2511  tag = "DROP SERVER";
2512  break;
2513  case OBJECT_OPCLASS:
2514  tag = "DROP OPERATOR CLASS";
2515  break;
2516  case OBJECT_OPFAMILY:
2517  tag = "DROP OPERATOR FAMILY";
2518  break;
2519  case OBJECT_POLICY:
2520  tag = "DROP POLICY";
2521  break;
2522  case OBJECT_TRANSFORM:
2523  tag = "DROP TRANSFORM";
2524  break;
2525  case OBJECT_ACCESS_METHOD:
2526  tag = "DROP ACCESS METHOD";
2527  break;
2528  case OBJECT_PUBLICATION:
2529  tag = "DROP PUBLICATION";
2530  break;
2531  case OBJECT_STATISTIC_EXT:
2532  tag = "DROP STATISTICS";
2533  break;
2534  default:
2535  tag = "???";
2536  }
2537  break;
2538 
2539  case T_TruncateStmt:
2540  tag = "TRUNCATE TABLE";
2541  break;
2542 
2543  case T_CommentStmt:
2544  tag = "COMMENT";
2545  break;
2546 
2547  case T_SecLabelStmt:
2548  tag = "SECURITY LABEL";
2549  break;
2550 
2551  case T_CopyStmt:
2552  tag = "COPY";
2553  break;
2554 
2555  case T_RenameStmt:
2556 
2557  /*
2558  * When the column is renamed, the command tag is created from its
2559  * relation type
2560  */
2562  ((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
2563  ((RenameStmt *) parsetree)->relationType :
2564  ((RenameStmt *) parsetree)->renameType);
2565  break;
2566 
2568  tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2569  break;
2570 
2572  tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2573  break;
2574 
2575  case T_AlterOwnerStmt:
2576  tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2577  break;
2578 
2580  tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2581  break;
2582 
2583  case T_AlterTableStmt:
2584  tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
2585  break;
2586 
2587  case T_AlterDomainStmt:
2588  tag = "ALTER DOMAIN";
2589  break;
2590 
2591  case T_AlterFunctionStmt:
2592  switch (((AlterFunctionStmt *) parsetree)->objtype)
2593  {
2594  case OBJECT_FUNCTION:
2595  tag = "ALTER FUNCTION";
2596  break;
2597  case OBJECT_PROCEDURE:
2598  tag = "ALTER PROCEDURE";
2599  break;
2600  case OBJECT_ROUTINE:
2601  tag = "ALTER ROUTINE";
2602  break;
2603  default:
2604  tag = "???";
2605  }
2606  break;
2607 
2608  case T_GrantStmt:
2609  {
2610  GrantStmt *stmt = (GrantStmt *) parsetree;
2611 
2612  tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
2613  }
2614  break;
2615 
2616  case T_GrantRoleStmt:
2617  {
2618  GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2619 
2620  tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
2621  }
2622  break;
2623 
2625  tag = "ALTER DEFAULT PRIVILEGES";
2626  break;
2627 
2628  case T_DefineStmt:
2629  switch (((DefineStmt *) parsetree)->kind)
2630  {
2631  case OBJECT_AGGREGATE:
2632  tag = "CREATE AGGREGATE";
2633  break;
2634  case OBJECT_OPERATOR:
2635  tag = "CREATE OPERATOR";
2636  break;
2637  case OBJECT_TYPE:
2638  tag = "CREATE TYPE";
2639  break;
2640  case OBJECT_TSPARSER:
2641  tag = "CREATE TEXT SEARCH PARSER";
2642  break;
2643  case OBJECT_TSDICTIONARY:
2644  tag = "CREATE TEXT SEARCH DICTIONARY";
2645  break;
2646  case OBJECT_TSTEMPLATE:
2647  tag = "CREATE TEXT SEARCH TEMPLATE";
2648  break;
2650  tag = "CREATE TEXT SEARCH CONFIGURATION";
2651  break;
2652  case OBJECT_COLLATION:
2653  tag = "CREATE COLLATION";
2654  break;
2655  case OBJECT_ACCESS_METHOD:
2656  tag = "CREATE ACCESS METHOD";
2657  break;
2658  default:
2659  tag = "???";
2660  }
2661  break;
2662 
2663  case T_CompositeTypeStmt:
2664  tag = "CREATE TYPE";
2665  break;
2666 
2667  case T_CreateEnumStmt:
2668  tag = "CREATE TYPE";
2669  break;
2670 
2671  case T_CreateRangeStmt:
2672  tag = "CREATE TYPE";
2673  break;
2674 
2675  case T_AlterEnumStmt:
2676  tag = "ALTER TYPE";
2677  break;
2678 
2679  case T_ViewStmt:
2680  tag = "CREATE VIEW";
2681  break;
2682 
2683  case T_CreateFunctionStmt:
2684  if (((CreateFunctionStmt *) parsetree)->is_procedure)
2685  tag = "CREATE PROCEDURE";
2686  else
2687  tag = "CREATE FUNCTION";
2688  break;
2689 
2690  case T_IndexStmt:
2691  tag = "CREATE INDEX";
2692  break;
2693 
2694  case T_RuleStmt:
2695  tag = "CREATE RULE";
2696  break;
2697 
2698  case T_CreateSeqStmt:
2699  tag = "CREATE SEQUENCE";
2700  break;
2701 
2702  case T_AlterSeqStmt:
2703  tag = "ALTER SEQUENCE";
2704  break;
2705 
2706  case T_DoStmt:
2707  tag = "DO";
2708  break;
2709 
2710  case T_CreatedbStmt:
2711  tag = "CREATE DATABASE";
2712  break;
2713 
2714  case T_AlterDatabaseStmt:
2715  tag = "ALTER DATABASE";
2716  break;
2717 
2719  tag = "ALTER DATABASE";
2720  break;
2721 
2722  case T_DropdbStmt:
2723  tag = "DROP DATABASE";
2724  break;
2725 
2726  case T_NotifyStmt:
2727  tag = "NOTIFY";
2728  break;
2729 
2730  case T_ListenStmt:
2731  tag = "LISTEN";
2732  break;
2733 
2734  case T_UnlistenStmt:
2735  tag = "UNLISTEN";
2736  break;
2737 
2738  case T_LoadStmt:
2739  tag = "LOAD";
2740  break;
2741 
2742  case T_CallStmt:
2743  tag = "CALL";
2744  break;
2745 
2746  case T_ClusterStmt:
2747  tag = "CLUSTER";
2748  break;
2749 
2750  case T_VacuumStmt:
2751  if (((VacuumStmt *) parsetree)->is_vacuumcmd)
2752  tag = "VACUUM";
2753  else
2754  tag = "ANALYZE";
2755  break;
2756 
2757  case T_ExplainStmt:
2758  tag = "EXPLAIN";
2759  break;
2760 
2761  case T_CreateTableAsStmt:
2762  switch (((CreateTableAsStmt *) parsetree)->relkind)
2763  {
2764  case OBJECT_TABLE:
2765  if (((CreateTableAsStmt *) parsetree)->is_select_into)
2766  tag = "SELECT INTO";
2767  else
2768  tag = "CREATE TABLE AS";
2769  break;
2770  case OBJECT_MATVIEW:
2771  tag = "CREATE MATERIALIZED VIEW";
2772  break;
2773  default:
2774  tag = "???";
2775  }
2776  break;
2777 
2778  case T_RefreshMatViewStmt:
2779  tag = "REFRESH MATERIALIZED VIEW";
2780  break;
2781 
2782  case T_AlterSystemStmt:
2783  tag = "ALTER SYSTEM";
2784  break;
2785 
2786  case T_VariableSetStmt:
2787  switch (((VariableSetStmt *) parsetree)->kind)
2788  {
2789  case VAR_SET_VALUE:
2790  case VAR_SET_CURRENT:
2791  case VAR_SET_DEFAULT:
2792  case VAR_SET_MULTI:
2793  tag = "SET";
2794  break;
2795  case VAR_RESET:
2796  case VAR_RESET_ALL:
2797  tag = "RESET";
2798  break;
2799  default:
2800  tag = "???";
2801  }
2802  break;
2803 
2804  case T_VariableShowStmt:
2805  tag = "SHOW";
2806  break;
2807 
2808  case T_DiscardStmt:
2809  switch (((DiscardStmt *) parsetree)->target)
2810  {
2811  case DISCARD_ALL:
2812  tag = "DISCARD ALL";
2813  break;
2814  case DISCARD_PLANS:
2815  tag = "DISCARD PLANS";
2816  break;
2817  case DISCARD_TEMP:
2818  tag = "DISCARD TEMP";
2819  break;
2820  case DISCARD_SEQUENCES:
2821  tag = "DISCARD SEQUENCES";
2822  break;
2823  default:
2824  tag = "???";
2825  }
2826  break;
2827 
2828  case T_CreateTransformStmt:
2829  tag = "CREATE TRANSFORM";
2830  break;
2831 
2832  case T_CreateTrigStmt:
2833  tag = "CREATE TRIGGER";
2834  break;
2835 
2836  case T_CreateEventTrigStmt:
2837  tag = "CREATE EVENT TRIGGER";
2838  break;
2839 
2840  case T_AlterEventTrigStmt:
2841  tag = "ALTER EVENT TRIGGER";
2842  break;
2843 
2844  case T_CreatePLangStmt:
2845  tag = "CREATE LANGUAGE";
2846  break;
2847 
2848  case T_CreateRoleStmt:
2849  tag = "CREATE ROLE";
2850  break;
2851 
2852  case T_AlterRoleStmt:
2853  tag = "ALTER ROLE";
2854  break;
2855 
2856  case T_AlterRoleSetStmt:
2857  tag = "ALTER ROLE";
2858  break;
2859 
2860  case T_DropRoleStmt:
2861  tag = "DROP ROLE";
2862  break;
2863 
2864  case T_DropOwnedStmt:
2865  tag = "DROP OWNED";
2866  break;
2867 
2868  case T_ReassignOwnedStmt:
2869  tag = "REASSIGN OWNED";
2870  break;
2871 
2872  case T_LockStmt:
2873  tag = "LOCK TABLE";
2874  break;
2875 
2876  case T_ConstraintsSetStmt:
2877  tag = "SET CONSTRAINTS";
2878  break;
2879 
2880  case T_CheckPointStmt:
2881  tag = "CHECKPOINT";
2882  break;
2883 
2884  case T_ReindexStmt:
2885  tag = "REINDEX";
2886  break;
2887 
2889  tag = "CREATE CONVERSION";
2890  break;
2891 
2892  case T_CreateCastStmt:
2893  tag = "CREATE CAST";
2894  break;
2895 
2896  case T_CreateOpClassStmt:
2897  tag = "CREATE OPERATOR CLASS";
2898  break;
2899 
2900  case T_CreateOpFamilyStmt:
2901  tag = "CREATE OPERATOR FAMILY";
2902  break;
2903 
2904  case T_AlterOpFamilyStmt:
2905  tag = "ALTER OPERATOR FAMILY";
2906  break;
2907 
2908  case T_AlterOperatorStmt:
2909  tag = "ALTER OPERATOR";
2910  break;
2911 
2913  tag = "ALTER TEXT SEARCH DICTIONARY";
2914  break;
2915 
2917  tag = "ALTER TEXT SEARCH CONFIGURATION";
2918  break;
2919 
2920  case T_CreatePolicyStmt:
2921  tag = "CREATE POLICY";
2922  break;
2923 
2924  case T_AlterPolicyStmt:
2925  tag = "ALTER POLICY";
2926  break;
2927 
2928  case T_CreateAmStmt:
2929  tag = "CREATE ACCESS METHOD";
2930  break;
2931 
2933  tag = "CREATE PUBLICATION";
2934  break;
2935 
2937  tag = "ALTER PUBLICATION";
2938  break;
2939 
2941  tag = "CREATE SUBSCRIPTION";
2942  break;
2943 
2945  tag = "ALTER SUBSCRIPTION";
2946  break;
2947 
2949  tag = "DROP SUBSCRIPTION";
2950  break;
2951 
2952  case T_AlterCollationStmt:
2953  tag = "ALTER COLLATION";
2954  break;
2955 
2956  case T_PrepareStmt:
2957  tag = "PREPARE";
2958  break;
2959 
2960  case T_ExecuteStmt:
2961  tag = "EXECUTE";
2962  break;
2963 
2964  case T_CreateStatsStmt:
2965  tag = "CREATE STATISTICS";
2966  break;
2967 
2968  case T_AlterStatsStmt:
2969  tag = "ALTER STATISTICS";
2970  break;
2971 
2972  case T_DeallocateStmt:
2973  {
2974  DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2975 
2976  if (stmt->name == NULL)
2977  tag = "DEALLOCATE ALL";
2978  else
2979  tag = "DEALLOCATE";
2980  }
2981  break;
2982 
2983  /* already-planned queries */
2984  case T_PlannedStmt:
2985  {
2986  PlannedStmt *stmt = (PlannedStmt *) parsetree;
2987 
2988  switch (stmt->commandType)
2989  {
2990  case CMD_SELECT:
2991 
2992  /*
2993  * We take a little extra care here so that the result
2994  * will be useful for complaints about read-only
2995  * statements
2996  */
2997  if (stmt->rowMarks != NIL)
2998  {
2999  /* not 100% but probably close enough */
3000  switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
3001  {
3002  case LCS_FORKEYSHARE:
3003  tag = "SELECT FOR KEY SHARE";
3004  break;
3005  case LCS_FORSHARE:
3006  tag = "SELECT FOR SHARE";
3007  break;
3008  case LCS_FORNOKEYUPDATE:
3009  tag = "SELECT FOR NO KEY UPDATE";
3010  break;
3011  case LCS_FORUPDATE:
3012  tag = "SELECT FOR UPDATE";
3013  break;
3014  default:
3015  tag = "SELECT";
3016  break;
3017  }
3018  }
3019  else
3020  tag = "SELECT";
3021  break;
3022  case CMD_UPDATE:
3023  tag = "UPDATE";
3024  break;
3025  case CMD_INSERT:
3026  tag = "INSERT";
3027  break;
3028  case CMD_DELETE:
3029  tag = "DELETE";
3030  break;
3031  case CMD_UTILITY:
3032  tag = CreateCommandTag(stmt->utilityStmt);
3033  break;
3034  default:
3035  elog(WARNING, "unrecognized commandType: %d",
3036  (int) stmt->commandType);
3037  tag = "???";
3038  break;
3039  }
3040  }
3041  break;
3042 
3043  /* parsed-and-rewritten-but-not-planned queries */
3044  case T_Query:
3045  {
3046  Query *stmt = (Query *) parsetree;
3047 
3048  switch (stmt->commandType)
3049  {
3050  case CMD_SELECT:
3051 
3052  /*
3053  * We take a little extra care here so that the result
3054  * will be useful for complaints about read-only
3055  * statements
3056  */
3057  if (stmt->rowMarks != NIL)
3058  {
3059  /* not 100% but probably close enough */
3060  switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
3061  {
3062  case LCS_FORKEYSHARE:
3063  tag = "SELECT FOR KEY SHARE";
3064  break;
3065  case LCS_FORSHARE:
3066  tag = "SELECT FOR SHARE";
3067  break;
3068  case LCS_FORNOKEYUPDATE:
3069  tag = "SELECT FOR NO KEY UPDATE";
3070  break;
3071  case LCS_FORUPDATE:
3072  tag = "SELECT FOR UPDATE";
3073  break;
3074  default:
3075  tag = "???";
3076  break;
3077  }
3078  }
3079  else
3080  tag = "SELECT";
3081  break;
3082  case CMD_UPDATE:
3083  tag = "UPDATE";
3084  break;
3085  case CMD_INSERT:
3086  tag = "INSERT";
3087  break;
3088  case CMD_DELETE:
3089  tag = "DELETE";
3090  break;
3091  case CMD_UTILITY:
3092  tag = CreateCommandTag(stmt->utilityStmt);
3093  break;
3094  default:
3095  elog(WARNING, "unrecognized commandType: %d",
3096  (int) stmt->commandType);
3097  tag = "???";
3098  break;
3099  }
3100  }
3101  break;
3102 
3103  default:
3104  elog(WARNING, "unrecognized node type: %d",
3105  (int) nodeTag(parsetree));
3106  tag = "???";
3107  break;
3108  }
3109 
3110  return tag;
3111 }
#define NIL
Definition: pg_list.h:65
List * rowMarks
Definition: parsenodes.h:163
Node * utilityStmt
Definition: parsenodes.h:120
char relkind
Definition: pg_class.h:81
#define linitial(l)
Definition: pg_list.h:195
Node * utilityStmt
Definition: plannodes.h:92
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2252
bool is_grant
Definition: parsenodes.h:1924
#define WARNING
Definition: elog.h:40
Definition: nodes.h:310
bool ismove
Definition: parsenodes.h:2755
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:84
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:530
#define elog(elevel,...)
Definition: elog.h:228
static const char * AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:2103
TransactionStmtKind kind
Definition: parsenodes.h:3043

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3124 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_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, PlannedStmt::utilityStmt, Query::utilityStmt, and WARNING.

Referenced by check_log_statement(), and GetCommandLogLevel().

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

◆ ProcessUtility()

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

Definition at line 504 of file utility.c.

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

Referenced by _SPI_execute_plan(), ConvertTriggerToFK(), 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 
516  /*
517  * We provide a function hook variable that lets loadable plugins get
518  * control when ProcessUtility is called. Such a plugin would normally
519  * call standard_ProcessUtility().
520  */
522  (*ProcessUtility_hook) (pstmt, queryString,
523  context, params, queryEnv,
524  dest, completionTag);
525  else
526  standard_ProcessUtility(pstmt, queryString,
527  context, params, queryEnv,
528  dest, completionTag);
529 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:75
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:543
CmdType commandType
Definition: plannodes.h:46
#define Assert(condition)
Definition: c.h:739

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

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

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

◆ standard_ProcessUtility()

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

Definition at line 543 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(), COMPLETION_TAG_BUFSIZE, ReindexStmt::concurrent, NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetPGVariable(), TransactionStmt::gid, GrantRole(), IsInParallelMode(), IsTransactionBlock(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), VariableShowStmt::name, ReindexStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ReindexStmt::options, ParseState::p_queryEnv, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), REINDEX_OBJECT_DATABASE, REINDEX_OBJECT_INDEX, REINDEX_OBJECT_SCHEMA, REINDEX_OBJECT_SYSTEM, REINDEX_OBJECT_TABLE, ReindexIndex(), ReindexMultipleTables(), ReindexTable(), ReindexStmt::relation, ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), snprintf, 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, UINT64_FORMAT, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

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

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

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

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

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

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

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

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

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

Variable Documentation

◆ ProcessUtility_hook

Definition at line 75 of file utility.c.

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