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

Go to the source code of this file.

Data Structures

struct  AlterTableUtilityContext
 

Macros

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

Typedefs

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

Enumerations

enum  ProcessUtilityContext { PROCESS_UTILITY_TOPLEVEL , PROCESS_UTILITY_QUERY , PROCESS_UTILITY_QUERY_NONATOMIC , PROCESS_UTILITY_SUBCOMMAND }
 

Functions

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

Variables

PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
 

Macro Definition Documentation

◆ COMMAND_IS_NOT_READ_ONLY

#define COMMAND_IS_NOT_READ_ONLY   0

Definition at line 68 of file utility.h.

◆ 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.

◆ COMMAND_OK_IN_PARALLEL_MODE

#define COMMAND_OK_IN_PARALLEL_MODE   0x0002

Definition at line 57 of file utility.h.

◆ COMMAND_OK_IN_READ_ONLY_TXN

#define COMMAND_OK_IN_READ_ONLY_TXN   0x0001

Definition at line 56 of file utility.h.

◆ COMMAND_OK_IN_RECOVERY

#define COMMAND_OK_IN_RECOVERY   0x0004

Definition at line 58 of file utility.h.

Typedef Documentation

◆ AlterTableUtilityContext

◆ ProcessUtility_hook_type

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

Definition at line 71 of file utility.h.

Enumeration Type Documentation

◆ ProcessUtilityContext

Enumerator
PROCESS_UTILITY_TOPLEVEL 
PROCESS_UTILITY_QUERY 
PROCESS_UTILITY_QUERY_NONATOMIC 
PROCESS_UTILITY_SUBCOMMAND 

Definition at line 20 of file utility.h.

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

Function Documentation

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 94 of file utility.c.

95 {
96  Assert(IsA(pstmt, PlannedStmt));
97  switch (pstmt->commandType)
98  {
99  case CMD_SELECT:
100  if (pstmt->rowMarks != NIL)
101  return false; /* SELECT FOR [KEY] UPDATE/SHARE */
102  else if (pstmt->hasModifyingCTE)
103  return false; /* data-modifying CTE */
104  else
105  return true;
106  case CMD_UPDATE:
107  case CMD_INSERT:
108  case CMD_DELETE:
109  case CMD_MERGE:
110  return false;
111  case CMD_UTILITY:
112  /* For now, treat all utility commands as read/write */
113  return false;
114  default:
115  elog(WARNING, "unrecognized commandType: %d",
116  (int) pstmt->commandType);
117  break;
118  }
119  return false;
120 }
#define Assert(condition)
Definition: c.h:858
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:224
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
@ CMD_MERGE
Definition: nodes.h:269
@ CMD_UTILITY
Definition: nodes.h:270
@ CMD_INSERT
Definition: nodes.h:267
@ CMD_DELETE
Definition: nodes.h:268
@ CMD_UPDATE
Definition: nodes.h:266
@ CMD_SELECT
Definition: nodes.h:265
#define NIL
Definition: pg_list.h:68
bool hasModifyingCTE
Definition: plannodes.h:58
List * rowMarks
Definition: plannodes.h:87
CmdType commandType
Definition: plannodes.h:52

References Assert, CMD_DELETE, CMD_INSERT, CMD_MERGE, 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().

◆ CreateCommandName()

static const char* CreateCommandName ( Node parsetree)
inlinestatic

Definition at line 103 of file utility.h.

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

References CreateCommandTag(), and GetCommandTagName().

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

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2359 of file utility.c.

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

References AlterObjectTypeCommandTag(), CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, DISCARD_TEMP, elog, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, linitial, 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, stmt, 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, 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(), EventTriggerGetTag(), exec_parse_message(), exec_simple_query(), interpret_AS_clause(), PrepareQuery(), REGRESS_utility_command(), and standard_ProcessUtility().

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3246 of file utility.c.

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

References analyze(), CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, defGetBoolean(), DefElem::defname, elog, FetchPreparedStatement(), lfirst, LOGSTMT_ALL, LOGSTMT_DDL, LOGSTMT_MOD, nodeTag, ps, stmt, and WARNING.

Referenced by check_log_statement().

◆ ProcessUtility()

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

Definition at line 499 of file utility.c.

