]> granicus.if.org Git - postgresql/commitdiff
Editorialize a bit on new ProcessUtility() API.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 28 Apr 2013 04:18:45 +0000 (00:18 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 28 Apr 2013 04:18:45 +0000 (00:18 -0400)
Choose a saner ordering of parameters (adding a new input param after
the output params seemed a bit random), update the function's header
comment to match reality (cmon folks, is this really that hard?),
get rid of useless and sloppily-defined distinction between
PROCESS_UTILITY_SUBCOMMAND and PROCESS_UTILITY_GENERATED.

contrib/pg_stat_statements/pg_stat_statements.c
contrib/sepgsql/hooks.c
src/backend/commands/extension.c
src/backend/commands/schemacmds.c
src/backend/commands/trigger.c
src/backend/executor/functions.c
src/backend/executor/spi.c
src/backend/tcop/pquery.c
src/backend/tcop/utility.c
src/include/tcop/utility.h

index 8b6f88baf7a41dc66b72ba1240cba046483e6e11..a6ceaf4f3838f5be32951e55af0f0b06ac15d056 100644 (file)
@@ -239,10 +239,9 @@ static void pgss_ExecutorRun(QueryDesc *queryDesc,
                                 long count);
 static void pgss_ExecutorFinish(QueryDesc *queryDesc);
 static void pgss_ExecutorEnd(QueryDesc *queryDesc);
-static void pgss_ProcessUtility(Node *parsetree,
-                         const char *queryString, ParamListInfo params,
-                                       DestReceiver *dest, char *completionTag,
-                                       ProcessUtilityContext context);
+static void pgss_ProcessUtility(Node *parsetree, const char *queryString,
+                                       ProcessUtilityContext context, ParamListInfo params,
+                                       DestReceiver *dest, char *completionTag);
 static uint32 pgss_hash_fn(const void *key, Size keysize);
 static int     pgss_match_fn(const void *key1, const void *key2, Size keysize);
 static uint32 pgss_hash_string(const char *str);
@@ -786,8 +785,8 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
  */
 static void
 pgss_ProcessUtility(Node *parsetree, const char *queryString,
-                                       ParamListInfo params, DestReceiver *dest,
-                                       char *completionTag, ProcessUtilityContext context)
+                                       ProcessUtilityContext context, ParamListInfo params,
+                                       DestReceiver *dest, char *completionTag)
 {
        /*
         * If it's an EXECUTE statement, we don't track it and don't increment the
@@ -819,11 +818,13 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
                PG_TRY();
                {
                        if (prev_ProcessUtility)
-                               prev_ProcessUtility(parsetree, queryString, params,
-                                                                       dest, completionTag, context);
+                               prev_ProcessUtility(parsetree, queryString,
+                                                                       context, params,
+                                                                       dest, completionTag);
                        else
-                               standard_ProcessUtility(parsetree, queryString, params,
-                                                                               dest, completionTag, context);
+                               standard_ProcessUtility(parsetree, queryString,
+                                                                               context, params,
+                                                                               dest, completionTag);
                        nested_level--;
                }
                PG_CATCH();
@@ -880,11 +881,13 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
        else
        {
                if (prev_ProcessUtility)
-                       prev_ProcessUtility(parsetree, queryString, params,
-                                                               dest, completionTag, context);
+                       prev_ProcessUtility(parsetree, queryString,
+                                                               context, params,
+                                                               dest, completionTag);
                else
-                       standard_ProcessUtility(parsetree, queryString, params,
-                                                                       dest, completionTag, context);
+                       standard_ProcessUtility(parsetree, queryString,
+                                                                       context, params,
+                                                                       dest, completionTag);
        }
 }
 
index 04c5120890d31185314dd6838bdd5a6815207290..a1320e86381a9b398b8d6a39cdd4f68242d199c5 100644 (file)
@@ -299,10 +299,10 @@ sepgsql_exec_check_perms(List *rangeTabls, bool abort)
 static void
 sepgsql_utility_command(Node *parsetree,
                                                const char *queryString,
+                                               ProcessUtilityContext context,
                                                ParamListInfo params,
                                                DestReceiver *dest,
-                                               char *completionTag,
-                                               ProcessUtilityContext context)
+                                               char *completionTag)
 {
        sepgsql_context_info_t saved_context_info = sepgsql_context_info;
        ListCell   *cell;
@@ -362,11 +362,13 @@ sepgsql_utility_command(Node *parsetree,
                }
 
                if (next_ProcessUtility_hook)
-                       (*next_ProcessUtility_hook) (parsetree, queryString, params,
-                                                                                dest, completionTag, context);
+                       (*next_ProcessUtility_hook) (parsetree, queryString,
+                                                                                context, params,
+                                                                                dest, completionTag);
                else
-                       standard_ProcessUtility(parsetree, queryString, params,
-                                                                       dest, completionTag, context);
+                       standard_ProcessUtility(parsetree, queryString,
+                                                                       context, params,
+                                                                       dest, completionTag);
        }
        PG_CATCH();
        {
index 36df8bddcad8c94a59d91b0c7115dbcb4b5949f0..2d84ac8620dc3a23a6c41b4b1ce618bef5d8fcab 100644 (file)
@@ -750,10 +750,10 @@ execute_sql_string(const char *sql, const char *filename)
                        {
                                ProcessUtility(stmt,
                                                           sql,
+                                                          PROCESS_UTILITY_QUERY,
                                                           NULL,
                                                           dest,
-                                                          NULL,
-                                                          PROCESS_UTILITY_QUERY);
+                                                          NULL);
                        }
 
                        PopActiveSnapshot();
index 21d7e608df43bf48f045e2a20af2d269d739e94c..1d13ba0d3046a603324ff2dbb9fb9f71cd8565a3 100644 (file)
@@ -151,10 +151,10 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
                /* do this step */
                ProcessUtility(stmt,
                                           queryString,
+                                          PROCESS_UTILITY_SUBCOMMAND,
                                           NULL,
                                           None_Receiver,
-                                          NULL,
-                                          PROCESS_UTILITY_SUBCOMMAND);
+                                          NULL);
                /* make sure later steps can see the object created here */
                CommandCounterIncrement();
        }
