LCOV - code coverage report
Current view: top level - src/backend/tcop - utility.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 1036 1379 75.1 %
Date: 2019-11-13 23:06:49 Functions: 15 16 93.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * utility.c
       4             :  *    Contains functions which control the execution of the POSTGRES utility
       5             :  *    commands.  At one time acted as an interface between the Lisp and C
       6             :  *    systems.
       7             :  *
       8             :  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
       9             :  * Portions Copyright (c) 1994, Regents of the University of California
      10             :  *
      11             :  *
      12             :  * IDENTIFICATION
      13             :  *    src/backend/tcop/utility.c
      14             :  *
      15             :  *-------------------------------------------------------------------------
      16             :  */
      17             : #include "postgres.h"
      18             : 
      19             : #include "access/htup_details.h"
      20             : #include "access/reloptions.h"
      21             : #include "access/twophase.h"
      22             : #include "access/xact.h"
      23             : #include "access/xlog.h"
      24             : #include "catalog/catalog.h"
      25             : #include "catalog/namespace.h"
      26             : #include "catalog/pg_inherits.h"
      27             : #include "catalog/toasting.h"
      28             : #include "commands/alter.h"
      29             : #include "commands/async.h"
      30             : #include "commands/cluster.h"
      31             : #include "commands/collationcmds.h"
      32             : #include "commands/comment.h"
      33             : #include "commands/conversioncmds.h"
      34             : #include "commands/copy.h"
      35             : #include "commands/createas.h"
      36             : #include "commands/dbcommands.h"
      37             : #include "commands/defrem.h"
      38             : #include "commands/discard.h"
      39             : #include "commands/event_trigger.h"
      40             : #include "commands/explain.h"
      41             : #include "commands/extension.h"
      42             : #include "commands/lockcmds.h"
      43             : #include "commands/matview.h"
      44             : #include "commands/policy.h"
      45             : #include "commands/portalcmds.h"
      46             : #include "commands/prepare.h"
      47             : #include "commands/proclang.h"
      48             : #include "commands/publicationcmds.h"
      49             : #include "commands/schemacmds.h"
      50             : #include "commands/seclabel.h"
      51             : #include "commands/sequence.h"
      52             : #include "commands/subscriptioncmds.h"
      53             : #include "commands/tablecmds.h"
      54             : #include "commands/tablespace.h"
      55             : #include "commands/trigger.h"
      56             : #include "commands/typecmds.h"
      57             : #include "commands/user.h"
      58             : #include "commands/vacuum.h"
      59             : #include "commands/view.h"
      60             : #include "miscadmin.h"
      61             : #include "parser/parse_utilcmd.h"
      62             : #include "postmaster/bgwriter.h"
      63             : #include "rewrite/rewriteDefine.h"
      64             : #include "rewrite/rewriteRemove.h"
      65             : #include "storage/fd.h"
      66             : #include "tcop/pquery.h"
      67             : #include "tcop/utility.h"
      68             : #include "utils/acl.h"
      69             : #include "utils/guc.h"
      70             : #include "utils/lsyscache.h"
      71             : #include "utils/rel.h"
      72             : #include "utils/syscache.h"
      73             : 
      74             : /* Hook for plugins to get control in ProcessUtility() */
      75             : ProcessUtility_hook_type ProcessUtility_hook = NULL;
      76             : 
      77             : /* local function declarations */
      78             : static void ProcessUtilitySlow(ParseState *pstate,
      79             :                                PlannedStmt *pstmt,
      80             :                                const char *queryString,
      81             :                                ProcessUtilityContext context,
      82             :                                ParamListInfo params,
      83             :                                QueryEnvironment *queryEnv,
      84             :                                DestReceiver *dest,
      85             :                                char *completionTag);
      86             : static void ExecDropStmt(DropStmt *stmt, bool isTopLevel);
      87             : 
      88             : 
      89             : /*
      90             :  * CommandIsReadOnly: is an executable query read-only?
      91             :  *
      92             :  * This is a much stricter test than we apply for XactReadOnly mode;
      93             :  * the query must be *in truth* read-only, because the caller wishes
      94             :  * not to do CommandCounterIncrement for it.
      95             :  *
      96             :  * Note: currently no need to support raw or analyzed queries here
      97             :  */
      98             : bool
      99       10720 : CommandIsReadOnly(PlannedStmt *pstmt)
     100             : {
     101             :     Assert(IsA(pstmt, PlannedStmt));
     102       10720 :     switch (pstmt->commandType)
     103             :     {
     104             :         case CMD_SELECT:
     105       10720 :             if (pstmt->rowMarks != NIL)
     106           0 :                 return false;   /* SELECT FOR [KEY] UPDATE/SHARE */
     107       10720 :             else if (pstmt->hasModifyingCTE)
     108           0 :                 return false;   /* data-modifying CTE */
     109             :             else
     110       10720 :                 return true;
     111             :         case CMD_UPDATE:
     112             :         case CMD_INSERT:
     113             :         case CMD_DELETE:
     114           0 :             return false;
     115             :         case CMD_UTILITY:
     116             :             /* For now, treat all utility commands as read/write */
     117           0 :             return false;
     118             :         default:
     119           0 :             elog(WARNING, "unrecognized commandType: %d",
     120             :                  (int) pstmt->commandType);
     121           0 :             break;
     122             :     }
     123           0 :     return false;
     124             : }
     125             : 
     126             : /*
     127             :  * check_xact_readonly: is a utility command read-only?
     128             :  *
     129             :  * Here we use the loose rules of XactReadOnly mode: no permanent effects
     130             :  * on the database are allowed.
     131             :  */
     132             : static void
     133      312524 : check_xact_readonly(Node *parsetree)
     134             : {
     135             :     /* Only perform the check if we have a reason to do so. */
     136      312524 :     if (!XactReadOnly && !IsInParallelMode())
     137      305464 :         return;
     138             : 
     139             :     /*
     140             :      * Note: Commands that need to do more complicated checking are handled
     141             :      * elsewhere, in particular COPY and plannable statements do their own
     142             :      * checking.  However they should all call PreventCommandIfReadOnly or
     143             :      * PreventCommandIfParallelMode to actually throw the error.
     144             :      */
     145             : 
     146        7060 :     switch (nodeTag(parsetree))
     147             :     {
     148             :         case T_AlterDatabaseStmt:
     149             :         case T_AlterDatabaseSetStmt:
     150             :         case T_AlterDomainStmt:
     151             :         case T_AlterFunctionStmt:
     152             :         case T_AlterRoleStmt:
     153             :         case T_AlterRoleSetStmt:
     154             :         case T_AlterObjectDependsStmt:
     155             :         case T_AlterObjectSchemaStmt:
     156             :         case T_AlterOwnerStmt:
     157             :         case T_AlterOperatorStmt:
     158             :         case T_AlterSeqStmt:
     159             :         case T_AlterTableMoveAllStmt:
     160             :         case T_AlterTableStmt:
     161             :         case T_RenameStmt:
     162             :         case T_CommentStmt:
     163             :         case T_DefineStmt:
     164             :         case T_CreateCastStmt:
     165             :         case T_CreateEventTrigStmt:
     166             :         case T_AlterEventTrigStmt:
     167             :         case T_CreateConversionStmt:
     168             :         case T_CreatedbStmt:
     169             :         case T_CreateDomainStmt:
     170             :         case T_CreateFunctionStmt:
     171             :         case T_CreateRoleStmt:
     172             :         case T_IndexStmt:
     173             :         case T_CreatePLangStmt:
     174             :         case T_CreateOpClassStmt:
     175             :         case T_CreateOpFamilyStmt:
     176             :         case T_AlterOpFamilyStmt:
     177             :         case T_RuleStmt:
     178             :         case T_CreateSchemaStmt:
     179             :         case T_CreateSeqStmt:
     180             :         case T_CreateStmt:
     181             :         case T_CreateTableAsStmt:
     182             :         case T_RefreshMatViewStmt:
     183             :         case T_CreateTableSpaceStmt:
     184             :         case T_CreateTransformStmt:
     185             :         case T_CreateTrigStmt:
     186             :         case T_CompositeTypeStmt:
     187             :         case T_CreateEnumStmt:
     188             :         case T_CreateRangeStmt:
     189             :         case T_AlterEnumStmt:
     190             :         case T_ViewStmt:
     191             :         case T_DropStmt:
     192             :         case T_DropdbStmt:
     193             :         case T_DropTableSpaceStmt:
     194             :         case T_DropRoleStmt:
     195             :         case T_GrantStmt:
     196             :         case T_GrantRoleStmt:
     197             :         case T_AlterDefaultPrivilegesStmt:
     198             :         case T_TruncateStmt:
     199             :         case T_DropOwnedStmt:
     200             :         case T_ReassignOwnedStmt:
     201             :         case T_AlterTSDictionaryStmt:
     202             :         case T_AlterTSConfigurationStmt:
     203             :         case T_CreateExtensionStmt:
     204             :         case T_AlterExtensionStmt:
     205             :         case T_AlterExtensionContentsStmt:
     206             :         case T_CreateFdwStmt:
     207             :         case T_AlterFdwStmt:
     208             :         case T_CreateForeignServerStmt:
     209             :         case T_AlterForeignServerStmt:
     210             :         case T_CreateUserMappingStmt:
     211             :         case T_AlterUserMappingStmt:
     212             :         case T_DropUserMappingStmt:
     213             :         case T_AlterTableSpaceOptionsStmt:
     214             :         case T_CreateForeignTableStmt:
     215             :         case T_ImportForeignSchemaStmt:
     216             :         case T_SecLabelStmt:
     217             :         case T_CreatePublicationStmt:
     218             :         case T_AlterPublicationStmt:
     219             :         case T_CreateSubscriptionStmt:
     220             :         case T_AlterSubscriptionStmt:
     221             :         case T_DropSubscriptionStmt:
     222           8 :             PreventCommandIfReadOnly(CreateCommandTag(parsetree));
     223           0 :             PreventCommandIfParallelMode(CreateCommandTag(parsetree));
     224           0 :             break;
     225             :         default:
     226             :             /* do nothing */
     227        7052 :             break;
     228             :     }
     229             : }
     230             : 
     231             : /*
     232             :  * PreventCommandIfReadOnly: throw error if XactReadOnly
     233             :  *
     234             :  * This is useful mainly to ensure consistency of the error message wording;
     235             :  * most callers have checked XactReadOnly for themselves.
     236             :  */
     237             : void
     238       59946 : PreventCommandIfReadOnly(const char *cmdname)
     239             : {
     240       59946 :     if (XactReadOnly)
     241          28 :         ereport(ERROR,
     242             :                 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
     243             :         /* translator: %s is name of a SQL command, eg CREATE */
     244             :                  errmsg("cannot execute %s in a read-only transaction",
     245             :                         cmdname)));
     246       59918 : }
     247             : 
     248             : /*
     249             :  * PreventCommandIfParallelMode: throw error if current (sub)transaction is
     250             :  * in parallel mode.
     251             :  *
     252             :  * This is useful mainly to ensure consistency of the error message wording;
     253             :  * most callers have checked IsInParallelMode() for themselves.
     254             :  */
     255             : void
     256       62574 : PreventCommandIfParallelMode(const char *cmdname)
     257             : {
     258       62574 :     if (IsInParallelMode())
     259           0 :         ereport(ERROR,
     260             :                 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
     261             :         /* translator: %s is name of a SQL command, eg CREATE */
     262             :                  errmsg("cannot execute %s during a parallel operation",
     263             :                         cmdname)));
     264       62574 : }
     265             : 
     266             : /*
     267             :  * PreventCommandDuringRecovery: throw error if RecoveryInProgress
     268             :  *
     269             :  * The majority of operations that are unsafe in a Hot Standby
     270             :  * will be rejected by XactReadOnly tests.  However there are a few
     271             :  * commands that are allowed in "read-only" xacts but cannot be allowed
     272             :  * in Hot Standby mode.  Those commands should call this function.
     273             :  */
     274             : void
     275       20330 : PreventCommandDuringRecovery(const char *cmdname)
     276             : {
     277       20330 :     if (RecoveryInProgress())
     278           0 :         ereport(ERROR,
     279             :                 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
     280             :         /* translator: %s is name of a SQL command, eg CREATE */
     281             :                  errmsg("cannot execute %s during recovery",
     282             :                         cmdname)));
     283       20330 : }
     284             : 
     285             : /*
     286             :  * CheckRestrictedOperation: throw error for hazardous command if we're
     287             :  * inside a security restriction context.
     288             :  *
     289             :  * This is needed to protect session-local state for which there is not any
     290             :  * better-defined protection mechanism, such as ownership.
     291             :  */
     292             : static void
     293        5746 : CheckRestrictedOperation(const char *cmdname)
     294             : {
     295        5746 :     if (InSecurityRestrictedOperation())
     296           0 :         ereport(ERROR,
     297             :                 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
     298             :         /* translator: %s is name of a SQL command, eg PREPARE */
     299             :                  errmsg("cannot execute %s within security-restricted operation",
     300             :                         cmdname)));
     301        5746 : }
     302             : 
     303             : 
     304             : /*
     305             :  * ProcessUtility
     306             :  *      general utility function invoker
     307             :  *
     308             :  *  pstmt: PlannedStmt wrapper for the utility statement
     309             :  *  queryString: original source text of command
     310             :  *  context: identifies source of statement (toplevel client command,
     311             :  *      non-toplevel client command, subcommand of a larger utility command)
     312             :  *  params: parameters to use during execution
     313             :  *  queryEnv: environment for parse through execution (e.g., ephemeral named
     314             :  *      tables like trigger transition tables).  May be NULL.
     315             :  *  dest: where to send results
     316             :  *  completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
     317             :  *      in which to store a command completion status string.
     318             :  *
     319             :  * Caller MUST supply a queryString; it is not allowed (anymore) to pass NULL.
     320             :  * If you really don't have source text, you can pass a constant string,
     321             :  * perhaps "(query not available)".
     322             :  *
     323             :  * completionTag is only set nonempty if we want to return a nondefault status.
     324             :  *
     325             :  * completionTag may be NULL if caller doesn't want a status string.
     326             :  *
     327             :  * Note for users of ProcessUtility_hook: the same queryString may be passed
     328             :  * to multiple invocations of ProcessUtility when processing a query string
     329             :  * containing multiple semicolon-separated statements.  One should use
     330             :  * pstmt->stmt_location and pstmt->stmt_len to identify the substring
     331             :  * containing the current statement.  Keep in mind also that some utility
     332             :  * statements (e.g., CREATE SCHEMA) will recurse to ProcessUtility to process
     333             :  * sub-statements, often passing down the same queryString, stmt_location,
     334             :  * and stmt_len that were given for the whole statement.
     335             :  */
     336             : void
     337      312524 : ProcessUtility(PlannedStmt *pstmt,
     338             :                const char *queryString,
     339             :                ProcessUtilityContext context,
     340             :                ParamListInfo params,
     341             :                QueryEnvironment *queryEnv,
     342             :                DestReceiver *dest,
     343             :                char *completionTag)
     344             : {
     345             :     Assert(IsA(pstmt, PlannedStmt));
     346             :     Assert(pstmt->commandType == CMD_UTILITY);
     347             :     Assert(queryString != NULL);    /* required as of 8.4 */
     348             : 
     349             :     /*
     350             :      * We provide a function hook variable that lets loadable plugins get
     351             :      * control when ProcessUtility is called.  Such a plugin would normally
     352             :      * call standard_ProcessUtility().
     353             :      */
     354      312524 :     if (ProcessUtility_hook)
     355         136 :         (*ProcessUtility_hook) (pstmt, queryString,
     356             :                                 context, params, queryEnv,
     357             :                                 dest, completionTag);
     358             :     else
     359      312388 :         standard_ProcessUtility(pstmt, queryString,
     360             :                                 context, params, queryEnv,
     361             :                                 dest, completionTag);
     362      305394 : }
     363             : 
     364             : /*
     365             :  * standard_ProcessUtility itself deals only with utility commands for
     366             :  * which we do not provide event trigger support.  Commands that do have
     367             :  * such support are passed down to ProcessUtilitySlow, which contains the
     368             :  * necessary infrastructure for such triggers.
     369             :  *
     370             :  * This division is not just for performance: it's critical that the
     371             :  * event trigger code not be invoked when doing START TRANSACTION for
     372             :  * example, because we might need to refresh the event trigger cache,
     373             :  * which requires being in a valid transaction.
     374             :  */
     375             : void
     376      312524 : standard_ProcessUtility(PlannedStmt *pstmt,
     377             :                         const char *queryString,
     378             :                         ProcessUtilityContext context,
     379             :                         ParamListInfo params,
     380             :                         QueryEnvironment *queryEnv,
     381             :                         DestReceiver *dest,
     382             :                         char *completionTag)
     383             : {
     384      312524 :     Node       *parsetree = pstmt->utilityStmt;
     385      312524 :     bool        isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
     386      312524 :     bool        isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
     387             :     ParseState *pstate;
     388             : 
     389             :     /* This can recurse, so check for excessive recursion */
     390      312524 :     check_stack_depth();
     391             : 
     392      312524 :     check_xact_readonly(parsetree);
     393             : 
     394      312516 :     if (completionTag)
     395      299500 :         completionTag[0] = '\0';
     396             : 
     397      312516 :     pstate = make_parsestate(NULL);
     398      312516 :     pstate->p_sourcetext = queryString;
     399             : 
     400      312516 :     switch (nodeTag(parsetree))
     401             :     {
     402             :             /*
     403             :              * ******************** transactions ********************
     404             :              */
     405             :         case T_TransactionStmt:
     406             :             {
     407       21068 :                 TransactionStmt *stmt = (TransactionStmt *) parsetree;
     408             : 
     409       21068 :                 switch (stmt->kind)
     410             :                 {
     411             :                         /*
     412             :                          * START TRANSACTION, as defined by SQL99: Identical
     413             :                          * to BEGIN.  Same code for both.
     414             :                          */
     415             :                     case TRANS_STMT_BEGIN:
     416             :                     case TRANS_STMT_START:
     417             :                         {
     418             :                             ListCell   *lc;
     419             : 
     420        9904 :                             BeginTransactionBlock();
     421       15300 :                             foreach(lc, stmt->options)
     422             :                             {
     423        5396 :                                 DefElem    *item = (DefElem *) lfirst(lc);
     424             : 
     425        5396 :                                 if (strcmp(item->defname, "transaction_isolation") == 0)
     426        4860 :                                     SetPGVariable("transaction_isolation",
     427        4860 :                                                   list_make1(item->arg),
     428             :                                                   true);
     429         536 :                                 else if (strcmp(item->defname, "transaction_read_only") == 0)
     430         522 :                                     SetPGVariable("transaction_read_only",
     431         522 :                                                   list_make1(item->arg),
     432             :                                                   true);
     433          14 :                                 else if (strcmp(item->defname, "transaction_deferrable") == 0)
     434          14 :                                     SetPGVariable("transaction_deferrable",
     435          14 :                                                   list_make1(item->arg),
     436             :                                                   true);
     437             :                             }
     438             :                         }
     439        9904 :                         break;
     440             : 
     441             :                     case TRANS_STMT_COMMIT:
     442        8570 :                         if (!EndTransactionBlock(stmt->chain))
     443             :                         {
     444             :                             /* report unsuccessful commit in completionTag */
     445         550 :                             if (completionTag)
     446         550 :                                 strcpy(completionTag, "ROLLBACK");
     447             :                         }
     448        8550 :                         break;
     449             : 
     450             :                     case TRANS_STMT_PREPARE:
     451         134 :                         PreventCommandDuringRecovery("PREPARE TRANSACTION");
     452         134 :                         if (!PrepareTransactionBlock(stmt->gid))
     453             :                         {
     454             :                             /* report unsuccessful commit in completionTag */
     455           2 :                             if (completionTag)
     456           2 :                                 strcpy(completionTag, "ROLLBACK");
     457             :                         }
     458         134 :                         break;
     459             : 
     460             :                     case TRANS_STMT_COMMIT_PREPARED:
     461          52 :                         PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
     462          52 :                         PreventCommandDuringRecovery("COMMIT PREPARED");
     463          52 :                         FinishPreparedTransaction(stmt->gid, true);
     464          46 :                         break;
     465             : 
     466             :                     case TRANS_STMT_ROLLBACK_PREPARED:
     467          26 :                         PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
     468          26 :                         PreventCommandDuringRecovery("ROLLBACK PREPARED");
     469          26 :                         FinishPreparedTransaction(stmt->gid, false);
     470          20 :                         break;
     471             : 
     472             :                     case TRANS_STMT_ROLLBACK:
     473        1044 :                         UserAbortTransactionBlock(stmt->chain);
     474        1024 :                         break;
     475             : 
     476             :                     case TRANS_STMT_SAVEPOINT:
     477         800 :                         RequireTransactionBlock(isTopLevel, "SAVEPOINT");
     478         796 :                         DefineSavepoint(stmt->savepoint_name);
     479         788 :                         break;
     480             : 
     481             :                     case TRANS_STMT_RELEASE:
     482         146 :                         RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
     483         142 :                         ReleaseSavepoint(stmt->savepoint_name);
     484         138 :                         break;
     485             : 
     486             :                     case TRANS_STMT_ROLLBACK_TO:
     487         392 :                         RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
     488         388 :                         RollbackToSavepoint(stmt->savepoint_name);
     489             : 
     490             :                         /*
     491             :                          * CommitTransactionCommand is in charge of
     492             :                          * re-defining the savepoint again
     493             :                          */
     494         380 :                         break;
     495             :                 }
     496             :             }
     497       20984 :             break;
     498             : 
     499             :             /*
     500             :              * Portal (cursor) manipulation
     501             :              */
     502             :         case T_DeclareCursorStmt:
     503        1942 :             PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
     504             :                               queryString, isTopLevel);
     505        1940 :             break;
     506             : 
     507             :         case T_ClosePortalStmt:
     508             :             {
     509        1616 :                 ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
     510             : 
     511        1616 :                 CheckRestrictedOperation("CLOSE");
     512        1616 :                 PerformPortalClose(stmt->portalname);
     513             :             }
     514        1614 :             break;
     515             : 
     516             :         case T_FetchStmt:
     517        4224 :             PerformPortalFetch((FetchStmt *) parsetree, dest,
     518             :                                completionTag);
     519        4156 :             break;
     520             : 
     521             :         case T_DoStmt:
     522         522 :             ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
     523         262 :             break;
     524             : 
     525             :         case T_CreateTableSpaceStmt:
     526             :             /* no event triggers for global objects */
     527          28 :             PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
     528          28 :             CreateTableSpace((CreateTableSpaceStmt *) parsetree);
     529          20 :             break;
     530             : 
     531             :         case T_DropTableSpaceStmt:
     532             :             /* no event triggers for global objects */
     533          20 :             PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
     534          20 :             DropTableSpace((DropTableSpaceStmt *) parsetree);
     535          16 :             break;
     536             : 
     537             :         case T_AlterTableSpaceOptionsStmt:
     538             :             /* no event triggers for global objects */
     539          16 :             AlterTableSpaceOptions((AlterTableSpaceOptionsStmt *) parsetree);
     540           8 :             break;
     541             : 
     542             :         case T_TruncateStmt:
     543         756 :             ExecuteTruncate((TruncateStmt *) parsetree);
     544         664 :             break;
     545             : 
     546             :         case T_CopyStmt:
     547             :             {
     548             :                 uint64      processed;
     549             : 
     550        4604 :                 DoCopy(pstate, (CopyStmt *) parsetree,
     551             :                        pstmt->stmt_location, pstmt->stmt_len,
     552             :                        &processed);
     553        4308 :                 if (completionTag)
     554        4308 :                     snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
     555             :                              "COPY " UINT64_FORMAT, processed);
     556             :             }
     557        4308 :             break;
     558             : 
     559             :         case T_PrepareStmt:
     560         294 :             CheckRestrictedOperation("PREPARE");
     561         294 :             PrepareQuery((PrepareStmt *) parsetree, queryString,
     562             :                          pstmt->stmt_location, pstmt->stmt_len);
     563         286 :             break;
     564             : 
     565             :         case T_ExecuteStmt:
     566         802 :             ExecuteQuery((ExecuteStmt *) parsetree, NULL,
     567             :                          queryString, params,
     568             :                          dest, completionTag);
     569         736 :             break;
     570             : 
     571             :         case T_DeallocateStmt:
     572        3752 :             CheckRestrictedOperation("DEALLOCATE");
     573        3752 :             DeallocateQuery((DeallocateStmt *) parsetree);
     574        3752 :             break;
     575             : 
     576             :         case T_GrantRoleStmt:
     577             :             /* no event triggers for global objects */
     578        1046 :             GrantRole((GrantRoleStmt *) parsetree);
     579        1030 :             break;
     580             : 
     581             :         case T_CreatedbStmt:
     582             :             /* no event triggers for global objects */
     583         884 :             PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
     584         884 :             createdb(pstate, (CreatedbStmt *) parsetree);
     585         882 :             break;
     586             : 
     587             :         case T_AlterDatabaseStmt:
     588             :             /* no event triggers for global objects */
     589           6 :             AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
     590           6 :             break;
     591             : 
     592             :         case T_AlterDatabaseSetStmt:
     593             :             /* no event triggers for global objects */
     594         828 :             AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
     595         828 :             break;
     596             : 
     597             :         case T_DropdbStmt:
     598             :             /* no event triggers for global objects */
     599          38 :             PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
     600          38 :             DropDatabase(pstate, (DropdbStmt *) parsetree);
     601          26 :             break;
     602             : 
     603             :             /* Query-level asynchronous notification */
     604             :         case T_NotifyStmt:
     605             :             {
     606          80 :                 NotifyStmt *stmt = (NotifyStmt *) parsetree;
     607             : 
     608          80 :                 PreventCommandDuringRecovery("NOTIFY");
     609          80 :                 Async_Notify(stmt->conditionname, stmt->payload);
     610             :             }
     611          80 :             break;
     612             : 
     613             :         case T_ListenStmt:
     614             :             {
     615          36 :                 ListenStmt *stmt = (ListenStmt *) parsetree;
     616             : 
     617          36 :                 PreventCommandDuringRecovery("LISTEN");
     618          36 :                 CheckRestrictedOperation("LISTEN");
     619          36 :                 Async_Listen(stmt->conditionname);
     620             :             }
     621          36 :             break;
     622             : 
     623             :         case T_UnlistenStmt:
     624             :             {
     625          28 :                 UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
     626             : 
     627             :                 /* we allow UNLISTEN during recovery, as it's a noop */
     628          28 :                 CheckRestrictedOperation("UNLISTEN");
     629          28 :                 if (stmt->conditionname)
     630           4 :                     Async_Unlisten(stmt->conditionname);
     631             :                 else
     632          24 :                     Async_UnlistenAll();
     633             :             }
     634          28 :             break;
     635             : 
     636             :         case T_LoadStmt:
     637             :             {
     638          18 :                 LoadStmt   *stmt = (LoadStmt *) parsetree;
     639             : 
     640          18 :                 closeAllVfds(); /* probably not necessary... */
     641             :                 /* Allowed names are restricted if you're not superuser */
     642          18 :                 load_file(stmt->filename, !superuser());
     643             :             }
     644          18 :             break;
     645             : 
     646             :         case T_CallStmt:
     647         234 :             ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
     648         198 :             break;
     649             : 
     650             :         case T_ClusterStmt:
     651             :             /* we choose to allow this during "read only" transactions */
     652          86 :             PreventCommandDuringRecovery("CLUSTER");
     653             :             /* forbidden in parallel mode due to CommandIsReadOnly */
     654          86 :             cluster((ClusterStmt *) parsetree, isTopLevel);
     655          78 :             break;
     656             : 
     657             :         case T_VacuumStmt:
     658             :             {
     659       12272 :                 VacuumStmt *stmt = (VacuumStmt *) parsetree;
     660             : 
     661             :                 /* we choose to allow this during "read only" transactions */
     662       12272 :                 PreventCommandDuringRecovery(stmt->is_vacuumcmd ?
     663             :                                              "VACUUM" : "ANALYZE");
     664             :                 /* forbidden in parallel mode due to CommandIsReadOnly */
     665       12272 :                 ExecVacuum(pstate, stmt, isTopLevel);
     666             :             }
     667       12180 :             break;
     668             : 
     669             :         case T_ExplainStmt:
     670        9234 :             ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
     671             :                          queryEnv, dest);
     672        9206 :             break;
     673             : 
     674             :         case T_AlterSystemStmt:
     675          30 :             PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
     676          30 :             AlterSystemSetConfigFile((AlterSystemStmt *) parsetree);
     677          30 :             break;
     678             : 
     679             :         case T_VariableSetStmt:
     680       15608 :             ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
     681       15566 :             break;
     682             : 
     683             :         case T_VariableShowStmt:
     684             :             {
     685         448 :                 VariableShowStmt *n = (VariableShowStmt *) parsetree;
     686             : 
     687         448 :                 GetPGVariable(n->name, dest);
     688             :             }
     689         448 :             break;
     690             : 
     691             :         case T_DiscardStmt:
     692             :             /* should we allow DISCARD PLANS? */
     693          20 :             CheckRestrictedOperation("DISCARD");
     694          20 :             DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
     695          20 :             break;
     696             : 
     697             :         case T_CreateEventTrigStmt:
     698             :             /* no event triggers on event triggers */
     699         108 :             CreateEventTrigger((CreateEventTrigStmt *) parsetree);
     700          64 :             break;
     701             : 
     702             :         case T_AlterEventTrigStmt:
     703             :             /* no event triggers on event triggers */
     704          20 :             AlterEventTrigger((AlterEventTrigStmt *) parsetree);
     705          20 :             break;
     706             : 
     707             :             /*
     708             :              * ******************************** ROLE statements ****
     709             :              */
     710             :         case T_CreateRoleStmt:
     711             :             /* no event triggers for global objects */
     712         728 :             CreateRole(pstate, (CreateRoleStmt *) parsetree);
     713         714 :             break;
     714             : 
     715             :         case T_AlterRoleStmt:
     716             :             /* no event triggers for global objects */
     717         218 :             AlterRole((AlterRoleStmt *) parsetree);
     718         194 :             break;
     719             : 
     720             :         case T_AlterRoleSetStmt:
     721             :             /* no event triggers for global objects */
     722          58 :             AlterRoleSet((AlterRoleSetStmt *) parsetree);
     723          50 :             break;
     724             : 
     725             :         case T_DropRoleStmt:
     726             :             /* no event triggers for global objects */
     727         740 :             DropRole((DropRoleStmt *) parsetree);
     728         654 :             break;
     729             : 
     730             :         case T_ReassignOwnedStmt:
     731             :             /* no event triggers for global objects */
     732          16 :             ReassignOwnedObjects((ReassignOwnedStmt *) parsetree);
     733           8 :             break;
     734             : 
     735             :         case T_LockStmt:
     736             : 
     737             :             /*
     738             :              * Since the lock would just get dropped immediately, LOCK TABLE
     739             :              * outside a transaction block is presumed to be user error.
     740             :              */
     741        3994 :             RequireTransactionBlock(isTopLevel, "LOCK TABLE");
     742             :             /* forbidden in parallel mode due to CommandIsReadOnly */
     743        3994 :             LockTableCommand((LockStmt *) parsetree);
     744        3932 :             break;
     745             : 
     746             :         case T_ConstraintsSetStmt:
     747          66 :             WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
     748          66 :             AfterTriggerSetState((ConstraintsSetStmt *) parsetree);
     749          54 :             break;
     750             : 
     751             :         case T_CheckPointStmt:
     752          78 :             if (!superuser())
     753           0 :                 ereport(ERROR,
     754             :                         (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
     755             :                          errmsg("must be superuser to do CHECKPOINT")));
     756             : 
     757             :             /*
     758             :              * You might think we should have a PreventCommandDuringRecovery()
     759             :              * here, but we interpret a CHECKPOINT command during recovery as
     760             :              * a request for a restartpoint instead. We allow this since it
     761             :              * can be a useful way of reducing switchover time when using
     762             :              * various forms of replication.
     763             :              */
     764          78 :             RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT |
     765          78 :                               (RecoveryInProgress() ? 0 : CHECKPOINT_FORCE));
     766          78 :             break;
     767             : 
     768             :         case T_ReindexStmt:
     769             :             {
     770         288 :                 ReindexStmt *stmt = (ReindexStmt *) parsetree;
     771             : 
     772         288 :                 if (stmt->concurrent)
     773         136 :                     PreventInTransactionBlock(isTopLevel,
     774             :                                               "REINDEX CONCURRENTLY");
     775             : 
     776             :                 /* we choose to allow this during "read only" transactions */
     777         284 :                 PreventCommandDuringRecovery("REINDEX");
     778             :                 /* forbidden in parallel mode due to CommandIsReadOnly */
     779         284 :                 switch (stmt->kind)
     780             :                 {
     781             :                     case REINDEX_OBJECT_INDEX:
     782          84 :                         ReindexIndex(stmt->relation, stmt->options, stmt->concurrent);
     783          52 :                         break;
     784             :                     case REINDEX_OBJECT_TABLE:
     785         132 :                         ReindexTable(stmt->relation, stmt->options, stmt->concurrent);
     786         116 :                         break;
     787             :                     case REINDEX_OBJECT_SCHEMA:
     788             :                     case REINDEX_OBJECT_SYSTEM:
     789             :                     case REINDEX_OBJECT_DATABASE:
     790             : 
     791             :                         /*
     792             :                          * This cannot run inside a user transaction block; if
     793             :                          * we were inside a transaction, then its commit- and
     794             :                          * start-transaction-command calls would not have the
     795             :                          * intended effect!
     796             :                          */
     797         104 :                         PreventInTransactionBlock(isTopLevel,
     798         104 :                                                   (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
     799          36 :                                                   (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
     800             :                                                   "REINDEX DATABASE");
     801          64 :                         ReindexMultipleTables(stmt->name, stmt->kind, stmt->options, stmt->concurrent);
     802          50 :                         break;
     803             :                     default:
     804           0 :                         elog(ERROR, "unrecognized object type: %d",
     805             :                              (int) stmt->kind);
     806             :                         break;
     807             :                 }
     808             :             }
     809         218 :             break;
     810             : 
     811             :             /*
     812             :              * The following statements are supported by Event Triggers only
     813             :              * in some cases, so we "fast path" them in the other cases.
     814             :              */
     815             : 
     816             :         case T_GrantStmt:
     817             :             {
     818       39550 :                 GrantStmt  *stmt = (GrantStmt *) parsetree;
     819             : 
     820       39550 :                 if (EventTriggerSupportsObjectType(stmt->objtype))
     821       38870 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     822             :                                        context, params, queryEnv,
     823             :                                        dest, completionTag);
     824             :                 else
     825         680 :                     ExecuteGrantStmt(stmt);
     826             :             }
     827       39474 :             break;
     828             : 
     829             :         case T_DropStmt:
     830             :             {
     831       13614 :                 DropStmt   *stmt = (DropStmt *) parsetree;
     832             : 
     833       13614 :                 if (EventTriggerSupportsObjectType(stmt->removeType))
     834       13552 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     835             :                                        context, params, queryEnv,
     836             :                                        dest, completionTag);
     837             :                 else
     838          62 :                     ExecDropStmt(stmt, isTopLevel);
     839             :             }
     840       13024 :             break;
     841             : 
     842             :         case T_RenameStmt:
     843             :             {
     844         718 :                 RenameStmt *stmt = (RenameStmt *) parsetree;
     845             : 
     846         718 :                 if (EventTriggerSupportsObjectType(stmt->renameType))
     847         694 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     848             :                                        context, params, queryEnv,
     849             :                                        dest, completionTag);
     850             :                 else
     851          24 :                     ExecRenameStmt(stmt);
     852             :             }
     853         486 :             break;
     854             : 
     855             :         case T_AlterObjectDependsStmt:
     856             :             {
     857          24 :                 AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
     858             : 
     859          24 :                 if (EventTriggerSupportsObjectType(stmt->objectType))
     860          24 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     861             :                                        context, params, queryEnv,
     862             :                                        dest, completionTag);
     863             :                 else
     864           0 :                     ExecAlterObjectDependsStmt(stmt, NULL);
     865             :             }
     866          24 :             break;
     867             : 
     868             :         case T_AlterObjectSchemaStmt:
     869             :             {
     870         240 :                 AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
     871             : 
     872         240 :                 if (EventTriggerSupportsObjectType(stmt->objectType))
     873         240 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     874             :                                        context, params, queryEnv,
     875             :                                        dest, completionTag);
     876             :                 else
     877           0 :                     ExecAlterObjectSchemaStmt(stmt, NULL);
     878             :             }
     879         160 :             break;
     880             : 
     881             :         case T_AlterOwnerStmt:
     882             :             {
     883        1076 :                 AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
     884             : 
     885        1076 :                 if (EventTriggerSupportsObjectType(stmt->objectType))
     886        1034 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     887             :                                        context, params, queryEnv,
     888             :                                        dest, completionTag);
     889             :                 else
     890          42 :                     ExecAlterOwnerStmt(stmt);
     891             :             }
     892         916 :             break;
     893             : 
     894             :         case T_CommentStmt:
     895             :             {
     896       16800 :                 CommentStmt *stmt = (CommentStmt *) parsetree;
     897             : 
     898       16800 :                 if (EventTriggerSupportsObjectType(stmt->objtype))
     899       16146 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     900             :                                        context, params, queryEnv,
     901             :                                        dest, completionTag);
     902             :                 else
     903         654 :                     CommentObject(stmt);
     904       16710 :                 break;
     905             :             }
     906             : 
     907             :         case T_SecLabelStmt:
     908             :             {
     909          84 :                 SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
     910             : 
     911          84 :                 if (EventTriggerSupportsObjectType(stmt->objtype))
     912          54 :                     ProcessUtilitySlow(pstate, pstmt, queryString,
     913             :                                        context, params, queryEnv,
     914             :                                        dest, completionTag);
     915             :                 else
     916          30 :                     ExecSecLabelStmt(stmt);
     917          28 :                 break;
     918             :             }
     919             : 
     920             :         default:
     921             :             /* All other statement types have event trigger support */
     922      153556 :             ProcessUtilitySlow(pstate, pstmt, queryString,
     923             :                                context, params, queryEnv,
     924             :                                dest, completionTag);
     925      149180 :             break;
     926             :     }
     927             : 
     928      305394 :     free_parsestate(pstate);
     929             : 
     930             :     /*
     931             :      * Make effects of commands visible, for instance so that
     932             :      * PreCommit_on_commit_actions() can see them (see for example bug
     933             :      * #15631).
     934             :      */
     935      305394 :     CommandCounterIncrement();
     936      305394 : }
     937             : 
     938             : /*
     939             :  * The "Slow" variant of ProcessUtility should only receive statements
     940             :  * supported by the event triggers facility.  Therefore, we always
     941             :  * perform the trigger support calls if the context allows it.
     942             :  */
     943             : static void
     944      224170 : ProcessUtilitySlow(ParseState *pstate,
     945             :                    PlannedStmt *pstmt,
     946             :                    const char *queryString,
     947             :                    ProcessUtilityContext context,
     948             :                    ParamListInfo params,
     949             :                    QueryEnvironment *queryEnv,
     950             :                    DestReceiver *dest,
     951             :                    char *completionTag)
     952             : {
     953      224170 :     Node       *parsetree = pstmt->utilityStmt;
     954      224170 :     bool        isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
     955      224170 :     bool        isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
     956             :     bool        needCleanup;
     957      224170 :     bool        commandCollected = false;
     958             :     ObjectAddress address;
     959      224170 :     ObjectAddress secondaryObject = InvalidObjectAddress;
     960             : 
     961             :     /* All event trigger calls are done only when isCompleteQuery is true */
     962      224170 :     needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
     963             : 
     964             :     /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
     965      224170 :     PG_TRY();
     966             :     {
     967      224170 :         if (isCompleteQuery)
     968      217526 :             EventTriggerDDLCommandStart(parsetree);
     969             : 
     970      224170 :         switch (nodeTag(parsetree))
     971             :         {
     972             :                 /*
     973             :                  * relation and attribute manipulation
     974             :                  */
     975             :             case T_CreateSchemaStmt:
     976         666 :                 CreateSchemaCommand((CreateSchemaStmt *) parsetree,
     977             :                                     queryString,
     978             :                                     pstmt->stmt_location,
     979             :                                     pstmt->stmt_len);
     980             : 
     981             :                 /*
     982             :                  * EventTriggerCollectSimpleCommand called by
     983             :                  * CreateSchemaCommand
     984             :                  */
     985         646 :                 commandCollected = true;
     986         646 :                 break;
     987             : 
     988             :             case T_CreateStmt:
     989             :             case T_CreateForeignTableStmt:
     990             :                 {
     991             :                     List       *stmts;
     992             :                     ListCell   *l;
     993             : 
     994             :                     /* Run parse analysis ... */
     995       20854 :                     stmts = transformCreateStmt((CreateStmt *) parsetree,
     996             :                                                 queryString);
     997             : 
     998             :                     /* ... and do it */
     999       46940 :                     foreach(l, stmts)
    1000             :                     {
    1001       26998 :                         Node       *stmt = (Node *) lfirst(l);
    1002             : 
    1003       26998 :                         if (IsA(stmt, CreateStmt))
    1004             :                         {
    1005             :                             Datum       toast_options;
    1006             :                             static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
    1007             : 
    1008             :                             /* Create the table itself */
    1009       20470 :                             address = DefineRelation((CreateStmt *) stmt,
    1010             :                                                      RELKIND_RELATION,
    1011             :                                                      InvalidOid, NULL,
    1012             :                                                      queryString);
    1013       19874 :                             EventTriggerCollectSimpleCommand(address,
    1014             :                                                              secondaryObject,
    1015             :                                                              stmt);
    1016             : 
    1017             :                             /*
    1018             :                              * Let NewRelationCreateToastTable decide if this
    1019             :                              * one needs a secondary relation too.
    1020             :                              */
    1021       19874 :                             CommandCounterIncrement();
    1022             : 
    1023             :                             /*
    1024             :                              * parse and validate reloptions for the toast
    1025             :                              * table
    1026             :                              */
    1027       19874 :                             toast_options = transformRelOptions((Datum) 0,
    1028             :                                                                 ((CreateStmt *) stmt)->options,
    1029             :                                                                 "toast",
    1030             :                                                                 validnsps,
    1031             :                                                                 true,
    1032             :                                                                 false);
    1033       19874 :                             (void) heap_reloptions(RELKIND_TOASTVALUE,
    1034             :                                                    toast_options,
    1035             :                                                    true);
    1036             : 
    1037       19870 :                             NewRelationCreateToastTable(address.objectId,
    1038             :                                                         toast_options);
    1039             :                         }
    1040        6528 :                         else if (IsA(stmt, CreateForeignTableStmt))
    1041             :                         {
    1042             :                             /* Create the table itself */
    1043         270 :                             address = DefineRelation((CreateStmt *) stmt,
    1044             :                                                      RELKIND_FOREIGN_TABLE,
    1045             :                                                      InvalidOid, NULL,
    1046             :                                                      queryString);
    1047         256 :                             CreateForeignTable((CreateForeignTableStmt *) stmt,
    1048             :                                                address.objectId);
    1049         204 :                             EventTriggerCollectSimpleCommand(address,
    1050             :                                                              secondaryObject,
    1051             :                                                              stmt);
    1052             :                         }
    1053             :                         else
    1054             :                         {
    1055             :                             /*
    1056             :                              * Recurse for anything else.  Note the recursive
    1057             :                              * call will stash the objects so created into our
    1058             :                              * event trigger context.
    1059             :                              */
    1060             :                             PlannedStmt *wrapper;
    1061             : 
    1062        6258 :                             wrapper = makeNode(PlannedStmt);
    1063        6258 :                             wrapper->commandType = CMD_UTILITY;
    1064        6258 :                             wrapper->canSetTag = false;
    1065        6258 :                             wrapper->utilityStmt = stmt;
    1066        6258 :                             wrapper->stmt_location = pstmt->stmt_location;
    1067        6258 :                             wrapper->stmt_len = pstmt->stmt_len;
    1068             : 
    1069        6258 :                             ProcessUtility(wrapper,
    1070             :                                            queryString,
    1071             :                                            PROCESS_UTILITY_SUBCOMMAND,
    1072             :                                            params,
    1073             :                                            NULL,
    1074             :                                            None_Receiver,
    1075             :                                            NULL);
    1076             :                         }
    1077             : 
    1078             :                         /* Need CCI between commands */
    1079       26188 :                         if (lnext(stmts, l) != NULL)
    1080        6254 :                             CommandCounterIncrement();
    1081             :                     }
    1082             : 
    1083             :                     /*
    1084             :                      * The multiple commands generated here are stashed
    1085             :                      * individually, so disable collection below.
    1086             :                      */
    1087       19942 :                     commandCollected = true;
    1088             :                 }
    1089       19942 :                 break;
    1090             : 
    1091             :             case T_AlterTableStmt:
    1092             :                 {
    1093       10514 :                     AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
    1094             :                     Oid         relid;
    1095             :                     List       *stmts;
    1096             :                     ListCell   *l;
    1097             :                     LOCKMODE    lockmode;
    1098             : 
    1099             :                     /*
    1100             :                      * Figure out lock mode, and acquire lock.  This also does
    1101             :                      * basic permissions checks, so that we won't wait for a
    1102             :                      * lock on (for example) a relation on which we have no
    1103             :                      * permissions.
    1104             :                      */
    1105       10514 :                     lockmode = AlterTableGetLockLevel(atstmt->cmds);
    1106       10514 :                     relid = AlterTableLookupRelation(atstmt, lockmode);
    1107             : 
    1108       10478 :                     if (OidIsValid(relid))
    1109             :                     {
    1110             :                         /* Run parse analysis ... */
    1111       10386 :                         stmts = transformAlterTableStmt(relid, atstmt,
    1112             :                                                         queryString);
    1113             : 
    1114             :                         /* ... ensure we have an event trigger context ... */
    1115       10354 :                         EventTriggerAlterTableStart(parsetree);
    1116       10354 :                         EventTriggerAlterTableRelid(relid);
    1117             : 
    1118             :                         /* ... and do it */
    1119       19400 :                         foreach(l, stmts)
    1120             :                         {
    1121       10542 :                             Node       *stmt = (Node *) lfirst(l);
    1122             : 
    1123       10542 :                             if (IsA(stmt, AlterTableStmt))
    1124             :                             {
    1125             :                                 /* Do the table alteration proper */
    1126       10350 :                                 AlterTable(relid, lockmode,
    1127             :                                            (AlterTableStmt *) stmt);
    1128             :                             }
    1129             :                             else
    1130             :                             {
    1131             :                                 /*
    1132             :                                  * Recurse for anything else.  If we need to
    1133             :                                  * do so, "close" the current complex-command
    1134             :                                  * set, and start a new one at the bottom;
    1135             :                                  * this is needed to ensure the ordering of
    1136             :                                  * queued commands is consistent with the way
    1137             :                                  * they are executed here.
    1138             :                                  */
    1139             :                                 PlannedStmt *wrapper;
    1140             : 
    1141         192 :                                 EventTriggerAlterTableEnd();
    1142         192 :                                 wrapper = makeNode(PlannedStmt);
    1143         192 :                                 wrapper->commandType = CMD_UTILITY;
    1144         192 :                                 wrapper->canSetTag = false;
    1145         192 :                                 wrapper->utilityStmt = stmt;
    1146         192 :                                 wrapper->stmt_location = pstmt->stmt_location;
    1147         192 :                                 wrapper->stmt_len = pstmt->stmt_len;
    1148         192 :                                 ProcessUtility(wrapper,
    1149             :                                                queryString,
    1150             :                                                PROCESS_UTILITY_SUBCOMMAND,
    1151             :                                                params,
    1152             :                                                NULL,
    1153             :                                                None_Receiver,
    1154             :                                                NULL);
    1155         184 :                                 EventTriggerAlterTableStart(parsetree);
    1156         184 :                                 EventTriggerAlterTableRelid(relid);
    1157             :                             }
    1158             : 
    1159             :                             /* Need CCI between commands */
    1160        9046 :                             if (lnext(stmts, l) != NULL)
    1161         188 :                                 CommandCounterIncrement();
    1162             :                         }
    1163             : 
    1164             :                         /* done */
    1165        8858 :                         EventTriggerAlterTableEnd();
    1166             :                     }
    1167             :                     else
    1168          92 :                         ereport(NOTICE,
    1169             :                                 (errmsg("relation \"%s\" does not exist, skipping",
    1170             :                                         atstmt->relation->relname)));
    1171             :                 }
    1172             : 
    1173             :                 /* ALTER TABLE stashes commands internally */
    1174        8950 :                 commandCollected = true;
    1175        8950 :                 break;
    1176             : 
    1177             :             case T_AlterDomainStmt:
    1178             :                 {
    1179         152 :                     AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
    1180             : 
    1181             :                     /*
    1182             :                      * Some or all of these functions are recursive to cover
    1183             :                      * inherited things, so permission checks are done there.
    1184             :                      */
    1185         152 :                     switch (stmt->subtype)
    1186             :                     {
    1187             :                         case 'T':   /* ALTER DOMAIN DEFAULT */
    1188             : 
    1189             :                             /*
    1190             :                              * Recursively alter column default for table and,
    1191             :                              * if requested, for descendants
    1192             :                              */
    1193           8 :                             address =
    1194           8 :                                 AlterDomainDefault(stmt->typeName,
    1195             :                                                    stmt->def);
    1196           8 :                             break;
    1197             :                         case 'N':   /* ALTER DOMAIN DROP NOT NULL */
    1198           8 :                             address =
    1199           8 :                                 AlterDomainNotNull(stmt->typeName,
    1200             :                                                    false);
    1201           8 :                             break;
    1202             :                         case 'O':   /* ALTER DOMAIN SET NOT NULL */
    1203          16 :                             address =
    1204          16 :                                 AlterDomainNotNull(stmt->typeName,
    1205             :                                                    true);
    1206           8 :                             break;
    1207             :                         case 'C':   /* ADD CONSTRAINT */
    1208          84 :                             address =
    1209          84 :                                 AlterDomainAddConstraint(stmt->typeName,
    1210             :                                                          stmt->def,
    1211             :                                                          &secondaryObject);
    1212          44 :                             break;
    1213             :                         case 'X':   /* DROP CONSTRAINT */
    1214          28 :                             address =
    1215          56 :                                 AlterDomainDropConstraint(stmt->typeName,
    1216          28 :                                                           stmt->name,
    1217             :                                                           stmt->behavior,
    1218          28 :                                                           stmt->missing_ok);
    1219          24 :                             break;
    1220             :                         case 'V':   /* VALIDATE CONSTRAINT */
    1221           8 :                             address =
    1222           8 :                                 AlterDomainValidateConstraint(stmt->typeName,
    1223           8 :                                                               stmt->name);
    1224           4 :                             break;
    1225             :                         default:    /* oops */
    1226           0 :                             elog(ERROR, "unrecognized alter domain type: %d",
    1227             :                                  (int) stmt->subtype);
    1228             :                             break;
    1229             :                     }
    1230             :                 }
    1231          96 :                 break;
    1232             : 
    1233             :                 /*
    1234             :                  * ************* object creation / destruction **************
    1235             :                  */
    1236             :             case T_DefineStmt:
    1237             :                 {
    1238       16932 :                     DefineStmt *stmt = (DefineStmt *) parsetree;
    1239             : 
    1240       16932 :                     switch (stmt->kind)
    1241             :                     {
    1242             :                         case OBJECT_AGGREGATE:
    1243         622 :                             address =
    1244        1244 :                                 DefineAggregate(pstate, stmt->defnames, stmt->args,
    1245         622 :                                                 stmt->oldstyle,
    1246             :                                                 stmt->definition,
    1247         622 :                                                 stmt->replace);
    1248         408 :                             break;
    1249             :                         case OBJECT_OPERATOR:
    1250             :                             Assert(stmt->args == NIL);
    1251        1320 :                             address = DefineOperator(stmt->defnames,
    1252             :                                                      stmt->definition);
    1253        1276 :                             break;
    1254             :                         case OBJECT_TYPE:
    1255             :                             Assert(stmt->args == NIL);
    1256         256 :                             address = DefineType(pstate,
    1257             :                                                  stmt->defnames,
    1258             :                                                  stmt->definition);
    1259         240 :                             break;
    1260             :                         case OBJECT_TSPARSER:
    1261             :                             Assert(stmt->args == NIL);
    1262          28 :                             address = DefineTSParser(stmt->defnames,
    1263             :                                                      stmt->definition);
    1264          24 :                             break;
    1265             :                         case OBJECT_TSDICTIONARY:
    1266             :                             Assert(stmt->args == NIL);
    1267        7190 :                             address = DefineTSDictionary(stmt->defnames,
    1268             :                                                          stmt->definition);
    1269        7174 :                             break;
    1270             :                         case OBJECT_TSTEMPLATE:
    1271             :                             Assert(stmt->args == NIL);
    1272         354 :                             address = DefineTSTemplate(stmt->defnames,
    1273             :                                                        stmt->definition);
    1274         350 :                             break;
    1275             :                         case OBJECT_TSCONFIGURATION:
    1276             :                             Assert(stmt->args == NIL);
    1277        7142 :                             address = DefineTSConfiguration(stmt->defnames,
    1278             :                                                             stmt->definition,
    1279             :                                                             &secondaryObject);
    1280        7142 :                             break;
    1281             :                         case OBJECT_COLLATION:
    1282             :                             Assert(stmt->args == NIL);
    1283          20 :                             address = DefineCollation(pstate,
    1284             :                                                       stmt->defnames,
    1285             :                                                       stmt->definition,
    1286          20 :                                                       stmt->if_not_exists);
    1287          12 :                             break;
    1288             :                         default:
    1289           0 :                             elog(ERROR, "unrecognized define stmt type: %d",
    1290             :                                  (int) stmt->kind);
    1291             :                             break;
    1292             :                     }
    1293             :                 }
    1294       16626 :                 break;
    1295             : 
    1296             :             case T_IndexStmt:   /* CREATE INDEX */
    1297             :                 {
    1298        7228 :                     IndexStmt  *stmt = (IndexStmt *) parsetree;
    1299             :                     Oid         relid;
    1300             :                     LOCKMODE    lockmode;
    1301             : 
    1302        7228 :                     if (stmt->concurrent)
    1303          56 :                         PreventInTransactionBlock(isTopLevel,
    1304             :                                                   "CREATE INDEX CONCURRENTLY");
    1305             : 
    1306             :                     /*
    1307             :                      * Look up the relation OID just once, right here at the
    1308             :                      * beginning, so that we don't end up repeating the name
    1309             :                      * lookup later and latching onto a different relation
    1310             :                      * partway through.  To avoid lock upgrade hazards, it's
    1311             :                      * important that we take the strongest lock that will
    1312             :                      * eventually be needed here, so the lockmode calculation
    1313             :                      * needs to match what DefineIndex() does.
    1314             :                      */
    1315       14448 :                     lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
    1316        7224 :                         : ShareLock;
    1317        7224 :                     relid =
    1318        7224 :                         RangeVarGetRelidExtended(stmt->relation, lockmode,
    1319             :                                                  0,
    1320             :                                                  RangeVarCallbackOwnsRelation,
    1321             :                                                  NULL);
    1322             : 
    1323             :                     /*
    1324             :                      * CREATE INDEX on partitioned tables (but not regular
    1325             :                      * inherited tables) recurses to partitions, so we must
    1326             :                      * acquire locks early to avoid deadlocks.
    1327             :                      *
    1328             :                      * We also take the opportunity to verify that all
    1329             :                      * partitions are something we can put an index on, to
    1330             :                      * avoid building some indexes only to fail later.
    1331             :                      */
    1332       14356 :                     if (stmt->relation->inh &&
    1333        7136 :                         get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
    1334             :                     {
    1335             :                         ListCell   *lc;
    1336         478 :                         List       *inheritors = NIL;
    1337             : 
    1338         478 :                         inheritors = find_all_inheritors(relid, lockmode, NULL);
    1339        1234 :                         foreach(lc, inheritors)
    1340             :                         {
    1341         764 :                             char        relkind = get_rel_relkind(lfirst_oid(lc));
    1342             : 
    1343         764 :                             if (relkind != RELKIND_RELATION &&
    1344         534 :                                 relkind != RELKIND_MATVIEW &&
    1345          12 :                                 relkind != RELKIND_PARTITIONED_TABLE &&
    1346             :                                 relkind != RELKIND_FOREIGN_TABLE)
    1347           0 :                                 elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
    1348             :                                      relkind, stmt->relation->relname);
    1349             : 
    1350         776 :                             if (relkind == RELKIND_FOREIGN_TABLE &&
    1351          16 :                                 (stmt->unique || stmt->primary))
    1352           8 :                                 ereport(ERROR,
    1353             :                                         (errcode(ERRCODE_WRONG_OBJECT_TYPE),
    1354             :                                          errmsg("cannot create unique index on partitioned table \"%s\"",
    1355             :                                                 stmt->relation->relname),
    1356             :                                          errdetail("Table \"%s\" contains partitions that are foreign tables.",
    1357             :                                                    stmt->relation->relname)));
    1358             :                         }
    1359         470 :                         list_free(inheritors);
    1360             :                     }
    1361             : 
    1362             :                     /* Run parse analysis ... */
    1363        7212 :                     stmt = transformIndexStmt(relid, stmt, queryString);
    1364             : 
    1365             :                     /* ... and do it */
    1366        7208 :                     EventTriggerAlterTableStart(parsetree);
    1367        7208 :                     address =
    1368             :                         DefineIndex(relid,  /* OID of heap relation */
    1369             :                                     stmt,
    1370             :                                     InvalidOid, /* no predefined OID */
    1371             :                                     InvalidOid, /* no parent index */
    1372             :                                     InvalidOid, /* no parent constraint */
    1373             :                                     false,  /* is_alter_table */
    1374             :                                     true,   /* check_rights */
    1375             :                                     true,   /* check_not_in_use */
    1376             :                                     false,  /* skip_build */
    1377             :                                     false); /* quiet */
    1378             : 
    1379             :                     /*
    1380             :                      * Add the CREATE INDEX node itself to stash right away;
    1381             :                      * if there were any commands stashed in the ALTER TABLE
    1382             :                      * code, we need them to appear after this one.
    1383             :                      */
    1384        7044 :                     EventTriggerCollectSimpleCommand(address, secondaryObject,
    1385             :                                                      parsetree);
    1386        7044 :                     commandCollected = true;
    1387        7044 :                     EventTriggerAlterTableEnd();
    1388             :                 }
    1389        7044 :                 break;
    1390             : 
    1391             :             case T_CreateExtensionStmt:
    1392         504 :                 address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
    1393         492 :                 break;
    1394             : 
    1395             :             case T_AlterExtensionStmt:
    1396           2 :                 address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
    1397           2 :                 break;
    1398             : 
    1399             :             case T_AlterExtensionContentsStmt:
    1400         118 :                 address = ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree,
    1401             :                                                          &secondaryObject);
    1402         118 :                 break;
    1403             : 
    1404             :             case T_CreateFdwStmt:
    1405         112 :                 address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
    1406          78 :                 break;
    1407             : 
    1408             :             case T_AlterFdwStmt:
    1409          76 :                 address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
    1410          32 :                 break;
    1411             : 
    1412             :             case T_CreateForeignServerStmt:
    1413         162 :                 address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
    1414         132 :                 break;
    1415             : 
    1416             :             case T_AlterForeignServerStmt:
    1417          92 :                 address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
    1418          62 :                 break;
    1419             : 
    1420             :             case T_CreateUserMappingStmt:
    1421         168 :                 address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
    1422         122 :                 break;
    1423             : 
    1424             :             case T_AlterUserMappingStmt:
    1425          68 :                 address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
    1426          38 :                 break;
    1427             : 
    1428             :             case T_DropUserMappingStmt:
    1429          88 :                 RemoveUserMapping((DropUserMappingStmt *) parsetree);
    1430             :                 /* no commands stashed for DROP */
    1431          62 :                 commandCollected = true;
    1432          62 :                 break;
    1433             : 
    1434             :             case T_ImportForeignSchemaStmt:
    1435          36 :                 ImportForeignSchema((ImportForeignSchemaStmt *) parsetree);
    1436             :                 /* commands are stashed inside ImportForeignSchema */
    1437          10 :                 commandCollected = true;
    1438          10 :                 break;
    1439             : 
    1440             :             case T_CompositeTypeStmt:   /* CREATE TYPE (composite) */
    1441             :                 {
    1442         414 :                     CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
    1443             : 
    1444         414 :                     address = DefineCompositeType(stmt->typevar,
    1445             :                                                   stmt->coldeflist);
    1446             :                 }
    1447         406 :                 break;
    1448             : 
    1449             :             case T_CreateEnumStmt:  /* CREATE TYPE AS ENUM */
    1450         348 :                 address = DefineEnum((CreateEnumStmt *) parsetree);
    1451         348 :                 break;
    1452             : 
    1453             :             case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
    1454          58 :                 address = DefineRange((CreateRangeStmt *) parsetree);
    1455          54 :                 break;
    1456             : 
    1457             :             case T_AlterEnumStmt:   /* ALTER TYPE (enum) */
    1458         280 :                 address = AlterEnum((AlterEnumStmt *) parsetree);
    1459         260 :                 break;
    1460             : 
    1461             :             case T_ViewStmt:    /* CREATE VIEW */
    1462       41426 :                 EventTriggerAlterTableStart(parsetree);
    1463       41426 :                 address = DefineView((ViewStmt *) parsetree, queryString,
    1464             :                                      pstmt->stmt_location, pstmt->stmt_len);
    1465       41390 :                 EventTriggerCollectSimpleCommand(address, secondaryObject,
    1466             :                                                  parsetree);
    1467             :                 /* stashed internally */
    1468       41390 :                 commandCollected = true;
    1469       41390 :                 EventTriggerAlterTableEnd();
    1470       41390 :                 break;
    1471             : 
    1472             :             case T_CreateFunctionStmt:  /* CREATE FUNCTION */
    1473       21132 :                 address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
    1474       20886 :                 break;
    1475             : 
    1476             :             case T_AlterFunctionStmt:   /* ALTER FUNCTION */
    1477         102 :                 address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
    1478          82 :                 break;
    1479             : 
    1480             :             case T_RuleStmt:    /* CREATE RULE */
    1481        1134 :                 address = DefineRule((RuleStmt *) parsetree, queryString);
    1482        1106 :                 break;
    1483             : 
    1484             :             case T_CreateSeqStmt:
    1485         982 :                 address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
    1486         914 :                 break;
    1487             : 
    1488             :             case T_AlterSeqStmt:
    1489         742 :                 address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
    1490         710 :                 break;
    1491             : 
    1492             :             case T_CreateTableAsStmt:
    1493         832 :                 address = ExecCreateTableAs((CreateTableAsStmt *) parsetree,
    1494             :                                             queryString, params, queryEnv,
    1495             :                                             completionTag);
    1496         772 :                 break;
    1497             : 
    1498             :             case T_RefreshMatViewStmt:
    1499             : 
    1500             :                 /*
    1501             :                  * REFRESH CONCURRENTLY executes some DDL commands internally.
    1502             :                  * Inhibit DDL command collection here to avoid those commands
    1503             :                  * from showing up in the deparsed command queue.  The refresh
    1504             :                  * command itself is queued, which is enough.
    1505             :                  */
    1506          90 :                 EventTriggerInhibitCommandCollection();
    1507          90 :                 PG_TRY();
    1508             :                 {
    1509          90 :                     address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
    1510             :                                                  queryString, params, completionTag);
    1511             :                 }
    1512          20 :                 PG_FINALLY();
    1513             :                 {
    1514          90 :                     EventTriggerUndoInhibitCommandCollection();
    1515             :                 }
    1516          90 :                 PG_END_TRY();
    1517          70 :                 break;
    1518             : 
    1519             :             case T_CreateTrigStmt:
    1520        1972 :                 address = CreateTrigger((CreateTrigStmt *) parsetree,
    1521             :                                         queryString, InvalidOid, InvalidOid,
    1522             :                                         InvalidOid, InvalidOid, InvalidOid,
    1523             :                                         InvalidOid, NULL, false, false);
    1524        1840 :                 break;
    1525             : 
    1526             :             case T_CreatePLangStmt:
    1527         364 :                 address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
    1528         364 :                 break;
    1529             : 
    1530             :             case T_CreateDomainStmt:
    1531        2040 :                 address = DefineDomain((CreateDomainStmt *) parsetree);
    1532        2032 :                 break;
    1533             : 
    1534             :             case T_CreateConversionStmt:
    1535          44 :                 address = CreateConversionCommand((CreateConversionStmt *) parsetree);
    1536          36 :                 break;
    1537             : 
    1538             :             case T_CreateCastStmt:
    1539         198 :                 address = CreateCast((CreateCastStmt *) parsetree);
    1540         194 :                 break;
    1541             : 
    1542             :             case T_CreateOpClassStmt:
    1543         306 :                 DefineOpClass((CreateOpClassStmt *) parsetree);
    1544             :                 /* command is stashed in DefineOpClass */
    1545         306 :                 commandCollected = true;
    1546         306 :                 break;
    1547             : 
    1548             :             case T_CreateOpFamilyStmt:
    1549          98 :                 address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
    1550          98 :                 break;
    1551             : 
    1552             :             case T_CreateTransformStmt:
    1553          50 :                 address = CreateTransform((CreateTransformStmt *) parsetree);
    1554          40 :                 break;
    1555             : 
    1556             :             case T_AlterOpFamilyStmt:
    1557         286 :                 AlterOpFamily((AlterOpFamilyStmt *) parsetree);
    1558             :                 /* commands are stashed in AlterOpFamily */
    1559         198 :                 commandCollected = true;
    1560         198 :                 break;
    1561             : 
    1562             :             case T_AlterTSDictionaryStmt:
    1563          14 :                 address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
    1564          14 :                 break;
    1565             : 
    1566             :             case T_AlterTSConfigurationStmt:
    1567       21432 :                 AlterTSConfiguration((AlterTSConfigurationStmt *) parsetree);
    1568             : 
    1569             :                 /*
    1570             :                  * Commands are stashed in MakeConfigurationMapping and
    1571             :                  * DropConfigurationMapping, which are called from
    1572             :                  * AlterTSConfiguration
    1573             :                  */
    1574       21432 :                 commandCollected = true;
    1575       21432 :                 break;
    1576             : 
    1577             :             case T_AlterTableMoveAllStmt:
    1578          12 :                 AlterTableMoveAll((AlterTableMoveAllStmt *) parsetree);
    1579             :                 /* commands are stashed in AlterTableMoveAll */
    1580          12 :                 commandCollected = true;
    1581          12 :                 break;
    1582             : 
    1583             :             case T_DropStmt:
    1584       13552 :                 ExecDropStmt((DropStmt *) parsetree, isTopLevel);
    1585             :                 /* no commands stashed for DROP */
    1586       12978 :                 commandCollected = true;
    1587       12978 :                 break;
    1588             : 
    1589             :             case T_RenameStmt:
    1590         694 :                 address = ExecRenameStmt((RenameStmt *) parsetree);
    1591         466 :                 break;
    1592             : 
    1593             :             case T_AlterObjectDependsStmt:
    1594          24 :                 address =
    1595             :                     ExecAlterObjectDependsStmt((AlterObjectDependsStmt *) parsetree,
    1596             :                                                &secondaryObject);
    1597          24 :                 break;
    1598             : 
    1599             :             case T_AlterObjectSchemaStmt:
    1600         240 :                 address =
    1601             :                     ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree,
    1602             :                                               &secondaryObject);
    1603         160 :                 break;
    1604             : 
    1605             :             case T_AlterOwnerStmt:
    1606        1034 :                 address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
    1607         878 :                 break;
    1608             : 
    1609             :             case T_AlterOperatorStmt:
    1610         216 :                 address = AlterOperator((AlterOperatorStmt *) parsetree);
    1611         184 :                 break;
    1612             : 
    1613             :             case T_CommentStmt:
    1614       16146 :                 address = CommentObject((CommentStmt *) parsetree);
    1615       16056 :                 break;
    1616             : 
    1617             :             case T_GrantStmt:
    1618       38870 :                 ExecuteGrantStmt((GrantStmt *) parsetree);
    1619             :                 /* commands are stashed in ExecGrantStmt_oids */
    1620       38794 :                 commandCollected = true;
    1621       38794 :                 break;
    1622             : 
    1623             :             case T_DropOwnedStmt:
    1624          68 :                 DropOwnedObjects((DropOwnedStmt *) parsetree);
    1625             :                 /* no commands stashed for DROP */
    1626          56 :                 commandCollected = true;
    1627          56 :                 break;
    1628             : 
    1629             :             case T_AlterDefaultPrivilegesStmt:
    1630          80 :                 ExecAlterDefaultPrivilegesStmt(pstate, (AlterDefaultPrivilegesStmt *) parsetree);
    1631          76 :                 EventTriggerCollectAlterDefPrivs((AlterDefaultPrivilegesStmt *) parsetree);
    1632          76 :                 commandCollected = true;
    1633          76 :                 break;
    1634             : 
    1635             :             case T_CreatePolicyStmt:    /* CREATE POLICY */
    1636         390 :                 address = CreatePolicy((CreatePolicyStmt *) parsetree);
    1637         382 :                 break;
    1638             : 
    1639             :             case T_AlterPolicyStmt: /* ALTER POLICY */
    1640          56 :                 address = AlterPolicy((AlterPolicyStmt *) parsetree);
    1641          48 :                 break;
    1642             : 
    1643             :             case T_SecLabelStmt:
    1644          54 :                 address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
    1645          24 :                 break;
    1646             : 
    1647             :             case T_CreateAmStmt:
    1648          44 :                 address = CreateAccessMethod((CreateAmStmt *) parsetree);
    1649          28 :                 break;
    1650             : 
    1651             :             case T_CreatePublicationStmt:
    1652          90 :                 address = CreatePublication((CreatePublicationStmt *) parsetree);
    1653          70 :                 break;
    1654             : 
    1655             :             case T_AlterPublicationStmt:
    1656          82 :                 AlterPublication((AlterPublicationStmt *) parsetree);
    1657             : 
    1658             :                 /*
    1659             :                  * AlterPublication calls EventTriggerCollectSimpleCommand
    1660             :                  * directly
    1661             :                  */
    1662          50 :                 commandCollected = true;
    1663          50 :                 break;
    1664             : 
    1665             :             case T_CreateSubscriptionStmt:
    1666         102 :                 address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
    1667             :                                              isTopLevel);
    1668          50 :                 break;
    1669             : 
    1670             :             case T_AlterSubscriptionStmt:
    1671          66 :                 address = AlterSubscription((AlterSubscriptionStmt *) parsetree);
    1672          42 :                 break;
    1673             : 
    1674             :             case T_DropSubscriptionStmt:
    1675          40 :                 DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
    1676             :                 /* no commands stashed for DROP */
    1677          32 :                 commandCollected = true;
    1678          32 :                 break;
    1679             : 
    1680             :             case T_CreateStatsStmt:
    1681         176 :                 address = CreateStatistics((CreateStatsStmt *) parsetree);
    1682         132 :                 break;
    1683             : 
    1684             :             case T_AlterStatsStmt:
    1685          18 :                 address = AlterStatistics((AlterStatsStmt *) parsetree);
    1686          14 :                 break;
    1687             : 
    1688             :             case T_AlterCollationStmt:
    1689           0 :                 address = AlterCollation((AlterCollationStmt *) parsetree);
    1690           0 :                 break;
    1691             : 
    1692             :             default:
    1693           0 :                 elog(ERROR, "unrecognized node type: %d",
    1694             :                      (int) nodeTag(parsetree));
    1695             :                 break;
    1696             :         }
    1697             : 
    1698             :         /*
    1699             :          * Remember the object so that ddl_command_end event triggers have
    1700             :          * access to it.
    1701             :          */
    1702      218560 :         if (!commandCollected)
    1703       66582 :             EventTriggerCollectSimpleCommand(address, secondaryObject,
    1704             :                                              parsetree);
    1705             : 
    1706      218560 :         if (isCompleteQuery)
    1707             :         {
    1708      212076 :             EventTriggerSQLDrop(parsetree);
    1709      212064 :             EventTriggerDDLCommandEnd(parsetree);
    1710             :         }
    1711             :     }
    1712        5622 :     PG_FINALLY();
    1713             :     {
    1714      224170 :         if (needCleanup)
    1715         976 :             EventTriggerEndCompleteQuery();
    1716             :     }
    1717      224170 :     PG_END_TRY();
    1718      218548 : }
    1719             : 
    1720             : /*
    1721             :  * Dispatch function for DropStmt
    1722             :  */
    1723             : static void
    1724       13614 : ExecDropStmt(DropStmt *stmt, bool isTopLevel)
    1725             : {
    1726       13614 :     switch (stmt->removeType)
    1727             :     {
    1728             :         case OBJECT_INDEX:
    1729         346 :             if (stmt->concurrent)
    1730          38 :                 PreventInTransactionBlock(isTopLevel,
    1731             :                                           "DROP INDEX CONCURRENTLY");
    1732             :             /* fall through */
    1733             : 
    1734             :         case OBJECT_TABLE:
    1735             :         case OBJECT_SEQUENCE:
    1736             :         case OBJECT_VIEW:
    1737             :         case OBJECT_MATVIEW:
    1738             :         case OBJECT_FOREIGN_TABLE:
    1739        9462 :             RemoveRelations(stmt);
    1740        9274 :             break;
    1741             :         default:
    1742        4148 :             RemoveObjects(stmt);
    1743        3762 :             break;
    1744             :     }
    1745       13036 : }
    1746             : 
    1747             : 
    1748             : /*
    1749             :  * UtilityReturnsTuples
    1750             :  *      Return "true" if this utility statement will send output to the
    1751             :  *      destination.
    1752             :  *
    1753             :  * Generally, there should be a case here for each case in ProcessUtility
    1754             :  * where "dest" is passed on.
    1755             :  */
    1756             : bool
    1757      299724 : UtilityReturnsTuples(Node *parsetree)
    1758             : {
    1759      299724 :     switch (nodeTag(parsetree))
    1760             :     {
    1761             :         case T_CallStmt:
    1762             :             {
    1763         224 :                 CallStmt   *stmt = (CallStmt *) parsetree;
    1764             : 
    1765         224 :                 return (stmt->funcexpr->funcresulttype == RECORDOID);
    1766             :             }
    1767             :         case T_FetchStmt:
    1768             :             {
    1769        4224 :                 FetchStmt  *stmt = (FetchStmt *) parsetree;
    1770             :                 Portal      portal;
    1771             : 
    1772        4224 :                 if (stmt->ismove)
    1773          52 :                     return false;
    1774        4172 :                 portal = GetPortalByName(stmt->portalname);
    1775        4172 :                 if (!PortalIsValid(portal))
    1776          26 :                     return false;   /* not our business to raise error */
    1777        4146 :                 return portal->tupDesc ? true : false;
    1778             :             }
    1779             : 
    1780             :         case T_ExecuteStmt:
    1781             :             {
    1782         806 :                 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
    1783             :                 PreparedStatement *entry;
    1784             : 
    1785         806 :                 entry = FetchPreparedStatement(stmt->name, false);
    1786         806 :                 if (!entry)
    1787           0 :                     return false;   /* not our business to raise error */
    1788         806 :                 if (entry->plansource->resultDesc)
    1789         738 :                     return true;
    1790          68 :                 return false;
    1791             :             }
    1792             : 
    1793             :         case T_ExplainStmt:
    1794       11602 :             return true;
    1795             : 
    1796             :         case T_VariableShowStmt:
    1797         450 :             return true;
    1798             : 
    1799             :         default:
    1800      282418 :             return false;
    1801             :     }
    1802             : }
    1803             : 
    1804             : /*
    1805             :  * UtilityTupleDescriptor
    1806             :  *      Fetch the actual output tuple descriptor for a utility statement
    1807             :  *      for which UtilityReturnsTuples() previously returned "true".
    1808             :  *
    1809             :  * The returned descriptor is created in (or copied into) the current memory
    1810             :  * context.
    1811             :  */
    1812             : TupleDesc
    1813       17010 : UtilityTupleDescriptor(Node *parsetree)
    1814             : {
    1815       17010 :     switch (nodeTag(parsetree))
    1816             :     {
    1817             :         case T_CallStmt:
    1818          74 :             return CallStmtResultDesc((CallStmt *) parsetree);
    1819             : 
    1820             :         case T_FetchStmt:
    1821             :             {
    1822        4146 :                 FetchStmt  *stmt = (FetchStmt *) parsetree;
    1823             :                 Portal      portal;
    1824             : 
    1825        4146 :                 if (stmt->ismove)
    1826           0 :                     return NULL;
    1827        4146 :                 portal = GetPortalByName(stmt->portalname);
    1828        4146 :                 if (!PortalIsValid(portal))
    1829           0 :                     return NULL;    /* not our business to raise error */
    1830        4146 :                 return CreateTupleDescCopy(portal->tupDesc);
    1831             :             }
    1832             : 
    1833             :         case T_ExecuteStmt:
    1834             :             {
    1835         738 :                 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
    1836             :                 PreparedStatement *entry;
    1837             : 
    1838         738 :                 entry = FetchPreparedStatement(stmt->name, false);
    1839         738 :                 if (!entry)
    1840           0 :                     return NULL;    /* not our business to raise error */
    1841         738 :                 return FetchPreparedStatementResultDesc(entry);
    1842             :             }
    1843             : 
    1844             :         case T_ExplainStmt:
    1845       11602 :             return ExplainResultDesc((ExplainStmt *) parsetree);
    1846             : 
    1847             :         case T_VariableShowStmt:
    1848             :             {
    1849         450 :                 VariableShowStmt *n = (VariableShowStmt *) parsetree;
    1850             : 
    1851         450 :                 return GetPGVariableResultDesc(n->name);
    1852             :             }
    1853             : 
    1854             :         default:
    1855           0 :             return NULL;
    1856             :     }
    1857             : }
    1858             : 
    1859             : 
    1860             : /*
    1861             :  * QueryReturnsTuples
    1862             :  *      Return "true" if this Query will send output to the destination.
    1863             :  */
    1864             : #ifdef NOT_USED
    1865             : bool
    1866             : QueryReturnsTuples(Query *parsetree)
    1867             : {
    1868             :     switch (parsetree->commandType)
    1869             :     {
    1870             :         case CMD_SELECT:
    1871             :             /* returns tuples */
    1872             :             return true;
    1873             :         case CMD_INSERT:
    1874             :         case CMD_UPDATE:
    1875             :         case CMD_DELETE:
    1876             :             /* the forms with RETURNING return tuples */
    1877             :             if (parsetree->returningList)
    1878             :                 return true;
    1879             :             break;
    1880             :         case CMD_UTILITY:
    1881             :             return UtilityReturnsTuples(parsetree->utilityStmt);
    1882             :         case CMD_UNKNOWN:
    1883             :         case CMD_NOTHING:
    1884             :             /* probably shouldn't get here */
    1885             :             break;
    1886             :     }
    1887             :     return false;               /* default */
    1888             : }
    1889             : #endif
    1890             : 
    1891             : 
    1892             : /*
    1893             :  * UtilityContainsQuery
    1894             :  *      Return the contained Query, or NULL if there is none
    1895             :  *
    1896             :  * Certain utility statements, such as EXPLAIN, contain a plannable Query.
    1897             :  * This function encapsulates knowledge of exactly which ones do.
    1898             :  * We assume it is invoked only on already-parse-analyzed statements
    1899             :  * (else the contained parsetree isn't a Query yet).
    1900             :  *
    1901             :  * In some cases (currently, only EXPLAIN of CREATE TABLE AS/SELECT INTO and
    1902             :  * CREATE MATERIALIZED VIEW), potentially Query-containing utility statements
    1903             :  * can be nested.  This function will drill down to a non-utility Query, or
    1904             :  * return NULL if none.
    1905             :  */
    1906             : Query *
    1907       19978 : UtilityContainsQuery(Node *parsetree)
    1908             : {
    1909             :     Query      *qry;
    1910             : 
    1911       19978 :     switch (nodeTag(parsetree))
    1912             :     {
    1913             :         case T_DeclareCursorStmt:
    1914        2556 :             qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
    1915        2556 :             if (qry->commandType == CMD_UTILITY)
    1916           0 :                 return UtilityContainsQuery(qry->utilityStmt);
    1917        2556 :             return qry;
    1918             : 
    1919             :         case T_ExplainStmt:
    1920        4736 :             qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
    1921        4736 :             if (qry->commandType == CMD_UTILITY)
    1922          40 :                 return UtilityContainsQuery(qry->utilityStmt);
    1923        4696 :             return qry;
    1924             : 
    1925             :         case T_CreateTableAsStmt:
    1926          32 :             qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
    1927          32 :             if (qry->commandType == CMD_UTILITY)
    1928           0 :                 return UtilityContainsQuery(qry->utilityStmt);
    1929          32 :             return qry;
    1930             : 
    1931             :         default:
    1932       12654 :             return NULL;
    1933             :     }
    1934             : }
    1935             : 
    1936             : 
    1937             : /*
    1938             :  * AlterObjectTypeCommandTag
    1939             :  *      helper function for CreateCommandTag
    1940             :  *
    1941             :  * This covers most cases where ALTER is used with an ObjectType enum.
    1942             :  */
    1943             : static const char *
    1944       11922 : AlterObjectTypeCommandTag(ObjectType objtype)
    1945             : {
    1946             :     const char *tag;
    1947             : 
    1948       11922 :     switch (objtype)
    1949             :     {
    1950             :         case OBJECT_AGGREGATE:
    1951         172 :             tag = "ALTER AGGREGATE";
    1952         172 :             break;
    1953             :         case OBJECT_ATTRIBUTE:
    1954          16 :             tag = "ALTER TYPE";
    1955          16 :             break;
    1956             :         case OBJECT_CAST:
    1957           0 :             tag = "ALTER CAST";
    1958           0 :             break;
    1959             :         case OBJECT_COLLATION:
    1960           0 :             tag = "ALTER COLLATION";
    1961           0 :             break;
    1962             :         case OBJECT_COLUMN:
    1963           0 :             tag = "ALTER TABLE";
    1964           0 :             break;
    1965             :         case OBJECT_CONVERSION:
    1966          48 :             tag = "ALTER CONVERSION";
    1967          48 :             break;
    1968             :         case OBJECT_DATABASE:
    1969          30 :             tag = "ALTER DATABASE";
    1970          30 :             break;
    1971             :         case OBJECT_DOMAIN:
    1972             :         case OBJECT_DOMCONSTRAINT:
    1973          44 :             tag = "ALTER DOMAIN";
    1974          44 :             break;
    1975             :         case OBJECT_EXTENSION:
    1976           0 :             tag = "ALTER EXTENSION";
    1977           0 :             break;
    1978             :         case OBJECT_FDW:
    1979          30 :             tag = "ALTER FOREIGN DATA WRAPPER";
    1980          30 :             break;
    1981             :         case OBJECT_FOREIGN_SERVER:
    1982          62 :             tag = "ALTER SERVER";
    1983          62 :             break;
    1984             :         case OBJECT_FOREIGN_TABLE:
    1985         324 :             tag = "ALTER FOREIGN TABLE";
    1986         324 :             break;
    1987             :         case OBJECT_FUNCTION:
    1988         514 :             tag = "ALTER FUNCTION";
    1989         514 :             break;
    1990             :         case OBJECT_INDEX:
    1991         432 :             tag = "ALTER INDEX";
    1992         432 :             break;
    1993             :         case OBJECT_LANGUAGE:
    1994          32 :             tag = "ALTER LANGUAGE";
    1995          32 :             break;
    1996             :         case OBJECT_LARGEOBJECT:
    1997          10 :             tag = "ALTER LARGE OBJECT";
    1998          10 :             break;
    1999             :         case OBJECT_OPCLASS:
    2000          68 :             tag = "ALTER OPERATOR CLASS";
    2001          68 :             break;
    2002             :         case OBJECT_OPERATOR:
    2003          54 :             tag = "ALTER OPERATOR";
    2004          54 :             break;
    2005             :         case OBJECT_OPFAMILY:
    2006          74 :             tag = "ALTER OPERATOR FAMILY";
    2007          74 :             break;
    2008             :         case OBJECT_POLICY:
    2009          20 :             tag = "ALTER POLICY";
    2010          20 :             break;
    2011             :         case OBJECT_PROCEDURE:
    2012           8 :             tag = "ALTER PROCEDURE";
    2013           8 :             break;
    2014             :         case OBJECT_ROLE:
    2015          12 :             tag = "ALTER ROLE";
    2016          12 :             break;
    2017             :         case OBJECT_ROUTINE:
    2018          16 :             tag = "ALTER ROUTINE";
    2019          16 :             break;
    2020             :         case OBJECT_RULE:
    2021          20 :             tag = "ALTER RULE";
    2022          20 :             break;
    2023             :         case OBJECT_SCHEMA:
    2024          30 :             tag = "ALTER SCHEMA";
    2025          30 :             break;
    2026             :         case OBJECT_SEQUENCE:
    2027          16 :             tag = "ALTER SEQUENCE";
    2028          16 :             break;
    2029             :         case OBJECT_TABLE:
    2030             :         case OBJECT_TABCONSTRAINT:
    2031        9276 :             tag = "ALTER TABLE";
    2032        9276 :             break;
    2033             :         case OBJECT_TABLESPACE:
    2034           8 :             tag = "ALTER TABLESPACE";
    2035           8 :             break;
    2036             :         case OBJECT_TRIGGER:
    2037          10 :             tag = "ALTER TRIGGER";
    2038          10 :             break;
    2039             :         case OBJECT_EVENT_TRIGGER:
    2040          16 :             tag = "ALTER EVENT TRIGGER";
    2041          16 :             break;
    2042             :         case OBJECT_TSCONFIGURATION:
    2043          56 :             tag = "ALTER TEXT SEARCH CONFIGURATION";
    2044          56 :             break;
    2045             :         case OBJECT_TSDICTIONARY:
    2046          66 :             tag = "ALTER TEXT SEARCH DICTIONARY";
    2047          66 :             break;
    2048             :         case OBJECT_TSPARSER:
    2049          20 :             tag = "ALTER TEXT SEARCH PARSER";
    2050          20 :             break;
    2051             :         case OBJECT_TSTEMPLATE:
    2052          20 :             tag = "ALTER TEXT SEARCH TEMPLATE";
    2053          20 :             break;
    2054             :         case OBJECT_TYPE:
    2055         230 :             tag = "ALTER TYPE";
    2056         230 :             break;
    2057             :         case OBJECT_VIEW:
    2058          88 :             tag = "ALTER VIEW";
    2059          88 :             break;
    2060             :         case OBJECT_MATVIEW:
    2061          10 :             tag = "ALTER MATERIALIZED VIEW";
    2062          10 :             break;
    2063             :         case OBJECT_PUBLICATION:
    2064          16 :             tag = "ALTER PUBLICATION";
    2065          16 :             break;
    2066             :         case OBJECT_SUBSCRIPTION:
    2067          22 :             tag = "ALTER SUBSCRIPTION";
    2068          22 :             break;
    2069             :         case OBJECT_STATISTIC_EXT:
    2070          52 :             tag = "ALTER STATISTICS";
    2071          52 :             break;
    2072             :         default:
    2073           0 :             tag = "???";
    2074           0 :             break;
    2075             :     }
    2076             : 
    2077       11922 :     return tag;
    2078             : }
    2079             : 
    2080             : /*
    2081             :  * CreateCommandTag
    2082             :  *      utility to get a string representation of the command operation,
    2083             :  *      given either a raw (un-analyzed) parsetree, an analyzed Query,
    2084             :  *      or a PlannedStmt.
    2085             :  *
    2086             :  * This must handle all command types, but since the vast majority
    2087             :  * of 'em are utility commands, it seems sensible to keep it here.
    2088             :  *
    2089             :  * NB: all result strings must be shorter than COMPLETION_TAG_BUFSIZE.
    2090             :  * Also, the result must point at a true constant (permanent storage).
    2091             :  */
    2092             : const char *
    2093      515076 : CreateCommandTag(Node *parsetree)
    2094             : {
    2095             :     const char *tag;
    2096             : 
    2097      515076 :     switch (nodeTag(parsetree))
    2098             :     {
    2099             :             /* recurse if we're given a RawStmt */
    2100             :         case T_RawStmt:
    2101           0 :             tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
    2102           0 :             break;
    2103             : 
    2104             :             /* raw plannable queries */
    2105             :         case T_InsertStmt:
    2106       57012 :             tag = "INSERT";
    2107       57012 :             break;
    2108             : 
    2109             :         case T_DeleteStmt:
    2110        2748 :             tag = "DELETE";
    2111        2748 :             break;
    2112             : 
    2113             :         case T_UpdateStmt:
    2114        8886 :             tag = "UPDATE";
    2115        8886 :             break;
    2116             : 
    2117             :         case T_SelectStmt:
    2118      150458 :             tag = "SELECT";
    2119      150458 :             break;
    2120             : 
    2121             :             /* utility statements --- same whether raw or cooked */
    2122             :         case T_TransactionStmt:
    2123             :             {
    2124       20790 :                 TransactionStmt *stmt = (TransactionStmt *) parsetree;
    2125             : 
    2126       20790 :                 switch (stmt->kind)
    2127             :                 {
    2128             :                     case TRANS_STMT_BEGIN:
    2129        8782 :                         tag = "BEGIN";
    2130        8782 :                         break;
    2131             : 
    2132             :                     case TRANS_STMT_START:
    2133         974 :                         tag = "START TRANSACTION";
    2134         974 :                         break;
    2135             : 
    2136             :                     case TRANS_STMT_COMMIT:
    2137        8422 :                         tag = "COMMIT";
    2138        8422 :                         break;
    2139             : 
    2140             :                     case TRANS_STMT_ROLLBACK:
    2141             :                     case TRANS_STMT_ROLLBACK_TO:
    2142        1440 :                         tag = "ROLLBACK";
    2143        1440 :                         break;
    2144             : 
    2145             :                     case TRANS_STMT_SAVEPOINT:
    2146         810 :                         tag = "SAVEPOINT";
    2147         810 :                         break;
    2148             : 
    2149             :                     case TRANS_STMT_RELEASE:
    2150         150 :                         tag = "RELEASE";
    2151         150 :                         break;
    2152             : 
    2153             :                     case TRANS_STMT_PREPARE:
    2154         134 :                         tag = "PREPARE TRANSACTION";
    2155         134 :                         break;
    2156             : 
    2157             :                     case TRANS_STMT_COMMIT_PREPARED:
    2158          52 :                         tag = "COMMIT PREPARED";
    2159          52 :                         break;
    2160             : 
    2161             :                     case TRANS_STMT_ROLLBACK_PREPARED:
    2162          26 :                         tag = "ROLLBACK PREPARED";
    2163          26 :                         break;
    2164             : 
    2165             :                     default:
    2166           0 :                         tag = "???";
    2167           0 :                         break;
    2168             :                 }
    2169             :             }
    2170       20790 :             break;
    2171             : 
    2172             :         case T_DeclareCursorStmt:
    2173        1950 :             tag = "DECLARE CURSOR";
    2174        1950 :             break;
    2175             : 
    2176             :         case T_ClosePortalStmt:
    2177             :             {
    2178        1620 :                 ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
    2179             : 
    2180        1620 :                 if (stmt->portalname == NULL)
    2181           8 :                     tag = "CLOSE CURSOR ALL";
    2182             :                 else
    2183        1612 :                     tag = "CLOSE CURSOR";
    2184             :             }
    2185        1620 :             break;
    2186             : 
    2187             :         case T_FetchStmt:
    2188             :             {
    2189        4224 :                 FetchStmt  *stmt = (FetchStmt *) parsetree;
    2190             : 
    2191        4224 :                 tag = (stmt->ismove) ? "MOVE" : "FETCH";
    2192             :             }
    2193        4224 :             break;
    2194             : 
    2195             :         case T_CreateDomainStmt:
    2196        2044 :             tag = "CREATE DOMAIN";
    2197        2044 :             break;
    2198             : 
    2199             :         case T_CreateSchemaStmt:
    2200         688 :             tag = "CREATE SCHEMA";
    2201         688 :             break;
    2202             : 
    2203             :         case T_CreateStmt:
    2204       20614 :             tag = "CREATE TABLE";
    2205       20614 :             break;
    2206             : 
    2207             :         case T_CreateTableSpaceStmt:
    2208          28 :             tag = "CREATE TABLESPACE";
    2209          28 :             break;
    2210             : 
    2211             :         case T_DropTableSpaceStmt:
    2212          20 :             tag = "DROP TABLESPACE";
    2213          20 :             break;
    2214             : 
    2215             :         case T_AlterTableSpaceOptionsStmt:
    2216          16 :             tag = "ALTER TABLESPACE";
    2217          16 :             break;
    2218             : 
    2219             :         case T_CreateExtensionStmt:
    2220         510 :             tag = "CREATE EXTENSION";
    2221         510 :             break;
    2222             : 
    2223             :         case T_AlterExtensionStmt:
    2224           2 :             tag = "ALTER EXTENSION";
    2225           2 :             break;
    2226             : 
    2227             :         case T_AlterExtensionContentsStmt:
    2228         100 :             tag = "ALTER EXTENSION";
    2229         100 :             break;
    2230             : 
    2231             :         case T_CreateFdwStmt:
    2232         116 :             tag = "CREATE FOREIGN DATA WRAPPER";
    2233         116 :             break;
    2234             : 
    2235             :         case T_AlterFdwStmt:
    2236          76 :             tag = "ALTER FOREIGN DATA WRAPPER";
    2237          76 :             break;
    2238             : 
    2239             :         case T_CreateForeignServerStmt:
    2240         172 :             tag = "CREATE SERVER";
    2241         172 :             break;
    2242             : 
    2243             :         case T_AlterForeignServerStmt:
    2244          92 :             tag = "ALTER SERVER";
    2245          92 :             break;
    2246             : 
    2247             :         case T_CreateUserMappingStmt:
    2248         178 :             tag = "CREATE USER MAPPING";
    2249         178 :             break;
    2250             : 
    2251             :         case T_AlterUserMappingStmt:
    2252          68 :             tag = "ALTER USER MAPPING";
    2253          68 :             break;
    2254             : 
    2255             :         case T_DropUserMappingStmt:
    2256          88 :             tag = "DROP USER MAPPING";
    2257          88 :             break;
    2258             : 
    2259             :         case T_CreateForeignTableStmt:
    2260         236 :             tag = "CREATE FOREIGN TABLE";
    2261         236 :             break;
    2262             : 
    2263             :         case T_ImportForeignSchemaStmt:
    2264          36 :             tag = "IMPORT FOREIGN SCHEMA";
    2265          36 :             break;
    2266             : 
    2267             :         case T_DropStmt:
    2268       13446 :             switch (((DropStmt *) parsetree)->removeType)
    2269             :             {
    2270             :                 case OBJECT_TABLE:
    2271        8500 :                     tag = "DROP TABLE";
    2272        8500 :                     break;
    2273             :                 case OBJECT_SEQUENCE:
    2274         104 :                     tag = "DROP SEQUENCE";
    2275         104 :                     break;
    2276             :                 case OBJECT_VIEW:
    2277         434 :                     tag = "DROP VIEW";
    2278         434 :                     break;
    2279             :                 case OBJECT_MATVIEW:
    2280          36 :                     tag = "DROP MATERIALIZED VIEW";
    2281          36 :                     break;
    2282             :                 case OBJECT_INDEX:
    2283         350 :                     tag = "DROP INDEX";
    2284         350 :                     break;
    2285             :                 case OBJECT_TYPE:
    2286         264 :                     tag = "DROP TYPE";
    2287         264 :                     break;
    2288             :                 case OBJECT_DOMAIN:
    2289         232 :                     tag = "DROP DOMAIN";
    2290         232 :                     break;
    2291             :                 case OBJECT_COLLATION:
    2292          18 :                     tag = "DROP COLLATION";
    2293          18 :                     break;
    2294             :                 case OBJECT_CONVERSION:
    2295          24 :                     tag = "DROP CONVERSION";
    2296          24 :                     break;
    2297             :                 case OBJECT_SCHEMA:
    2298         212 :                     tag = "DROP SCHEMA";
    2299         212 :                     break;
    2300             :                 case OBJECT_TSPARSER:
    2301          12 :                     tag = "DROP TEXT SEARCH PARSER";
    2302          12 :                     break;
    2303             :                 case OBJECT_TSDICTIONARY:
    2304          16 :                     tag = "DROP TEXT SEARCH DICTIONARY";
    2305          16 :                     break;
    2306             :                 case OBJECT_TSTEMPLATE:
    2307          12 :                     tag = "DROP TEXT SEARCH TEMPLATE";
    2308          12 :                     break;
    2309             :                 case OBJECT_TSCONFIGURATION:
    2310          16 :                     tag = "DROP TEXT SEARCH CONFIGURATION";
    2311          16 :                     break;
    2312             :                 case OBJECT_FOREIGN_TABLE:
    2313          78 :                     tag = "DROP FOREIGN TABLE";
    2314          78 :                     break;
    2315             :                 case OBJECT_EXTENSION:
    2316          70 :                     tag = "DROP EXTENSION";
    2317          70 :                     break;
    2318             :                 case OBJECT_FUNCTION:
    2319        1604 :                     tag = "DROP FUNCTION";
    2320        1604 :                     break;
    2321             :                 case OBJECT_PROCEDURE:
    2322          76 :                     tag = "DROP PROCEDURE";
    2323          76 :                     break;
    2324             :                 case OBJECT_ROUTINE:
    2325          20 :                     tag = "DROP ROUTINE";
    2326          20 :                     break;
    2327             :                 case OBJECT_AGGREGATE:
    2328          70 :                     tag = "DROP AGGREGATE";
    2329          70 :                     break;
    2330             :                 case OBJECT_OPERATOR:
    2331          78 :                     tag = "DROP OPERATOR";
    2332          78 :                     break;
    2333             :                 case OBJECT_LANGUAGE:
    2334          16 :                     tag = "DROP LANGUAGE";
    2335          16 :                     break;
    2336             :                 case OBJECT_CAST:
    2337          36 :                     tag = "DROP CAST";
    2338          36 :                     break;
    2339             :                 case OBJECT_TRIGGER:
    2340         506 :                     tag = "DROP TRIGGER";
    2341         506 :                     break;
    2342             :                 case OBJECT_EVENT_TRIGGER:
    2343          62 :                     tag = "DROP EVENT TRIGGER";
    2344          62 :                     break;
    2345             :                 case OBJECT_RULE:
    2346         128 :                     tag = "DROP RULE";
    2347         128 :                     break;
    2348             :                 case OBJECT_FDW:
    2349          88 :                     tag = "DROP FOREIGN DATA WRAPPER";
    2350          88 :                     break;
    2351             :                 case OBJECT_FOREIGN_SERVER:
    2352          74 :                     tag = "DROP SERVER";
    2353          74 :                     break;
    2354             :                 case OBJECT_OPCLASS:
    2355          34 :                     tag = "DROP OPERATOR CLASS";
    2356          34 :                     break;
    2357             :                 case OBJECT_OPFAMILY:
    2358          82 :                     tag = "DROP OPERATOR FAMILY";
    2359          82 :                     break;
    2360             :                 case OBJECT_POLICY:
    2361          94 :                     tag = "DROP POLICY";
    2362          94 :                     break;
    2363             :                 case OBJECT_TRANSFORM:
    2364          16 :                     tag = "DROP TRANSFORM";
    2365          16 :                     break;
    2366             :                 case OBJECT_ACCESS_METHOD:
    2367          24 :                     tag = "DROP ACCESS METHOD";
    2368          24 :                     break;
    2369             :                 case OBJECT_PUBLICATION:
    2370          32 :                     tag = "DROP PUBLICATION";
    2371          32 :                     break;
    2372             :                 case OBJECT_STATISTIC_EXT:
    2373          28 :                     tag = "DROP STATISTICS";
    2374          28 :                     break;
    2375             :                 default:
    2376           0 :                     tag = "???";
    2377             :             }
    2378       13446 :             break;
    2379             : 
    2380             :         case T_TruncateStmt:
    2381         756 :             tag = "TRUNCATE TABLE";
    2382         756 :             break;
    2383             : 
    2384             :         case T_CommentStmt:
    2385       16350 :             tag = "COMMENT";
    2386       16350 :             break;
    2387             : 
    2388             :         case T_SecLabelStmt:
    2389          88 :             tag = "SECURITY LABEL";
    2390          88 :             break;
    2391             : 
    2392             :         case T_CopyStmt:
    2393        4612 :             tag = "COPY";
    2394        4612 :             break;
    2395             : 
    2396             :         case T_RenameStmt:
    2397             :             /*
    2398             :              * When the column is renamed, the command tag is created
    2399             :              * from its relation type
    2400             :              */
    2401         736 :             tag = AlterObjectTypeCommandTag(
    2402         736 :                 ((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
    2403             :                 ((RenameStmt *) parsetree)->relationType :
    2404             :                 ((RenameStmt *) parsetree)->renameType);
    2405         736 :             break;
    2406             : 
    2407             :         case T_AlterObjectDependsStmt:
    2408          24 :             tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
    2409          24 :             break;
    2410             : 
    2411             :         case T_AlterObjectSchemaStmt:
    2412         252 :             tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
    2413         252 :             break;
    2414             : 
    2415             :         case T_AlterOwnerStmt:
    2416        1076 :             tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
    2417        1076 :             break;
    2418             : 
    2419             :         case T_AlterTableMoveAllStmt:
    2420          12 :             tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
    2421          12 :             break;
    2422             : 
    2423             :         case T_AlterTableStmt:
    2424        9822 :             tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
    2425        9822 :             break;
    2426             : 
    2427             :         case T_AlterDomainStmt:
    2428         152 :             tag = "ALTER DOMAIN";
    2429         152 :             break;
    2430             : 
    2431             :         case T_AlterFunctionStmt:
    2432         116 :             switch (((AlterFunctionStmt *) parsetree)->objtype)
    2433             :             {
    2434             :                 case OBJECT_FUNCTION:
    2435         104 :                     tag = "ALTER FUNCTION";
    2436         104 :                     break;
    2437             :                 case OBJECT_PROCEDURE:
    2438          12 :                     tag = "ALTER PROCEDURE";
    2439          12 :                     break;
    2440             :                 case OBJECT_ROUTINE:
    2441           0 :                     tag = "ALTER ROUTINE";
    2442           0 :                     break;
    2443             :                 default:
    2444           0 :                     tag = "???";
    2445             :             }
    2446         116 :             break;
    2447             : 
    2448             :         case T_GrantStmt:
    2449             :             {
    2450       39444 :                 GrantStmt  *stmt = (GrantStmt *) parsetree;
    2451             : 
    2452       39444 :                 tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
    2453             :             }
    2454       39444 :             break;
    2455             : 
    2456             :         case T_GrantRoleStmt:
    2457             :             {
    2458        1038 :                 GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
    2459             : 
    2460        1038 :                 tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
    2461             :             }
    2462        1038 :             break;
    2463             : 
    2464             :         case T_AlterDefaultPrivilegesStmt:
    2465          98 :             tag = "ALTER DEFAULT PRIVILEGES";
    2466          98 :             break;
    2467             : 
    2468             :         case T_DefineStmt:
    2469       15758 :             switch (((DefineStmt *) parsetree)->kind)
    2470             :             {
    2471             :                 case OBJECT_AGGREGATE:
    2472         614 :                     tag = "CREATE AGGREGATE";
    2473         614 :                     break;
    2474             :                 case OBJECT_OPERATOR:
    2475         238 :                     tag = "CREATE OPERATOR";
    2476         238 :                     break;
    2477             :                 case OBJECT_TYPE:
    2478         170 :                     tag = "CREATE TYPE";
    2479         170 :                     break;
    2480             :                 case OBJECT_TSPARSER:
    2481          28 :                     tag = "CREATE TEXT SEARCH PARSER";
    2482          28 :                     break;
    2483             :                 case OBJECT_TSDICTIONARY:
    2484        7186 :                     tag = "CREATE TEXT SEARCH DICTIONARY";
    2485        7186 :                     break;
    2486             :                 case OBJECT_TSTEMPLATE:
    2487         350 :                     tag = "CREATE TEXT SEARCH TEMPLATE";
    2488         350 :                     break;
    2489             :                 case OBJECT_TSCONFIGURATION:
    2490        7150 :                     tag = "CREATE TEXT SEARCH CONFIGURATION";
    2491        7150 :                     break;
    2492             :                 case OBJECT_COLLATION:
    2493          22 :                     tag = "CREATE COLLATION";
    2494          22 :                     break;
    2495             :                 case OBJECT_ACCESS_METHOD:
    2496           0 :                     tag = "CREATE ACCESS METHOD";
    2497           0 :                     break;
    2498             :                 default:
    2499           0 :                     tag = "???";
    2500             :             }
    2501       15758 :             break;
    2502             : 
    2503             :         case T_CompositeTypeStmt:
    2504         416 :             tag = "CREATE TYPE";
    2505         416 :             break;
    2506             : 
    2507             :         case T_CreateEnumStmt:
    2508         116 :             tag = "CREATE TYPE";
    2509         116 :             break;
    2510             : 
    2511             :         case T_CreateRangeStmt:
    2512          68 :             tag = "CREATE TYPE";
    2513          68 :             break;
    2514             : 
    2515             :         case T_AlterEnumStmt:
    2516         292 :             tag = "ALTER TYPE";
    2517         292 :             break;
    2518             : 
    2519             :         case T_ViewStmt:
    2520       41448 :             tag = "CREATE VIEW";
    2521       41448 :             break;
    2522             : 
    2523             :         case T_CreateFunctionStmt:
    2524       17944 :             if (((CreateFunctionStmt *) parsetree)->is_procedure)
    2525         188 :                 tag = "CREATE PROCEDURE";
    2526             :             else
    2527       17756 :                 tag = "CREATE FUNCTION";
    2528       17944 :             break;
    2529             : 
    2530             :         case T_IndexStmt:
    2531        2892 :             tag = "CREATE INDEX";
    2532        2892 :             break;
    2533             : 
    2534             :         case T_RuleStmt:
    2535        1164 :             tag = "CREATE RULE";
    2536        1164 :             break;
    2537             : 
    2538             :         case T_CreateSeqStmt:
    2539         370 :             tag = "CREATE SEQUENCE";
    2540         370 :             break;
    2541             : 
    2542             :         case T_AlterSeqStmt:
    2543         150 :             tag = "ALTER SEQUENCE";
    2544         150 :             break;
    2545             : 
    2546             :         case T_DoStmt:
    2547         522 :             tag = "DO";
    2548         522 :             break;
    2549             : 
    2550             :         case T_CreatedbStmt:
    2551         884 :             tag = "CREATE DATABASE";
    2552         884 :             break;
    2553             : 
    2554             :         case T_AlterDatabaseStmt:
    2555           6 :             tag = "ALTER DATABASE";
    2556           6 :             break;
    2557             : 
    2558             :         case T_AlterDatabaseSetStmt:
    2559         828 :             tag = "ALTER DATABASE";
    2560         828 :             break;
    2561             : 
    2562             :         case T_DropdbStmt:
    2563          38 :             tag = "DROP DATABASE";
    2564          38 :             break;
    2565             : 
    2566             :         case T_NotifyStmt:
    2567          80 :             tag = "NOTIFY";
    2568          80 :             break;
    2569             : 
    2570             :         case T_ListenStmt:
    2571          36 :             tag = "LISTEN";
    2572          36 :             break;
    2573             : 
    2574             :         case T_UnlistenStmt:
    2575          28 :             tag = "UNLISTEN";
    2576          28 :             break;
    2577             : 
    2578             :         case T_LoadStmt:
    2579          18 :             tag = "LOAD";
    2580          18 :             break;
    2581             : 
    2582             :         case T_CallStmt:
    2583         240 :             tag = "CALL";
    2584         240 :             break;
    2585             : 
    2586             :         case T_ClusterStmt:
    2587          86 :             tag = "CLUSTER";
    2588          86 :             break;
    2589             : 
    2590             :         case T_VacuumStmt:
    2591       12256 :             if (((VacuumStmt *) parsetree)->is_vacuumcmd)
    2592        3534 :                 tag = "VACUUM";
    2593             :             else
    2594        8722 :                 tag = "ANALYZE";
    2595       12256 :             break;
    2596             : 
    2597             :         case T_ExplainStmt:
    2598        9242 :             tag = "EXPLAIN";
    2599        9242 :             break;
    2600             : 
    2601             :         case T_CreateTableAsStmt:
    2602         758 :             switch (((CreateTableAsStmt *) parsetree)->relkind)
    2603             :             {
    2604             :                 case OBJECT_TABLE:
    2605         560 :                     if (((CreateTableAsStmt *) parsetree)->is_select_into)
    2606           0 :                         tag = "SELECT INTO";
    2607             :                     else
    2608         560 :                         tag = "CREATE TABLE AS";
    2609         560 :                     break;
    2610             :                 case OBJECT_MATVIEW:
    2611         198 :                     tag = "CREATE MATERIALIZED VIEW";
    2612         198 :                     break;
    2613             :                 default:
    2614           0 :                     tag = "???";
    2615             :             }
    2616         758 :             break;
    2617             : 
    2618             :         case T_RefreshMatViewStmt:
    2619          96 :             tag = "REFRESH MATERIALIZED VIEW";
    2620          96 :             break;
    2621             : 
    2622             :         case T_AlterSystemStmt:
    2623          30 :             tag = "ALTER SYSTEM";
    2624          30 :             break;
    2625             : 
    2626             :         case T_VariableSetStmt:
    2627       11658 :             switch (((VariableSetStmt *) parsetree)->kind)
    2628             :             {
    2629             :                 case VAR_SET_VALUE:
    2630             :                 case VAR_SET_CURRENT:
    2631             :                 case VAR_SET_DEFAULT:
    2632             :                 case VAR_SET_MULTI:
    2633        9926 :                     tag = "SET";
    2634        9926 :                     break;
    2635             :                 case VAR_RESET:
    2636             :                 case VAR_RESET_ALL:
    2637        1732 :                     tag = "RESET";
    2638        1732 :                     break;
    2639             :                 default:
    2640           0 :                     tag = "???";
    2641             :             }
    2642       11658 :             break;
    2643             : 
    2644             :         case T_VariableShowStmt:
    2645         450 :             tag = "SHOW";
    2646         450 :             break;
    2647             : 
    2648             :         case T_DiscardStmt:
    2649          20 :             switch (((DiscardStmt *) parsetree)->target)
    2650             :             {
    2651             :                 case DISCARD_ALL:
    2652           4 :                     tag = "DISCARD ALL";
    2653           4 :                     break;
    2654             :                 case DISCARD_PLANS:
    2655           4 :                     tag = "DISCARD PLANS";
    2656           4 :                     break;
    2657             :                 case DISCARD_TEMP:
    2658           4 :                     tag = "DISCARD TEMP";
    2659           4 :                     break;
    2660             :                 case DISCARD_SEQUENCES:
    2661           8 :                     tag = "DISCARD SEQUENCES";
    2662           8 :                     break;
    2663             :                 default:
    2664           0 :                     tag = "???";
    2665             :             }
    2666          20 :             break;
    2667             : 
    2668             :         case T_CreateTransformStmt:
    2669          36 :             tag = "CREATE TRANSFORM";
    2670          36 :             break;
    2671             : 
    2672             :         case T_CreateTrigStmt:
    2673        1978 :             tag = "CREATE TRIGGER";
    2674        1978 :             break;
    2675             : 
    2676             :         case T_CreateEventTrigStmt:
    2677         108 :             tag = "CREATE EVENT TRIGGER";
    2678         108 :             break;
    2679             : 
    2680             :         case T_AlterEventTrigStmt:
    2681          20 :             tag = "ALTER EVENT TRIGGER";
    2682          20 :             break;
    2683             : 
    2684             :         case T_CreatePLangStmt:
    2685          10 :             tag = "CREATE LANGUAGE";
    2686          10 :             break;
    2687             : 
    2688             :         case T_CreateRoleStmt:
    2689         728 :             tag = "CREATE ROLE";
    2690         728 :             break;
    2691             : 
    2692             :         case T_AlterRoleStmt:
    2693         218 :             tag = "ALTER ROLE";
    2694         218 :             break;
    2695             : 
    2696             :         case T_AlterRoleSetStmt:
    2697          58 :             tag = "ALTER ROLE";
    2698          58 :             break;
    2699             : 
    2700             :         case T_DropRoleStmt:
    2701         740 :             tag = "DROP ROLE";
    2702         740 :             break;
    2703             : 
    2704             :         case T_DropOwnedStmt:
    2705          74 :             tag = "DROP OWNED";
    2706          74 :             break;
    2707             : 
    2708             :         case T_ReassignOwnedStmt:
    2709          16 :             tag = "REASSIGN OWNED";
    2710          16 :             break;
    2711             : 
    2712             :         case T_LockStmt:
    2713        3994 :             tag = "LOCK TABLE";
    2714        3994 :             break;
    2715             : 
    2716             :         case T_ConstraintsSetStmt:
    2717          66 :             tag = "SET CONSTRAINTS";
    2718          66 :             break;
    2719             : 
    2720             :         case T_CheckPointStmt:
    2721          78 :             tag = "CHECKPOINT";
    2722          78 :             break;
    2723             : 
    2724             :         case T_ReindexStmt:
    2725         288 :             tag = "REINDEX";
    2726         288 :             break;
    2727             : 
    2728             :         case T_CreateConversionStmt:
    2729          52 :             tag = "CREATE CONVERSION";
    2730          52 :             break;
    2731             : 
    2732             :         case T_CreateCastStmt:
    2733         126 :             tag = "CREATE CAST";
    2734         126 :             break;
    2735             : 
    2736             :         case T_CreateOpClassStmt:
    2737          72 :             tag = "CREATE OPERATOR CLASS";
    2738          72 :             break;
    2739             : 
    2740             :         case T_CreateOpFamilyStmt:
    2741          96 :             tag = "CREATE OPERATOR FAMILY";
    2742          96 :             break;
    2743             : 
    2744             :         case T_AlterOpFamilyStmt:
    2745         164 :             tag = "ALTER OPERATOR FAMILY";
    2746         164 :             break;
    2747             : 
    2748             :         case T_AlterOperatorStmt:
    2749          56 :             tag = "ALTER OPERATOR";
    2750          56 :             break;
    2751             : 
    2752             :         case T_AlterTSDictionaryStmt:
    2753          14 :             tag = "ALTER TEXT SEARCH DICTIONARY";
    2754          14 :             break;
    2755             : 
    2756             :         case T_AlterTSConfigurationStmt:
    2757       21438 :             tag = "ALTER TEXT SEARCH CONFIGURATION";
    2758       21438 :             break;
    2759             : 
    2760             :         case T_CreatePolicyStmt:
    2761         398 :             tag = "CREATE POLICY";
    2762         398 :             break;
    2763             : 
    2764             :         case T_AlterPolicyStmt:
    2765          64 :             tag = "ALTER POLICY";
    2766          64 :             break;
    2767             : 
    2768             :         case T_CreateAmStmt:
    2769          38 :             tag = "CREATE ACCESS METHOD";
    2770          38 :             break;
    2771             : 
    2772             :         case T_CreatePublicationStmt:
    2773          94 :             tag = "CREATE PUBLICATION";
    2774          94 :             break;
    2775             : 
    2776             :         case T_AlterPublicationStmt:
    2777          86 :             tag = "ALTER PUBLICATION";
    2778          86 :             break;
    2779             : 
    2780             :         case T_CreateSubscriptionStmt:
    2781         104 :             tag = "CREATE SUBSCRIPTION";
    2782         104 :             break;
    2783             : 
    2784             :         case T_AlterSubscriptionStmt:
    2785          66 :             tag = "ALTER SUBSCRIPTION";
    2786          66 :             break;
    2787             : 
    2788             :         case T_DropSubscriptionStmt:
    2789          40 :             tag = "DROP SUBSCRIPTION";
    2790          40 :             break;
    2791             : 
    2792             :         case T_AlterCollationStmt:
    2793           0 :             tag = "ALTER COLLATION";
    2794           0 :             break;
    2795             : 
    2796             :         case T_PrepareStmt:
    2797         294 :             tag = "PREPARE";
    2798         294 :             break;
    2799             : 
    2800             :         case T_ExecuteStmt:
    2801         806 :             tag = "EXECUTE";
    2802         806 :             break;
    2803             : 
    2804             :         case T_CreateStatsStmt:
    2805         176 :             tag = "CREATE STATISTICS";
    2806         176 :             break;
    2807             : 
    2808             :         case T_AlterStatsStmt:
    2809          20 :             tag = "ALTER STATISTICS";
    2810          20 :             break;
    2811             : 
    2812             :         case T_DeallocateStmt:
    2813             :             {
    2814        3752 :                 DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
    2815             : 
    2816        3752 :                 if (stmt->name == NULL)
    2817          24 :                     tag = "DEALLOCATE ALL";
    2818             :                 else
    2819        3728 :                     tag = "DEALLOCATE";
    2820             :             }
    2821        3752 :             break;
    2822             : 
    2823             :             /* already-planned queries */
    2824             :         case T_PlannedStmt:
    2825             :             {
    2826          20 :                 PlannedStmt *stmt = (PlannedStmt *) parsetree;
    2827             : 
    2828          20 :                 switch (stmt->commandType)
    2829             :                 {
    2830             :                     case CMD_SELECT:
    2831             : 
    2832             :                         /*
    2833             :                          * We take a little extra care here so that the result
    2834             :                          * will be useful for complaints about read-only
    2835             :                          * statements
    2836             :                          */
    2837           0 :                         if (stmt->rowMarks != NIL)
    2838             :                         {
    2839             :                             /* not 100% but probably close enough */
    2840           0 :                             switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
    2841             :                             {
    2842             :                                 case LCS_FORKEYSHARE:
    2843           0 :                                     tag = "SELECT FOR KEY SHARE";
    2844           0 :                                     break;
    2845             :                                 case LCS_FORSHARE:
    2846           0 :                                     tag = "SELECT FOR SHARE";
    2847           0 :                                     break;
    2848             :                                 case LCS_FORNOKEYUPDATE:
    2849           0 :                                     tag = "SELECT FOR NO KEY UPDATE";
    2850           0 :                                     break;
    2851             :                                 case LCS_FORUPDATE:
    2852           0 :                                     tag = "SELECT FOR UPDATE";
    2853           0 :                                     break;
    2854             :                                 default:
    2855           0 :                                     tag = "SELECT";
    2856           0 :                                     break;
    2857             :                             }
    2858             :                         }
    2859             :                         else
    2860           0 :                             tag = "SELECT";
    2861           0 :                         break;
    2862             :                     case CMD_UPDATE:
    2863           8 :                         tag = "UPDATE";
    2864           8 :                         break;
    2865             :                     case CMD_INSERT:
    2866           8 :                         tag = "INSERT";
    2867           8 :                         break;
    2868             :                     case CMD_DELETE:
    2869           4 :                         tag = "DELETE";
    2870           4 :                         break;
    2871             :                     case CMD_UTILITY:
    2872           0 :                         tag = CreateCommandTag(stmt->utilityStmt);
    2873           0 :                         break;
    2874             :                     default:
    2875           0 :                         elog(WARNING, "unrecognized commandType: %d",
    2876             :                              (int) stmt->commandType);
    2877           0 :                         tag = "???";
    2878           0 :                         break;
    2879             :                 }
    2880             :             }
    2881          20 :             break;
    2882             : 
    2883             :             /* parsed-and-rewritten-but-not-planned queries */
    2884             :         case T_Query:
    2885             :             {
    2886           0 :                 Query      *stmt = (Query *) parsetree;
    2887             : 
    2888           0 :                 switch (stmt->commandType)
    2889             :                 {
    2890             :                     case CMD_SELECT:
    2891             : 
    2892             :                         /*
    2893             :                          * We take a little extra care here so that the result
    2894             :                          * will be useful for complaints about read-only
    2895             :                          * statements
    2896             :                          */
    2897           0 :                         if (stmt->rowMarks != NIL)
    2898             :                         {
    2899             :                             /* not 100% but probably close enough */
    2900           0 :                             switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
    2901             :                             {
    2902             :                                 case LCS_FORKEYSHARE:
    2903           0 :                                     tag = "SELECT FOR KEY SHARE";
    2904           0 :                                     break;
    2905             :                                 case LCS_FORSHARE:
    2906           0 :                                     tag = "SELECT FOR SHARE";
    2907           0 :                                     break;
    2908             :                                 case LCS_FORNOKEYUPDATE:
    2909           0 :                                     tag = "SELECT FOR NO KEY UPDATE";
    2910           0 :                                     break;
    2911             :                                 case LCS_FORUPDATE:
    2912           0 :                                     tag = "SELECT FOR UPDATE";
    2913           0 :                                     break;
    2914             :                                 default:
    2915           0 :                                     tag = "???";
    2916           0 :                                     break;
    2917             :                             }
    2918             :                         }
    2919             :                         else
    2920           0 :                             tag = "SELECT";
    2921           0 :                         break;
    2922             :                     case CMD_UPDATE:
    2923           0 :                         tag = "UPDATE";
    2924           0 :                         break;
    2925             :                     case CMD_INSERT:
    2926           0 :                         tag = "INSERT";
    2927           0 :                         break;
    2928             :                     case CMD_DELETE:
    2929           0 :                         tag = "DELETE";
    2930           0 :                         break;
    2931             :                     case CMD_UTILITY:
    2932           0 :                         tag = CreateCommandTag(stmt->utilityStmt);
    2933           0 :                         break;
    2934             :                     default:
    2935           0 :                         elog(WARNING, "unrecognized commandType: %d",
    2936             :                              (int) stmt->commandType);
    2937           0 :                         tag = "???";
    2938           0 :                         break;
    2939             :                 }
    2940             :             }
    2941           0 :             break;
    2942             : 
    2943             :         default:
    2944           0 :             elog(WARNING, "unrecognized node type: %d",
    2945             :                  (int) nodeTag(parsetree));
    2946           0 :             tag = "???";
    2947           0 :             break;
    2948             :     }
    2949             : 
    2950      515076 :     return tag;
    2951             : }
    2952             : 
    2953             : 
    2954             : /*
    2955             :  * GetCommandLogLevel
    2956             :  *      utility to get the minimum log_statement level for a command,
    2957             :  *      given either a raw (un-analyzed) parsetree, an analyzed Query,
    2958             :  *      or a PlannedStmt.
    2959             :  *
    2960             :  * This must handle all command types, but since the vast majority
    2961             :  * of 'em are utility commands, it seems sensible to keep it here.
    2962             :  */
    2963             : LogStmtLevel
    2964           0 : GetCommandLogLevel(Node *parsetree)
    2965             : {
    2966             :     LogStmtLevel lev;
    2967             : 
    2968           0 :     switch (nodeTag(parsetree))
    2969             :     {
    2970             :             /* recurse if we're given a RawStmt */
    2971             :         case T_RawStmt:
    2972           0 :             lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
    2973           0 :             break;
    2974             : 
    2975             :             /* raw plannable queries */
    2976             :         case T_InsertStmt:
    2977             :         case T_DeleteStmt:
    2978             :         case T_UpdateStmt:
    2979           0 :             lev = LOGSTMT_MOD;
    2980           0 :             break;
    2981             : 
    2982             :         case T_SelectStmt:
    2983           0 :             if (((SelectStmt *) parsetree)->intoClause)
    2984           0 :                 lev = LOGSTMT_DDL;  /* SELECT INTO */
    2985             :             else
    2986           0 :                 lev = LOGSTMT_ALL;
    2987           0 :             break;
    2988             : 
    2989             :             /* utility statements --- same whether raw or cooked */
    2990             :         case T_TransactionStmt:
    2991           0 :             lev = LOGSTMT_ALL;
    2992           0 :             break;
    2993             : 
    2994             :         case T_DeclareCursorStmt:
    2995           0 :             lev = LOGSTMT_ALL;
    2996           0 :             break;
    2997             : 
    2998             :         case T_ClosePortalStmt:
    2999           0 :             lev = LOGSTMT_ALL;
    3000           0 :             break;
    3001             : 
    3002             :         case T_FetchStmt:
    3003           0 :             lev = LOGSTMT_ALL;
    3004           0 :             break;
    3005             : 
    3006             :         case T_CreateSchemaStmt:
    3007           0 :             lev = LOGSTMT_DDL;
    3008           0 :             break;
    3009             : 
    3010             :         case T_CreateStmt:
    3011             :         case T_CreateForeignTableStmt:
    3012           0 :             lev = LOGSTMT_DDL;
    3013           0 :             break;
    3014             : 
    3015             :         case T_CreateTableSpaceStmt:
    3016             :         case T_DropTableSpaceStmt:
    3017             :         case T_AlterTableSpaceOptionsStmt:
    3018           0 :             lev = LOGSTMT_DDL;
    3019           0 :             break;
    3020             : 
    3021             :         case T_CreateExtensionStmt:
    3022             :         case T_AlterExtensionStmt:
    3023             :         case T_AlterExtensionContentsStmt:
    3024           0 :             lev = LOGSTMT_DDL;
    3025           0 :             break;
    3026             : 
    3027             :         case T_CreateFdwStmt:
    3028             :         case T_AlterFdwStmt:
    3029             :         case T_CreateForeignServerStmt:
    3030             :         case T_AlterForeignServerStmt:
    3031             :         case T_CreateUserMappingStmt:
    3032             :         case T_AlterUserMappingStmt:
    3033             :         case T_DropUserMappingStmt:
    3034             :         case T_ImportForeignSchemaStmt:
    3035           0 :             lev = LOGSTMT_DDL;
    3036           0 :             break;
    3037             : 
    3038             :         case T_DropStmt:
    3039           0 :             lev = LOGSTMT_DDL;
    3040           0 :             break;
    3041             : 
    3042             :         case T_TruncateStmt:
    3043           0 :             lev = LOGSTMT_MOD;
    3044           0 :             break;
    3045             : 
    3046             :         case T_CommentStmt:
    3047           0 :             lev = LOGSTMT_DDL;
    3048           0 :             break;
    3049             : 
    3050             :         case T_SecLabelStmt:
    3051           0 :             lev = LOGSTMT_DDL;
    3052           0 :             break;
    3053             : 
    3054             :         case T_CopyStmt:
    3055           0 :             if (((CopyStmt *) parsetree)->is_from)
    3056           0 :                 lev = LOGSTMT_MOD;
    3057             :             else
    3058           0 :                 lev = LOGSTMT_ALL;
    3059           0 :             break;
    3060             : 
    3061             :         case T_PrepareStmt:
    3062             :             {
    3063           0 :                 PrepareStmt *stmt = (PrepareStmt *) parsetree;
    3064             : 
    3065             :                 /* Look through a PREPARE to the contained stmt */
    3066           0 :                 lev = GetCommandLogLevel(stmt->query);
    3067             :             }
    3068           0 :             break;
    3069             : 
    3070             :         case T_ExecuteStmt:
    3071             :             {
    3072           0 :                 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
    3073             :                 PreparedStatement *ps;
    3074             : 
    3075             :                 /* Look through an EXECUTE to the referenced stmt */
    3076           0 :                 ps = FetchPreparedStatement(stmt->name, false);
    3077           0 :                 if (ps && ps->plansource->raw_parse_tree)
    3078           0 :                     lev = GetCommandLogLevel(ps->plansource->raw_parse_tree->stmt);
    3079             :                 else
    3080           0 :                     lev = LOGSTMT_ALL;
    3081             :             }
    3082           0 :             break;
    3083             : 
    3084             :         case T_DeallocateStmt:
    3085           0 :             lev = LOGSTMT_ALL;
    3086           0 :             break;
    3087             : 
    3088             :         case T_RenameStmt:
    3089           0 :             lev = LOGSTMT_DDL;
    3090           0 :             break;
    3091             : 
    3092             :         case T_AlterObjectDependsStmt:
    3093           0 :             lev = LOGSTMT_DDL;
    3094           0 :             break;
    3095             : 
    3096             :         case T_AlterObjectSchemaStmt:
    3097           0 :             lev = LOGSTMT_DDL;
    3098           0 :             break;
    3099             : 
    3100             :         case T_AlterOwnerStmt:
    3101           0 :             lev = LOGSTMT_DDL;
    3102           0 :             break;
    3103             : 
    3104             :         case T_AlterOperatorStmt:
    3105           0 :             lev = LOGSTMT_DDL;
    3106           0 :             break;
    3107             : 
    3108             :         case T_AlterTableMoveAllStmt:
    3109             :         case T_AlterTableStmt:
    3110           0 :             lev = LOGSTMT_DDL;
    3111           0 :             break;
    3112             : 
    3113             :         case T_AlterDomainStmt:
    3114           0 :             lev = LOGSTMT_DDL;
    3115           0 :             break;
    3116             : 
    3117             :         case T_GrantStmt:
    3118           0 :             lev = LOGSTMT_DDL;
    3119           0 :             break;
    3120             : 
    3121             :         case T_GrantRoleStmt:
    3122           0 :             lev = LOGSTMT_DDL;
    3123           0 :             break;
    3124             : 
    3125             :         case T_AlterDefaultPrivilegesStmt:
    3126           0 :             lev = LOGSTMT_DDL;
    3127           0 :             break;
    3128             : 
    3129             :         case T_DefineStmt:
    3130           0 :             lev = LOGSTMT_DDL;
    3131           0 :             break;
    3132             : 
    3133             :         case T_CompositeTypeStmt:
    3134           0 :             lev = LOGSTMT_DDL;
    3135           0 :             break;
    3136             : 
    3137             :         case T_CreateEnumStmt:
    3138           0 :             lev = LOGSTMT_DDL;
    3139           0 :             break;
    3140             : 
    3141             :         case T_CreateRangeStmt:
    3142           0 :             lev = LOGSTMT_DDL;
    3143           0 :             break;
    3144             : 
    3145             :         case T_AlterEnumStmt:
    3146           0 :             lev = LOGSTMT_DDL;
    3147           0 :             break;
    3148             : 
    3149             :         case T_ViewStmt:
    3150           0 :             lev = LOGSTMT_DDL;
    3151           0 :             break;
    3152             : 
    3153             :         case T_CreateFunctionStmt:
    3154           0 :             lev = LOGSTMT_DDL;
    3155           0 :             break;
    3156             : 
    3157             :         case T_AlterFunctionStmt:
    3158           0 :             lev = LOGSTMT_DDL;
    3159           0 :             break;
    3160             : 
    3161             :         case T_IndexStmt:
    3162           0 :             lev = LOGSTMT_DDL;
    3163           0 :             break;
    3164             : 
    3165             :         case T_RuleStmt:
    3166           0 :             lev = LOGSTMT_DDL;
    3167           0 :             break;
    3168             : 
    3169             :         case T_CreateSeqStmt:
    3170           0 :             lev = LOGSTMT_DDL;
    3171           0 :             break;
    3172             : 
    3173             :         case T_AlterSeqStmt:
    3174           0 :             lev = LOGSTMT_DDL;
    3175           0 :             break;
    3176             : 
    3177             :         case T_DoStmt:
    3178           0 :             lev = LOGSTMT_ALL;
    3179           0 :             break;
    3180             : 
    3181             :         case T_CreatedbStmt:
    3182           0 :             lev = LOGSTMT_DDL;
    3183           0 :             break;
    3184             : 
    3185             :         case T_AlterDatabaseStmt:
    3186           0 :             lev = LOGSTMT_DDL;
    3187           0 :             break;
    3188             : 
    3189             :         case T_AlterDatabaseSetStmt:
    3190           0 :             lev = LOGSTMT_DDL;
    3191           0 :             break;
    3192             : 
    3193             :         case T_DropdbStmt:
    3194           0 :             lev = LOGSTMT_DDL;
    3195           0 :             break;
    3196             : 
    3197             :         case T_NotifyStmt:
    3198           0 :             lev = LOGSTMT_ALL;
    3199           0 :             break;
    3200             : 
    3201             :         case T_ListenStmt:
    3202           0 :             lev = LOGSTMT_ALL;
    3203           0 :             break;
    3204             : 
    3205             :         case T_UnlistenStmt:
    3206           0 :             lev = LOGSTMT_ALL;
    3207           0 :             break;
    3208             : 
    3209             :         case T_LoadStmt:
    3210           0 :             lev = LOGSTMT_ALL;
    3211           0 :             break;
    3212             : 
    3213             :         case T_CallStmt:
    3214           0 :             lev = LOGSTMT_ALL;
    3215           0 :             break;
    3216             : 
    3217             :         case T_ClusterStmt:
    3218           0 :             lev = LOGSTMT_DDL;
    3219           0 :             break;
    3220             : 
    3221             :         case T_VacuumStmt:
    3222           0 :             lev = LOGSTMT_ALL;
    3223           0 :             break;
    3224             : 
    3225             :         case T_ExplainStmt:
    3226             :             {
    3227           0 :                 ExplainStmt *stmt = (ExplainStmt *) parsetree;
    3228           0 :                 bool        analyze = false;
    3229             :                 ListCell   *lc;
    3230             : 
    3231             :                 /* Look through an EXPLAIN ANALYZE to the contained stmt */
    3232           0 :                 foreach(lc, stmt->options)
    3233             :                 {
    3234           0 :                     DefElem    *opt = (DefElem *) lfirst(lc);
    3235             : 
    3236           0 :                     if (strcmp(opt->defname, "analyze") == 0)
    3237           0 :                         analyze = defGetBoolean(opt);
    3238             :                     /* don't "break", as explain.c will use the last value */
    3239             :                 }
    3240           0 :                 if (analyze)
    3241           0 :                     return GetCommandLogLevel(stmt->query);
    3242             : 
    3243             :                 /* Plain EXPLAIN isn't so interesting */
    3244           0 :                 lev = LOGSTMT_ALL;
    3245             :             }
    3246           0 :             break;
    3247             : 
    3248             :         case T_CreateTableAsStmt:
    3249           0 :             lev = LOGSTMT_DDL;
    3250           0 :             break;
    3251             : 
    3252             :         case T_RefreshMatViewStmt:
    3253           0 :             lev = LOGSTMT_DDL;
    3254           0 :             break;
    3255             : 
    3256             :         case T_AlterSystemStmt:
    3257           0 :             lev = LOGSTMT_DDL;
    3258           0 :             break;
    3259             : 
    3260             :         case T_VariableSetStmt:
    3261           0 :             lev = LOGSTMT_ALL;
    3262           0 :             break;
    3263             : 
    3264             :         case T_VariableShowStmt:
    3265           0 :             lev = LOGSTMT_ALL;
    3266           0 :             break;
    3267             : 
    3268             :         case T_DiscardStmt:
    3269           0 :             lev = LOGSTMT_ALL;
    3270           0 :             break;
    3271             : 
    3272             :         case T_CreateTrigStmt:
    3273           0 :             lev = LOGSTMT_DDL;
    3274           0 :             break;
    3275             : 
    3276             :         case T_CreateEventTrigStmt:
    3277           0 :             lev = LOGSTMT_DDL;
    3278           0 :             break;
    3279             : 
    3280             :         case T_AlterEventTrigStmt:
    3281           0 :             lev = LOGSTMT_DDL;
    3282           0 :             break;
    3283             : 
    3284             :         case T_CreatePLangStmt:
    3285           0 :             lev = LOGSTMT_DDL;
    3286           0 :             break;
    3287             : 
    3288             :         case T_CreateDomainStmt:
    3289           0 :             lev = LOGSTMT_DDL;
    3290           0 :             break;
    3291             : 
    3292             :         case T_CreateRoleStmt:
    3293           0 :             lev = LOGSTMT_DDL;
    3294           0 :             break;
    3295             : 
    3296             :         case T_AlterRoleStmt:
    3297           0 :             lev = LOGSTMT_DDL;
    3298           0 :             break;
    3299             : 
    3300             :         case T_AlterRoleSetStmt:
    3301           0 :             lev = LOGSTMT_DDL;
    3302           0 :             break;
    3303             : 
    3304             :         case T_DropRoleStmt:
    3305           0 :             lev = LOGSTMT_DDL;
    3306           0 :             break;
    3307             : 
    3308             :         case T_DropOwnedStmt:
    3309           0 :             lev = LOGSTMT_DDL;
    3310           0 :             break;
    3311             : 
    3312             :         case T_ReassignOwnedStmt:
    3313           0 :             lev = LOGSTMT_DDL;
    3314           0 :             break;
    3315             : 
    3316             :         case T_LockStmt:
    3317           0 :             lev = LOGSTMT_ALL;
    3318           0 :             break;
    3319             : 
    3320             :         case T_ConstraintsSetStmt:
    3321           0 :             lev = LOGSTMT_ALL;
    3322           0 :             break;
    3323             : 
    3324             :         case T_CheckPointStmt:
    3325           0 :             lev = LOGSTMT_ALL;
    3326           0 :             break;
    3327             : 
    3328             :         case T_ReindexStmt:
    3329           0 :             lev = LOGSTMT_ALL;  /* should this be DDL? */
    3330           0 :             break;
    3331             : 
    3332             :         case T_CreateConversionStmt:
    3333           0 :             lev = LOGSTMT_DDL;
    3334           0 :             break;
    3335             : 
    3336             :         case T_CreateCastStmt:
    3337           0 :             lev = LOGSTMT_DDL;
    3338           0 :             break;
    3339             : 
    3340             :         case T_CreateOpClassStmt:
    3341           0 :             lev = LOGSTMT_DDL;
    3342           0 :             break;
    3343             : 
    3344             :         case T_CreateOpFamilyStmt:
    3345           0 :             lev = LOGSTMT_DDL;
    3346           0 :             break;
    3347             : 
    3348             :         case T_CreateTransformStmt:
    3349           0 :             lev = LOGSTMT_DDL;
    3350           0 :             break;
    3351             : 
    3352             :         case T_AlterOpFamilyStmt:
    3353           0 :             lev = LOGSTMT_DDL;
    3354           0 :             break;
    3355             : 
    3356             :         case T_CreatePolicyStmt:
    3357           0 :             lev = LOGSTMT_DDL;
    3358           0 :             break;
    3359             : 
    3360             :         case T_AlterPolicyStmt:
    3361           0 :             lev = LOGSTMT_DDL;
    3362           0 :             break;
    3363             : 
    3364             :         case T_AlterTSDictionaryStmt:
    3365           0 :             lev = LOGSTMT_DDL;
    3366           0 :             break;
    3367             : 
    3368             :         case T_AlterTSConfigurationStmt:
    3369           0 :             lev = LOGSTMT_DDL;
    3370           0 :             break;
    3371             : 
    3372             :         case T_CreateAmStmt:
    3373           0 :             lev = LOGSTMT_DDL;
    3374           0 :             break;
    3375             : 
    3376             :         case T_CreatePublicationStmt:
    3377           0 :             lev = LOGSTMT_DDL;
    3378           0 :             break;
    3379             : 
    3380             :         case T_AlterPublicationStmt:
    3381           0 :             lev = LOGSTMT_DDL;
    3382           0 :             break;
    3383             : 
    3384             :         case T_CreateSubscriptionStmt:
    3385           0 :             lev = LOGSTMT_DDL;
    3386           0 :             break;
    3387             : 
    3388             :         case T_AlterSubscriptionStmt:
    3389           0 :             lev = LOGSTMT_DDL;
    3390           0 :             break;
    3391             : 
    3392             :         case T_DropSubscriptionStmt:
    3393           0 :             lev = LOGSTMT_DDL;
    3394           0 :             break;
    3395             : 
    3396             :         case T_CreateStatsStmt:
    3397           0 :             lev = LOGSTMT_DDL;
    3398           0 :             break;
    3399             : 
    3400             :         case T_AlterStatsStmt:
    3401           0 :             lev = LOGSTMT_DDL;
    3402           0 :             break;
    3403             : 
    3404             :         case T_AlterCollationStmt:
    3405           0 :             lev = LOGSTMT_DDL;
    3406           0 :             break;
    3407             : 
    3408             :             /* already-planned queries */
    3409             :         case T_PlannedStmt:
    3410             :             {
    3411           0 :                 PlannedStmt *stmt = (PlannedStmt *) parsetree;
    3412             : 
    3413           0 :                 switch (stmt->commandType)
    3414             :                 {
    3415             :                     case CMD_SELECT:
    3416           0 :                         lev = LOGSTMT_ALL;
    3417           0 :                         break;
    3418             : 
    3419             :                     case CMD_UPDATE:
    3420             :                     case CMD_INSERT:
    3421             :                     case CMD_DELETE:
    3422           0 :                         lev = LOGSTMT_MOD;
    3423           0 :                         break;
    3424             : 
    3425             :                     case CMD_UTILITY:
    3426           0 :                         lev = GetCommandLogLevel(stmt->utilityStmt);
    3427           0 :                         break;
    3428             : 
    3429             :                     default:
    3430           0 :                         elog(WARNING, "unrecognized commandType: %d",
    3431             :                              (int) stmt->commandType);
    3432           0 :                         lev = LOGSTMT_ALL;
    3433           0 :                         break;
    3434             :                 }
    3435             :             }
    3436           0 :             break;
    3437             : 
    3438             :             /* parsed-and-rewritten-but-not-planned queries */
    3439             :         case T_Query:
    3440             :             {
    3441           0 :                 Query      *stmt = (Query *) parsetree;
    3442             : 
    3443           0 :                 switch (stmt->commandType)
    3444             :                 {
    3445             :                     case CMD_SELECT:
    3446           0 :                         lev = LOGSTMT_ALL;
    3447           0 :                         break;
    3448             : 
    3449             :                     case CMD_UPDATE:
    3450             :                     case CMD_INSERT:
    3451             :                     case CMD_DELETE:
    3452           0 :                         lev = LOGSTMT_MOD;
    3453           0 :                         break;
    3454             : 
    3455             :                     case CMD_UTILITY:
    3456           0 :                         lev = GetCommandLogLevel(stmt->utilityStmt);
    3457           0 :                         break;
    3458             : 
    3459             :                     default:
    3460           0 :                         elog(WARNING, "unrecognized commandType: %d",
    3461             :                              (int) stmt->commandType);
    3462           0 :                         lev = LOGSTMT_ALL;
    3463           0 :                         break;
    3464             :                 }
    3465             : 
    3466             :             }
    3467           0 :             break;
    3468             : 
    3469             :         default:
    3470           0 :             elog(WARNING, "unrecognized node type: %d",
    3471             :                  (int) nodeTag(parsetree));
    3472           0 :             lev = LOGSTMT_ALL;
    3473           0 :             break;
    3474             :     }
    3475             : 
    3476           0 :     return lev;
    3477             : }

Generated by: LCOV version 1.13