507 {
508  Assert(IsA(pstmt, PlannedStmt));
509  Assert(pstmt->commandType == CMD_UTILITY);
510  Assert(queryString != NULL); /* required as of 8.4 */
511  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
512 
513  /*
514  * We provide a function hook variable that lets loadable plugins get
515  * control when ProcessUtility is called. Such a plugin would normally
516  * call standard_ProcessUtility().
517  */
519  (*ProcessUtility_hook) (pstmt, queryString, readOnlyTree,
520  context, params, queryEnv,
521  dest, qc);
522  else
523  standard_ProcessUtility(pstmt, queryString, readOnlyTree,
524  context, params, queryEnv,
525  dest, qc);
526 }
tree context
Definition: radixtree.h:1833
CommandTag commandTag
Definition: cmdtag.h:31
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:540
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:70

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

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

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1956 of file utility.c.

1957 {
1958  PlannedStmt *wrapper;
1959 
1960  /*
1961  * For event triggers, we must "close" the current complex-command set,
1962  * and start a new one afterwards; this is needed to ensure the ordering
1963  * of command events is consistent with the way they were executed.
1964  */
1966 
1967  /* Create a suitable wrapper */
1968  wrapper = makeNode(PlannedStmt);
1969  wrapper->commandType = CMD_UTILITY;
1970  wrapper->canSetTag = false;
1971  wrapper->utilityStmt = stmt;
1972  wrapper->stmt_location = context->pstmt->stmt_location;
1973  wrapper->stmt_len = context->pstmt->stmt_len;
1974 
1975  ProcessUtility(wrapper,
1976  context->queryString,
1977  false,
1979  context->params,
1980  context->queryEnv,
1981  None_Receiver,
1982  NULL);
1983 
1984  EventTriggerAlterTableStart(context->pstmt->utilityStmt);
1986 }
DestReceiver * None_Receiver
Definition: dest.c:96
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerAlterTableEnd(void)
#define makeNode(_type_)
Definition: nodes.h:155
bool canSetTag
Definition: plannodes.h:60
ParseLoc stmt_len
Definition: plannodes.h:99
ParseLoc stmt_location
Definition: plannodes.h:98
Node * utilityStmt
Definition: plannodes.h:95
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:499

References PlannedStmt::canSetTag, CMD_UTILITY, PlannedStmt::commandType, context, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), makeNode, None_Receiver, PROCESS_UTILITY_SUBCOMMAND, ProcessUtility(), stmt, PlannedStmt::stmt_len, PlannedStmt::stmt_location, and PlannedStmt::utilityStmt.

Referenced by ATParseTransformCmd(), and ATRewriteTables().

◆ standard_ProcessUtility()

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

Definition at line 540 of file utility.c.

