Editorialize a bit on new ProcessUtility() API.

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.
This commit is contained in:
Tom Lane 2013-04-28 00:18:45 -04:00
parent 5525e6c40b
commit f8db76e875
10 changed files with 80 additions and 68 deletions

View 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);
}
}

View 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();
{

View 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();

View 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();
}

View 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);

View 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

View 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)

View 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));

View 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 */

View 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);