index bebb551f7fa75dbef370925472467713eae3faca..a0473498bd2de751a109107816d046e7857f0ad2 100644 (file)
@@ -1014,7 +1014,8 @@ ConvertTriggerToFK(CreateTrigStmt *stmt, Oid funcoid)
                /* ... and execute it */
                ProcessUtility((Node *) atstmt,
                                           "(generated ALTER TABLE ADD FOREIGN KEY command)",
-                                          NULL, None_Receiver, NULL, PROCESS_UTILITY_GENERATED);
+                                          PROCESS_UTILITY_SUBCOMMAND, NULL,
+                                          None_Receiver, NULL);
 
                /* Remove the matched item from the list */
                info_list = list_delete_ptr(info_list, info);
index c908f34cfe4bdd7fb0e059679d8307b2f75c8b23..dbb4805ae2c875818d828f782f3995c2de714699 100644 (file)
@@ -831,10 +831,10 @@ postquel_getnext(execution_state *es, SQLFunctionCachePtr fcache)
                                                (Node *) es->qd->plannedstmt :
                                                es->qd->utilitystmt),
                                           fcache->src,
+                                          PROCESS_UTILITY_QUERY,
                                           es->qd->params,
                                           es->qd->dest,
-                                          NULL,
-                                          PROCESS_UTILITY_QUERY);
+                                          NULL);
                result = true;                  /* never stops early */
        }
        else
index de8d59a8cdc44877d866eaf28da6f278b578e76b..ca0d05d2cc0fae877a8c7b37205683f33eeb6315 100644 (file)
@@ -2093,10 +2093,10 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
 
                                ProcessUtility(stmt,
                                                           plansource->query_string,
+                                                          PROCESS_UTILITY_QUERY,
                                                           paramLI,
                                                           dest,
-                                                          completionTag,
-                                                          PROCESS_UTILITY_QUERY);
+                                                          completionTag);
 
                                /* Update "processed" if stmt returned tuples */
                                if (_SPI_current->tuptable)
index 107d8aedab48bf14aaf259ab9ef0bbdd46ac20f4..2c3156a2e940f1a0bbcf3cddb0510bc65cfd0057 100644 (file)
@@ -1184,11 +1184,10 @@ PortalRunUtility(Portal portal, Node *utilityStmt, bool isTopLevel,
 
        ProcessUtility(utilityStmt,
                                   portal->sourceText,
+                                  isTopLevel ? PROCESS_UTILITY_TOPLEVEL : PROCESS_UTILITY_QUERY,
                                   portal->portalParams,
                                   dest,
-                                  completionTag,
-                                  isTopLevel ?
-                                       PROCESS_UTILITY_TOPLEVEL : PROCESS_UTILITY_QUERY);
+                                  completionTag);
 
        /* Some utility statements may change context on us */
        MemoryContextSwitchTo(PortalGetHeapMemory(portal));