548 {
549  Node *parsetree;
550  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
552  ParseState *pstate;
553  int readonly_flags;
554 
555  /* This can recurse, so check for excessive recursion */
557 
558  /*
559  * If the given node tree is read-only, make a copy to ensure that parse
560  * transformations don't damage the original tree. This could be
561  * refactored to avoid making unnecessary copies in more cases, but it's
562  * not clear that it's worth a great deal of trouble over. Statements
563  * that are complex enough to be expensive to copy are exactly the ones
564  * we'd need to copy, so that only marginal savings seem possible.
565  */
566  if (readOnlyTree)
567  pstmt = copyObject(pstmt);
568  parsetree = pstmt->utilityStmt;
569 
570  /* Prohibit read/write commands in read-only states. */
571  readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
572  if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
574  {
575  CommandTag commandtag = CreateCommandTag(parsetree);
576 
577  if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
579  if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
581  if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
583  }
584 
585  pstate = make_parsestate(NULL);
586  pstate->p_sourcetext = queryString;
587  pstate->p_queryEnv = queryEnv;
588 
589  switch (nodeTag(parsetree))
590  {
591  /*
592  * ******************** transactions ********************
593  */
594  case T_TransactionStmt:
595  {
596  TransactionStmt *stmt = (TransactionStmt *) parsetree;
597 
598  switch (stmt->kind)
599  {
600  /*
601  * START TRANSACTION, as defined by SQL99: Identical
602  * to BEGIN. Same code for both.
603  */
604  case TRANS_STMT_BEGIN:
605  case TRANS_STMT_START:
606  {
607  ListCell *lc;
608 
610  foreach(lc, stmt->options)
611  {
612  DefElem *item = (DefElem *) lfirst(lc);
613 
614  if (strcmp(item->defname, "transaction_isolation") == 0)
615  SetPGVariable("transaction_isolation",
616  list_make1(item->arg),
617  true);
618  else if (strcmp(item->defname, "transaction_read_only") == 0)
619  SetPGVariable("transaction_read_only",
620  list_make1(item->arg),
621  true);
622  else if (strcmp(item->defname, "transaction_deferrable") == 0)
623  SetPGVariable("transaction_deferrable",
624  list_make1(item->arg),
625  true);
626  }
627  }
628  break;
629 
630  case TRANS_STMT_COMMIT:
631  if (!EndTransactionBlock(stmt->chain))
632  {
633  /* report unsuccessful commit in qc */
634  if (qc)
635  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
636  }
637  break;
638 
639  case TRANS_STMT_PREPARE:
640  if (!PrepareTransactionBlock(stmt->gid))
641  {
642  /* report unsuccessful commit in qc */
643  if (qc)
644  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
645  }
646  break;
647 
649  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
650  FinishPreparedTransaction(stmt->gid, true);
651  break;
652 
654  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
655  FinishPreparedTransaction(stmt->gid, false);
656  break;
657 
658  case TRANS_STMT_ROLLBACK:
660  break;
661 
663  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
664  DefineSavepoint(stmt->savepoint_name);
665  break;
666 
667  case TRANS_STMT_RELEASE:
668  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
669  ReleaseSavepoint(stmt->savepoint_name);
670  break;
671 
673  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
674  RollbackToSavepoint(stmt->savepoint_name);
675 
676  /*
677  * CommitTransactionCommand is in charge of
678  * re-defining the savepoint again
679  */
680  break;
681  }
682  }
683  break;
684 
685  /*
686  * Portal (cursor) manipulation
687  */
688  case T_DeclareCursorStmt:
689  PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
690  isTopLevel);
691  break;
692 
693  case T_ClosePortalStmt:
694  {
695  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
696 
697  CheckRestrictedOperation("CLOSE");
698  PerformPortalClose(stmt->portalname);
699  }
700  break;
701 
702  case T_FetchStmt:
703  PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
704  break;
705 
706  case T_DoStmt:
707  ExecuteDoStmt(pstate, (DoStmt *) parsetree, isAtomicContext);
708  break;
709 
710  case T_CreateTableSpaceStmt:
711  /* no event triggers for global objects */
712  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
713  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
714  break;
715 
716  case T_DropTableSpaceStmt:
717  /* no event triggers for global objects */
718  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
719  DropTableSpace((DropTableSpaceStmt *) parsetree);
720  break;
721 
722  case T_AlterTableSpaceOptionsStmt:
723  /* no event triggers for global objects */
725  break;
726 
727  case T_TruncateStmt:
728  ExecuteTruncate((TruncateStmt *) parsetree);
729  break;
730 
731  case T_CopyStmt:
732  {
733  uint64 processed;
734 
735  DoCopy(pstate, (CopyStmt *) parsetree,
736  pstmt->stmt_location, pstmt->stmt_len,
737  &processed);
738  if (qc)
739  SetQueryCompletion(qc, CMDTAG_COPY, processed);
740  }
741  break;
742 
743  case T_PrepareStmt:
744  CheckRestrictedOperation("PREPARE");
745  PrepareQuery(pstate, (PrepareStmt *) parsetree,
746  pstmt->stmt_location, pstmt->stmt_len);
747  break;
748 
749  case T_ExecuteStmt:
750  ExecuteQuery(pstate,
751  (ExecuteStmt *) parsetree, NULL,
752  params,
753  dest, qc);
754  break;
755 
756  case T_DeallocateStmt:
757  CheckRestrictedOperation("DEALLOCATE");
758  DeallocateQuery((DeallocateStmt *) parsetree);
759  break;
760 
761  case T_GrantRoleStmt:
762  /* no event triggers for global objects */
763  GrantRole(pstate, (GrantRoleStmt *) parsetree);
764  break;
765 
766  case T_CreatedbStmt:
767  /* no event triggers for global objects */
768  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
769  createdb(pstate, (CreatedbStmt *) parsetree);
770  break;
771 
772  case T_AlterDatabaseStmt:
773  /* no event triggers for global objects */
774  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
775  break;
776 
777  case T_AlterDatabaseRefreshCollStmt:
778  /* no event triggers for global objects */
780  break;
781 
782  case T_AlterDatabaseSetStmt:
783  /* no event triggers for global objects */
784  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
785  break;
786 
787  case T_DropdbStmt:
788  /* no event triggers for global objects */
789  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
790  DropDatabase(pstate, (DropdbStmt *) parsetree);
791  break;
792 
793  /* Query-level asynchronous notification */
794  case T_NotifyStmt:
795  {
796  NotifyStmt *stmt = (NotifyStmt *) parsetree;
797 
798  Async_Notify(stmt->conditionname, stmt->payload);
799  }
800  break;
801 
802  case T_ListenStmt:
803  {
804  ListenStmt *stmt = (ListenStmt *) parsetree;
805 
806  CheckRestrictedOperation("LISTEN");
807 
808  /*
809  * We don't allow LISTEN in background processes, as there is
810  * no mechanism for them to collect NOTIFY messages, so they'd
811  * just block cleanout of the async SLRU indefinitely.
812  * (Authors of custom background workers could bypass this
813  * restriction by calling Async_Listen directly, but then it's
814  * on them to provide some mechanism to process the message
815  * queue.) Note there seems no reason to forbid UNLISTEN.
816  */
817  if (MyBackendType != B_BACKEND)
818  ereport(ERROR,
819  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
820  /* translator: %s is name of a SQL command, eg LISTEN */
821  errmsg("cannot execute %s within a background process",
822  "LISTEN")));
823 
824  Async_Listen(stmt->conditionname);
825  }
826  break;
827 
828  case T_UnlistenStmt:
829  {
830  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
831 
832  CheckRestrictedOperation("UNLISTEN");
833  if (stmt->conditionname)
834  Async_Unlisten(stmt->conditionname);
835  else
837  }
838  break;
839 
840  case T_LoadStmt:
841  {
842  LoadStmt *stmt = (LoadStmt *) parsetree;
843 
844  closeAllVfds(); /* probably not necessary... */
845  /* Allowed names are restricted if you're not superuser */
846  load_file(stmt->filename, !superuser());
847  }
848  break;
849 
850  case T_CallStmt:
851  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
852  break;
853 
854  case T_ClusterStmt:
855  cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
856  break;
857 
858  case T_VacuumStmt:
859  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
860  break;
861 
862  case T_ExplainStmt:
863  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
864  break;
865 
866  case T_AlterSystemStmt:
867  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
869  break;
870 
871  case T_VariableSetStmt:
872  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
873  break;
874 
875  case T_VariableShowStmt:
876  {
877  VariableShowStmt *n = (VariableShowStmt *) parsetree;
878 
879  GetPGVariable(n->name, dest);
880  }
881  break;
882 
883  case T_DiscardStmt:
884  /* should we allow DISCARD PLANS? */
885  CheckRestrictedOperation("DISCARD");
886  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
887  break;
888 
889  case T_CreateEventTrigStmt:
890  /* no event triggers on event triggers */
892  break;
893 
894  case T_AlterEventTrigStmt:
895  /* no event triggers on event triggers */
896  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
897  break;
898 
899  /*
900  * ******************************** ROLE statements ****
901  */
902  case T_CreateRoleStmt:
903  /* no event triggers for global objects */
904  CreateRole(pstate, (CreateRoleStmt *) parsetree);
905  break;
906 
907  case T_AlterRoleStmt:
908  /* no event triggers for global objects */
909  AlterRole(pstate, (AlterRoleStmt *) parsetree);
910  break;
911 
912  case T_AlterRoleSetStmt:
913  /* no event triggers for global objects */
914  AlterRoleSet((AlterRoleSetStmt *) parsetree);
915  break;
916 
917  case T_DropRoleStmt:
918  /* no event triggers for global objects */
919  DropRole((DropRoleStmt *) parsetree);
920  break;
921 
922  case T_ReassignOwnedStmt:
923  /* no event triggers for global objects */
925  break;
926 
927  case T_LockStmt:
928 
929  /*
930  * Since the lock would just get dropped immediately, LOCK TABLE
931  * outside a transaction block is presumed to be user error.
932  */
933  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
934  LockTableCommand((LockStmt *) parsetree);
935  break;
936 
937  case T_ConstraintsSetStmt:
938  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
940  break;
941 
942  case T_CheckPointStmt:
943  if (!has_privs_of_role(GetUserId(), ROLE_PG_CHECKPOINT))
944  ereport(ERROR,
945  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
946  /* translator: %s is name of a SQL command, eg CHECKPOINT */
947  errmsg("permission denied to execute %s command",
948  "CHECKPOINT"),
949  errdetail("Only roles with privileges of the \"%s\" role may execute this command.",
950  "pg_checkpoint")));
951 
954  break;
955 
956  /*
957  * The following statements are supported by Event Triggers only
958  * in some cases, so we "fast path" them in the other cases.
959  */
960 
961  case T_GrantStmt:
962  {
963  GrantStmt *stmt = (GrantStmt *) parsetree;
964 
965  if (EventTriggerSupportsObjectType(stmt->objtype))
966  ProcessUtilitySlow(pstate, pstmt, queryString,
967  context, params, queryEnv,
968  dest, qc);
969  else
971  }
972  break;
973 
974  case T_DropStmt:
975  {
976  DropStmt *stmt = (DropStmt *) parsetree;
977 
978  if (EventTriggerSupportsObjectType(stmt->removeType))
979  ProcessUtilitySlow(pstate, pstmt, queryString,
980  context, params, queryEnv,
981  dest, qc);
982  else
983  ExecDropStmt(stmt, isTopLevel);
984  }
985  break;
986 
987  case T_RenameStmt:
988  {
989  RenameStmt *stmt = (RenameStmt *) parsetree;
990 
991  if (EventTriggerSupportsObjectType(stmt->renameType))
992  ProcessUtilitySlow(pstate, pstmt, queryString,
993  context, params, queryEnv,
994  dest, qc);
995  else
997  }
998  break;
999 
1000  case T_AlterObjectDependsStmt:
1001  {
1003 
1004  if (EventTriggerSupportsObjectType(stmt->objectType))
1005  ProcessUtilitySlow(pstate, pstmt, queryString,
1006  context, params, queryEnv,
1007  dest, qc);
1008  else
1010  }
1011  break;
1012 
1013  case T_AlterObjectSchemaStmt:
1014  {
1016 
1017  if (EventTriggerSupportsObjectType(stmt->objectType))
1018  ProcessUtilitySlow(pstate, pstmt, queryString,
1019  context, params, queryEnv,
1020  dest, qc);
1021  else
1023  }
1024  break;
1025 
1026  case T_AlterOwnerStmt:
1027  {
1028  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1029 
1030  if (EventTriggerSupportsObjectType(stmt->objectType))
1031  ProcessUtilitySlow(pstate, pstmt, queryString,
1032  context, params, queryEnv,
1033  dest, qc);
1034  else
1036  }
1037  break;
1038 
1039  case T_CommentStmt:
1040  {
1041  CommentStmt *stmt = (CommentStmt *) parsetree;
1042 
1043  if (EventTriggerSupportsObjectType(stmt->objtype))
1044  ProcessUtilitySlow(pstate, pstmt, queryString,
1045  context, params, queryEnv,
1046  dest, qc);
1047  else
1049  break;
1050  }
1051 
1052  case T_SecLabelStmt:
1053  {
1054  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1055 
1056  if (EventTriggerSupportsObjectType(stmt->objtype))
1057  ProcessUtilitySlow(pstate, pstmt, queryString,
1058  context, params, queryEnv,
1059  dest, qc);
1060  else
1062  break;
1063  }
1064 
1065  default:
1066  /* All other statement types have event trigger support */
1067  ProcessUtilitySlow(pstate, pstmt, queryString,
1068  context, params, queryEnv,
1069  dest, qc);
1070  break;
1071  }
1072 
1073  free_parsestate(pstate);
1074 
1075  /*
1076  * Make effects of commands visible, for instance so that
1077  * PreCommit_on_commit_actions() can see them (see for example bug
1078  * #15631).
1079  */
1081 }
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:5134
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:391
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:825
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:456
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:356
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:520
void Async_UnlistenAll(void)
Definition: async.c:770
void Async_Unlisten(const char *channel)
Definition: async.c:752
void Async_Listen(const char *channel)
Definition: async.c:738
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:591
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:62
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
Definition: prepare.c:56
void ExecuteQuery(ParseState *pstate, ExecuteStmt *stmt, IntoClause *intoClause, ParamListInfo params, DestReceiver *dest, QueryCompletion *qc)
Definition: prepare.c:147
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:502
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1015
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:395
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:208
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1611
Oid AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
Definition: user.c:619
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:1000
void DropRole(DropRoleStmt *stmt)
Definition: user.c:1090
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:132
void GrantRole(ParseState *pstate, GrantRoleStmt *stmt)
Definition: user.c:1480
void RequestCheckpoint(int flags)
Definition: checkpointer.c:941
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:108
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
Definition: cmdtag.h:37
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress AlterDatabaseRefreshColl(AlterDatabaseRefreshCollStmt *stmt)
Definition: dbcommands.c:2487
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:670
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:2316
void DropDatabase(ParseState *pstate, DropdbStmt *stmt)
Definition: dbcommands.c:2291
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:2581
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:144
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:857
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:182
void closeAllVfds(void)
Definition: fd.c:3020
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
void ExecuteDoStmt(ParseState *pstate, DoStmt *stmt, bool atomic)
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:4560
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc_funcs.c:382
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc_funcs.c:315
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc_funcs.c:43
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:41
@ B_BACKEND
Definition: miscadmin.h:338
Oid GetUserId(void)
Definition: miscinit.c:514
BackendType MyBackendType
Definition: miscinit.c:63
#define copyObject(obj)
Definition: nodes.h:224
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:72
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:39
#define list_make1(x1)
Definition: pg_list.h:212
void PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo params, bool isTopLevel)
Definition: portalcmds.c:43
void PerformPortalClose(const char *name)
Definition: portalcmds.c:214
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, QueryCompletion *qc)
Definition: portalcmds.c:167
void check_stack_depth(void)
Definition: postgres.c:3531
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:115
Node * arg
Definition: parsenodes.h:816
Definition: nodes.h:129
QueryEnvironment * p_queryEnv
Definition: parse_node.h:220
const char * p_sourcetext
Definition: parse_node.h:193
bool superuser(void)
Definition: superuser.c:46
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1779
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5658
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1503
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree)
Definition: utility.c:128
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:404
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:422
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1992
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:459
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:441
static void ProcessUtilitySlow(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:1089
#define COMMAND_OK_IN_PARALLEL_MODE
Definition: utility.h:57
#define COMMAND_IS_STRICTLY_READ_ONLY
Definition: utility.h:65
void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:147
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3656
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:4153
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3941
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3662
void DefineSavepoint(const char *name)
Definition: xact.c:4322
bool XactReadOnly
Definition: xact.c:80
void CommandCounterIncrement(void)
Definition: xact.c:1097
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3584
void ReleaseSavepoint(const char *name)
Definition: xact.c:4407
bool IsTransactionBlock(void)
Definition: xact.c:4915
bool IsInParallelMode(void)
Definition: xact.c:1086
void BeginTransactionBlock(void)
Definition: xact.c:3873
void RollbackToSavepoint(const char *name)
Definition: xact.c:4516
bool EndTransactionBlock(bool chain)
Definition: xact.c:3993
bool RecoveryInProgress(void)
Definition: xlog.c:6290
#define CHECKPOINT_FORCE
Definition: xlog.h:140
#define CHECKPOINT_WAIT
Definition: xlog.h:143
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:139

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseRefreshColl(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), B_BACKEND, BeginTransactionBlock(), castNode, 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(), context, copyObject, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, generate_unaccent_rules::dest, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), EndTransactionBlock(), ereport, errcode(), errdetail(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), FinishPreparedTransaction(), free_parsestate(), GetCommandTagName(), GetPGVariable(), GetUserId(), GrantRole(), has_privs_of_role(), IsInParallelMode(), IsTransactionBlock(), lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), MyBackendType, VariableShowStmt::name, nodeTag, ParseState::p_queryEnv, ParseState::p_sourcetext, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), ReleaseSavepoint(), RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), SetPGVariable(), SetQueryCompletion(), stmt, PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), 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(), REGRESS_utility_command(), and sepgsql_utility_command().

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

