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 101 of file utility.c.

102 {
103  Assert(IsA(pstmt, PlannedStmt));
104  switch (pstmt->commandType)
105  {
106  case CMD_SELECT:
107  if (pstmt->rowMarks != NIL)
108  return false; /* SELECT FOR [KEY] UPDATE/SHARE */
109  else if (pstmt->hasModifyingCTE)
110  return false; /* data-modifying CTE */
111  else
112  return true;
113  case CMD_UPDATE:
114  case CMD_INSERT:
115  case CMD_DELETE:
116  case CMD_MERGE:
117  return false;
118  case CMD_UTILITY:
119  /* For now, treat all utility commands as read/write */
120  return false;
121  default:
122  elog(WARNING, "unrecognized commandType: %d",
123  (int) pstmt->commandType);
124  break;
125  }
126  return false;
127 }
#define WARNING
Definition: elog.h:36
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
@ CMD_MERGE
Definition: nodes.h:259
@ CMD_UTILITY
Definition: nodes.h:260
@ CMD_INSERT
Definition: nodes.h:257
@ CMD_DELETE
Definition: nodes.h:258
@ CMD_UPDATE
Definition: nodes.h:256
@ CMD_SELECT
Definition: nodes.h:255
#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:48
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2367

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 2367 of file utility.c.

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

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 3254 of file utility.c.

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

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 506 of file utility.c.

514 {
515  Assert(IsA(pstmt, PlannedStmt));
516  Assert(pstmt->commandType == CMD_UTILITY);
517  Assert(queryString != NULL); /* required as of 8.4 */
518  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
519 
520  /*
521  * We provide a function hook variable that lets loadable plugins get
522  * control when ProcessUtility is called. Such a plugin would normally
523  * call standard_ProcessUtility().
524  */
526  (*ProcessUtility_hook) (pstmt, queryString, readOnlyTree,
527  context, params, queryEnv,
528  dest, qc);
529  else
530  standard_ProcessUtility(pstmt, queryString, readOnlyTree,
531  context, params, queryEnv,
532  dest, qc);
533 }
CommandTag commandTag
Definition: cmdtag.h:32
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:547
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:77

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

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

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1963 of file utility.c.

1964 {
1965  PlannedStmt *wrapper;
1966 
1967  /*
1968  * For event triggers, we must "close" the current complex-command set,
1969  * and start a new one afterwards; this is needed to ensure the ordering
1970  * of command events is consistent with the way they were executed.
1971  */
1973 
1974  /* Create a suitable wrapper */
1975  wrapper = makeNode(PlannedStmt);
1976  wrapper->commandType = CMD_UTILITY;
1977  wrapper->canSetTag = false;
1978  wrapper->utilityStmt = stmt;
1979  wrapper->stmt_location = context->pstmt->stmt_location;
1980  wrapper->stmt_len = context->pstmt->stmt_len;
1981 
1982  ProcessUtility(wrapper,
1983  context->queryString,
1984  false,
1986  context->params,
1987  context->queryEnv,
1988  None_Receiver,
1989  NULL);
1990 
1993 }
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
ParamListInfo params
Definition: utility.h:35
QueryEnvironment * queryEnv
Definition: utility.h:36
PlannedStmt * pstmt
Definition: utility.h:32
const char * queryString
Definition: utility.h:33
bool canSetTag
Definition: plannodes.h:60
int stmt_location
Definition: plannodes.h:98
int stmt_len
Definition: plannodes.h:99
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:506

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, 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 547 of file utility.c.

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

2185 {
2186  Query *qry;
2187 
2188  switch (nodeTag(parsetree))
2189  {
2190  case T_DeclareCursorStmt:
2191  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2192  if (qry->commandType == CMD_UTILITY)
2193  return UtilityContainsQuery(qry->utilityStmt);
2194  return qry;
2195 
2196  case T_ExplainStmt:
2197  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2198  if (qry->commandType == CMD_UTILITY)
2199  return UtilityContainsQuery(qry->utilityStmt);
2200  return qry;
2201 
2202  case T_CreateTableAsStmt:
2203  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2204  if (qry->commandType == CMD_UTILITY)
2205  return UtilityContainsQuery(qry->utilityStmt);
2206  return qry;
2207 
2208  default:
2209  return NULL;
2210  }
2211 }
CmdType commandType
Definition: parsenodes.h:120
Node * utilityStmt
Definition: parsenodes.h:135
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2184

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 2032 of file utility.c.

2033 {
2034  switch (nodeTag(parsetree))
2035  {
2036  case T_CallStmt:
2037  {
2038  CallStmt *stmt = (CallStmt *) parsetree;
2039 
2040  return (stmt->funcexpr->funcresulttype == RECORDOID);
2041  }
2042  case T_FetchStmt:
2043  {
2044  FetchStmt *stmt = (FetchStmt *) parsetree;
2045  Portal portal;
2046 
2047  if (stmt->ismove)
2048  return false;
2049  portal = GetPortalByName(stmt->portalname);
2050  if (!PortalIsValid(portal))
2051  return false; /* not our business to raise error */
2052  return portal->tupDesc ? true : false;
2053  }
2054 
2055  case T_ExecuteStmt:
2056  {
2057  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2058  PreparedStatement *entry;
2059 
2060  entry = FetchPreparedStatement(stmt->name, false);
2061  if (!entry)
2062  return false; /* not our business to raise error */
2063  if (entry->plansource->resultDesc)
2064  return true;
2065  return false;
2066  }
2067 
2068  case T_ExplainStmt:
2069  return true;
2070 
2071  case T_VariableShowStmt:
2072  return true;
2073 
2074  default:
2075  return false;
2076  }
2077 }
return true
Definition: isn.c:126
#define PortalIsValid(p)
Definition: portal.h:212
Portal GetPortalByName(const char *name)
Definition: portalmem.c:131
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 2088 of file utility.c.

2089 {
2090  switch (nodeTag(parsetree))
2091  {
2092  case T_CallStmt:
2093  return CallStmtResultDesc((CallStmt *) parsetree);
2094 
2095  case T_FetchStmt:
2096  {
2097  FetchStmt *stmt = (FetchStmt *) parsetree;
2098  Portal portal;
2099 
2100  if (stmt->ismove)
2101  return NULL;
2102  portal = GetPortalByName(stmt->portalname);
2103  if (!PortalIsValid(portal))
2104  return NULL; /* not our business to raise error */
2105  return CreateTupleDescCopy(portal->tupDesc);
2106  }
2107 
2108  case T_ExecuteStmt:
2109  {
2110  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2111  PreparedStatement *entry;
2112 
2113  entry = FetchPreparedStatement(stmt->name, false);
2114  if (!entry)
2115  return NULL; /* not our business to raise error */
2116  return FetchPreparedStatementResultDesc(entry);
2117  }
2118 
2119  case T_ExplainStmt:
2120  return ExplainResultDesc((ExplainStmt *) parsetree);
2121 
2122  case T_VariableShowStmt:
2123  {
2124  VariableShowStmt *n = (VariableShowStmt *) parsetree;
2125 
2126  return GetPGVariableResultDesc(n->name);
2127  }
2128 
2129  default:
2130  return NULL;
2131  }
2132 }
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:466
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:341
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 77 of file utility.c.

Referenced by _PG_init(), and ProcessUtility().