index 2710db12321f457c7baf50e42c4ceaf6ddf19d42..c9408970b10a31a3f75cf863716a7393b16167c2 100644 (file)
@@ -71,10 +71,10 @@ ProcessUtility_hook_type ProcessUtility_hook = NULL;
 /* local function declarations */
 static void ProcessUtilitySlow(Node *parsetree,
                                   const char *queryString,
+                                  ProcessUtilityContext context,
                                   ParamListInfo params,
                                   DestReceiver *dest,
-                                  char *completionTag,
-                                  ProcessUtilityContext context);
+                                  char *completionTag);
 static void ExecDropStmt(DropStmt *stmt, bool isTopLevel);
 
 
@@ -314,8 +314,9 @@ CheckRestrictedOperation(const char *cmdname)
  *
  *     parsetree: the parse tree for the utility statement
  *     queryString: original source text of command
+ *     context: identifies source of statement (toplevel client command,
+ *             non-toplevel client command, subcommand of a larger utility command)
  *     params: parameters to use during execution
- *     isTopLevel: true if executing a "top level" (interactively issued) command
  *     dest: where to send results
  *     completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
  *             in which to store a command completion status string.
@@ -331,10 +332,10 @@ CheckRestrictedOperation(const char *cmdname)
 void
 ProcessUtility(Node *parsetree,
                           const char *queryString,
+                          ProcessUtilityContext context,
                           ParamListInfo params,
                           DestReceiver *dest,
-                          char *completionTag,
-                          ProcessUtilityContext context)
+                          char *completionTag)
 {
        Assert(queryString != NULL);    /* required as of 8.4 */
 
@@ -344,11 +345,13 @@ ProcessUtility(Node *parsetree,
         * call standard_ProcessUtility().
         */
        if (ProcessUtility_hook)
-               (*ProcessUtility_hook) (parsetree, queryString, params,
-                                                               dest, completionTag, context);
+               (*ProcessUtility_hook) (parsetree, queryString,
+                                                               context, params,
+                                                               dest, completionTag);
        else
-               standard_ProcessUtility(parsetree, queryString, params,
-                                                               dest, completionTag, context);
+               standard_ProcessUtility(parsetree, queryString,
+                                                               context, params,
+                                                               dest, completionTag);
 }
 
 /*
@@ -365,10 +368,10 @@ ProcessUtility(Node *parsetree,
 void
 standard_ProcessUtility(Node *parsetree,
                                                const char *queryString,
+                                               ProcessUtilityContext context,
                                                ParamListInfo params,
                                                DestReceiver *dest,
-                                               char *completionTag,
-                                               ProcessUtilityContext context)
+                                               char *completionTag)
 {
        bool            isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
 
@@ -817,8 +820,9 @@ standard_ProcessUtility(Node *parsetree,
                                DropStmt   *stmt = (DropStmt *) parsetree;
 
                                if (EventTriggerSupportsObjectType(stmt->removeType))
-                                       ProcessUtilitySlow(parsetree, queryString, params,
-                                                                          dest, completionTag, context);
+                                       ProcessUtilitySlow(parsetree, queryString,
+                                                                          context, params,
+                                                                          dest, completionTag);
                                else
                                        ExecDropStmt(stmt, isTopLevel);
                        }
@@ -829,8 +833,9 @@ standard_ProcessUtility(Node *parsetree,
                                RenameStmt *stmt = (RenameStmt *) parsetree;
 
                                if (EventTriggerSupportsObjectType(stmt->renameType))
-                                       ProcessUtilitySlow(parsetree, queryString, params,
-                                                                          dest, completionTag, context);
+                                       ProcessUtilitySlow(parsetree, queryString,
+                                                                          context, params,
+                                                                          dest, completionTag);
                                else
                                        ExecRenameStmt(stmt);
                        }
@@ -841,8 +846,9 @@ standard_ProcessUtility(Node *parsetree,
                                AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
 
                                if (EventTriggerSupportsObjectType(stmt->objectType))
-                                       ProcessUtilitySlow(parsetree, queryString, params,
-                                                                          dest, completionTag, context);
+                                       ProcessUtilitySlow(parsetree, queryString,
+                                                                          context, params,
+                                                                          dest, completionTag);
                                else
                                        ExecAlterObjectSchemaStmt(stmt);
                        }
@@ -853,8 +859,9 @@ standard_ProcessUtility(Node *parsetree,
                                AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
 
                                if (EventTriggerSupportsObjectType(stmt->objectType))
-                                       ProcessUtilitySlow(parsetree, queryString, params,
-                                                                          dest, completionTag, context);
+                                       ProcessUtilitySlow(parsetree, queryString,
+                                                                          context, params,
+                                                                          dest, completionTag);
                                else
                                        ExecAlterOwnerStmt(stmt);
                        }
@@ -862,8 +869,9 @@ standard_ProcessUtility(Node *parsetree,
 
                default:
                        /* All other statement types have event trigger support */
-                       ProcessUtilitySlow(parsetree, queryString, params,
-                                                          dest, completionTag, context);
+                       ProcessUtilitySlow(parsetree, queryString,
+                                                          context, params,
+                                                          dest, completionTag);
                        break;
        }
 }