Definition at line 2176 of file utility.c.

2177 {
2178  Query *qry;
2179 
2180  switch (nodeTag(parsetree))
2181  {
2182  case T_DeclareCursorStmt:
2183  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2184  if (qry->commandType == CMD_UTILITY)
2185  return UtilityContainsQuery(qry->utilityStmt);
2186  return qry;
2187 
2188  case T_ExplainStmt:
2189  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2190  if (qry->commandType == CMD_UTILITY)
2191  return UtilityContainsQuery(qry->utilityStmt);
2192  return qry;
2193 
2194  case T_CreateTableAsStmt:
2195  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2196  if (qry->commandType == CMD_UTILITY)
2197  return UtilityContainsQuery(qry->utilityStmt);
2198  return qry;
2199 
2200  default:
2201  return NULL;
2202  }
2203 }
CmdType commandType
Definition: parsenodes.h:121
Node * utilityStmt
Definition: parsenodes.h:136
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2176

References castNode, CMD_UTILITY, Query::commandType, nodeTag, and Query::utilityStmt.

Referenced by AcquireExecutorLocks(), AcquirePlannerLocks(), and extract_query_dependencies_walker().

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 2025 of file utility.c.

2026 {
2027  switch (nodeTag(parsetree))
2028  {
2029  case T_CallStmt:
2030  {
2031  CallStmt *stmt = (CallStmt *) parsetree;
2032 
2033  return (stmt->funcexpr->funcresulttype == RECORDOID);
2034  }
2035  case T_FetchStmt:
2036  {
2037  FetchStmt *stmt = (FetchStmt *) parsetree;
2038  Portal portal;
2039 
2040  if (stmt->ismove)
2041  return false;
2042  portal = GetPortalByName(stmt->portalname);
2043  if (!PortalIsValid(portal))
2044  return false; /* not our business to raise error */
2045  return portal->tupDesc ? true : false;
2046  }
2047 
2048  case T_ExecuteStmt:
2049  {
2050  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2051  PreparedStatement *entry;
2052 
2053  entry = FetchPreparedStatement(stmt->name, false);
2054  if (!entry)
2055  return false; /* not our business to raise error */
2056  if (entry->plansource->resultDesc)
2057  return true;
2058  return false;
2059  }
2060 
2061  case T_ExplainStmt:
2062  return true;
2063 
2064  case T_VariableShowStmt:
2065  return true;
2066 
2067  default:
2068  return false;
2069  }
2070 }
return true
Definition: isn.c:126
#define PortalIsValid(p)
Definition: portal.h:212
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc resultDesc
Definition: plancache.h:108
TupleDesc tupDesc
Definition: portal.h:160
CachedPlanSource * plansource
Definition: prepare.h:31

