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