@@ -876,10 +884,10 @@ standard_ProcessUtility(Node *parsetree,
 static void
 ProcessUtilitySlow(Node *parsetree,
                                   const char *queryString,
+                                  ProcessUtilityContext context,
                                   ParamListInfo params,
                                   DestReceiver *dest,
-                                  char *completionTag,
-                                  ProcessUtilityContext context)
+                                  char *completionTag)
 {
        bool            isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
        bool            isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
@@ -966,10 +974,10 @@ ProcessUtilitySlow(Node *parsetree,
                                                        /* Recurse for anything else */
                                                        ProcessUtility(stmt,
                                                                                   queryString,
+                                                                                  PROCESS_UTILITY_SUBCOMMAND,
                                                                                   params,
                                                                                   None_Receiver,
-                                                                                  NULL,
-                                                                                  PROCESS_UTILITY_GENERATED);
+                                                                                  NULL);
                                                }
 
                                                /* Need CCI between commands */
@@ -1017,10 +1025,10 @@ ProcessUtilitySlow(Node *parsetree,
                                                                /* Recurse for anything else */
                                                                ProcessUtility(stmt,
                                                                                           queryString,
+                                                                                          PROCESS_UTILITY_SUBCOMMAND,
                                                                                           params,
                                                                                           None_Receiver,
-                                                                                          NULL,
-                                                                                          PROCESS_UTILITY_GENERATED);
+                                                                                          NULL);
                                                        }
 
                                                        /* Need CCI between commands */
index 0697678979aa16ea8dff6f1e9136a67833149b53..9864447b726694bb2bc61850910d2ac37ddeb581 100644 (file)
@@ -20,23 +20,22 @@ typedef enum
 {
        PROCESS_UTILITY_TOPLEVEL,               /* toplevel interactive command */
        PROCESS_UTILITY_QUERY,                  /* a complete query, but not toplevel */
-       PROCESS_UTILITY_SUBCOMMAND,             /* a piece of a query */
-       PROCESS_UTILITY_GENERATED               /* internally generated node query node */
+       PROCESS_UTILITY_SUBCOMMAND              /* a portion of a query */
 } ProcessUtilityContext;
 
 /* Hook for plugins to get control in ProcessUtility() */
 typedef void (*ProcessUtility_hook_type) (Node *parsetree,
-                         const char *queryString, ParamListInfo params,
-                         DestReceiver *dest, char *completionTag,
-                         ProcessUtilityContext context);
+                         const char *queryString, ProcessUtilityContext context,
+                         ParamListInfo params,
+                         DestReceiver *dest, char *completionTag);
 extern PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook;
 
 extern void ProcessUtility(Node *parsetree, const char *queryString,
-                          ParamListInfo params, DestReceiver *dest, char *completionTag,
-                          ProcessUtilityContext context);
+                          ProcessUtilityContext context, ParamListInfo params,
+                          DestReceiver *dest, char *completionTag);
 extern void standard_ProcessUtility(Node *parsetree, const char *queryString,
-                                               ParamListInfo params, DestReceiver *dest,
-                                               char *completionTag, ProcessUtilityContext context);
+                                               ProcessUtilityContext context, ParamListInfo params,
+                                               DestReceiver *dest, char *completionTag);
 
 extern bool UtilityReturnsTuples(Node *parsetree);