References FetchPreparedStatement(), GetPortalByName(), nodeTag, PreparedStatement::plansource, PortalIsValid, CachedPlanSource::resultDesc, stmt, true, and PortalData::tupDesc.

Referenced by ChoosePortalStrategy().

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 2081 of file utility.c.

2082 {
2083  switch (nodeTag(parsetree))
2084  {
2085  case T_CallStmt:
2086  return CallStmtResultDesc((CallStmt *) parsetree);
2087 
2088  case T_FetchStmt:
2089  {
2090  FetchStmt *stmt = (FetchStmt *) parsetree;
2091  Portal portal;
2092 
2093  if (stmt->ismove)
2094  return NULL;
2095  portal = GetPortalByName(stmt->portalname);
2096  if (!PortalIsValid(portal))
2097  return NULL; /* not our business to raise error */
2098  return CreateTupleDescCopy(portal->tupDesc);
2099  }
2100 
2101  case T_ExecuteStmt:
2102  {
2103  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2104  PreparedStatement *entry;
2105 
2106  entry = FetchPreparedStatement(stmt->name, false);
2107  if (!entry)
2108  return NULL; /* not our business to raise error */
2109  return FetchPreparedStatementResultDesc(entry);
2110  }
2111 
2112  case T_ExplainStmt:
2113  return ExplainResultDesc((ExplainStmt *) parsetree);
2114 
2115  case T_VariableShowStmt:
2116  {
2117  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2118 
2119  return GetPGVariableResultDesc(n->name);
2120  }
2121 
2122  default:
2123  return NULL;
2124  }
2125 }
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:463
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:388
TupleDesc CallStmtResultDesc(CallStmt *stmt)
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc_funcs.c:394
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:133

References CallStmtResultDesc(), CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), VariableShowStmt::name, nodeTag, PortalIsValid, stmt, and PortalData::tupDesc.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

Variable Documentation

◆ ProcessUtility_hook

PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
extern

Definition at line 70 of file utility.c.

Referenced by _PG_init(), and ProcessUtility().