mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Modify processing of DECLARE CURSOR and EXPLAIN so that they can resolve the
types of unspecified parameters when submitted via extended query protocol. This worked in 8.2 but I had broken it during plancache changes. DECLARE CURSOR is now treated almost exactly like a plain SELECT through parse analysis, rewrite, and planning; only just before sending to the executor do we divert it away to ProcessUtility. This requires a special-case check in a number of places, but practically all of them were already special-casing SELECT INTO, so it's not too ugly. (Maybe it would be a good idea to merge the two by treating IntoClause as a form of utility statement? Not going to worry about that now, though.) That approach doesn't work for EXPLAIN, however, so for that I punted and used a klugy solution of running parse analysis an extra time if under extended query protocol.
This commit is contained in:
@ -26,7 +26,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.292 2007/03/29 00:15:38 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.293 2007/04/27 22:05:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -420,7 +420,7 @@ ExecCheckXactReadOnly(PlannedStmt *plannedstmt)
|
||||
*
|
||||
* XXX should we allow this if the destination is temp?
|
||||
*/
|
||||
if (plannedstmt->into != NULL)
|
||||
if (plannedstmt->intoClause != NULL)
|
||||
goto fail;
|
||||
|
||||
/* Fail if write permissions are requested on any non-temp table */
|
||||
@ -522,10 +522,10 @@ InitPlan(QueryDesc *queryDesc, int eflags)
|
||||
* correct tuple descriptors. (Other SELECT INTO stuff comes later.)
|
||||
*/
|
||||
estate->es_select_into = false;
|
||||
if (operation == CMD_SELECT && plannedstmt->into != NULL)
|
||||
if (operation == CMD_SELECT && plannedstmt->intoClause != NULL)
|
||||
{
|
||||
estate->es_select_into = true;
|
||||
estate->es_into_oids = interpretOidsOption(plannedstmt->into->options);
|
||||
estate->es_into_oids = interpretOidsOption(plannedstmt->intoClause->options);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2395,7 +2395,7 @@ typedef struct
|
||||
static void
|
||||
OpenIntoRel(QueryDesc *queryDesc)
|
||||
{
|
||||
IntoClause *into = queryDesc->plannedstmt->into;
|
||||
IntoClause *into = queryDesc->plannedstmt->intoClause;
|
||||
EState *estate = queryDesc->estate;
|
||||
Relation intoRelationDesc;
|
||||
char *intoName;
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.115 2007/04/16 01:14:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.116 2007/04/27 22:05:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -317,7 +317,7 @@ postquel_start(execution_state *es, SQLFunctionCachePtr fcache)
|
||||
/* We assume we don't need to set up ActiveSnapshot for ExecutorStart */
|
||||
|
||||
/* Utility commands don't need Executor. */
|
||||
if (es->qd->operation != CMD_UTILITY)
|
||||
if (es->qd->utilitystmt == NULL)
|
||||
{
|
||||
/*
|
||||
* Only set up to collect queued triggers if it's not a SELECT.
|
||||
@ -346,9 +346,12 @@ postquel_getnext(execution_state *es, SQLFunctionCachePtr fcache)
|
||||
{
|
||||
ActiveSnapshot = es->qd->snapshot;
|
||||
|
||||
if (es->qd->operation == CMD_UTILITY)
|
||||
if (es->qd->utilitystmt)
|
||||
{
|
||||
ProcessUtility(es->qd->utilitystmt,
|
||||
/* ProcessUtility needs the PlannedStmt for DECLARE CURSOR */
|
||||
ProcessUtility((es->qd->plannedstmt ?
|
||||
(Node *) es->qd->plannedstmt :
|
||||
es->qd->utilitystmt),
|
||||
fcache->src,
|
||||
es->qd->params,
|
||||
false, /* not top level */
|
||||
@ -366,7 +369,8 @@ postquel_getnext(execution_state *es, SQLFunctionCachePtr fcache)
|
||||
*/
|
||||
if (LAST_POSTQUEL_COMMAND(es) &&
|
||||
es->qd->operation == CMD_SELECT &&
|
||||
es->qd->plannedstmt->into == NULL)
|
||||
es->qd->plannedstmt->utilityStmt == NULL &&
|
||||
es->qd->plannedstmt->intoClause == NULL)
|
||||
count = 1L;
|
||||
else
|
||||
count = 0L;
|
||||
@ -396,7 +400,7 @@ postquel_end(execution_state *es)
|
||||
es->status = F_EXEC_DONE;
|
||||
|
||||
/* Utility commands don't need Executor. */
|
||||
if (es->qd->operation != CMD_UTILITY)
|
||||
if (es->qd->utilitystmt == NULL)
|
||||
{
|
||||
/* Make our snapshot the active one for any called functions */
|
||||
saveActiveSnapshot = ActiveSnapshot;
|
||||
@ -894,7 +898,9 @@ check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList,
|
||||
* Note: eventually replace this test with QueryReturnsTuples? We'd need
|
||||
* a more general method of determining the output type, though.
|
||||
*/
|
||||
if (!(parse->commandType == CMD_SELECT && parse->into == NULL))
|
||||
if (!(parse->commandType == CMD_SELECT &&
|
||||
parse->utilityStmt == NULL &&
|
||||
parse->intoClause == NULL))
|
||||
{
|
||||
if (rettype != VOIDOID)
|
||||
ereport(ERROR,
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.178 2007/04/16 18:21:07 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.179 2007/04/27 22:05:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1581,7 +1581,8 @@ _SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
|
||||
ActiveSnapshot->curcid = GetCurrentCommandId();
|
||||
}
|
||||
|
||||
if (IsA(stmt, PlannedStmt))
|
||||
if (IsA(stmt, PlannedStmt) &&
|
||||
((PlannedStmt *) stmt)->utilityStmt == NULL)
|
||||
{
|
||||
qdesc = CreateQueryDesc((PlannedStmt *) stmt,
|
||||
ActiveSnapshot,
|
||||
@ -1687,7 +1688,8 @@ _SPI_pquery(QueryDesc *queryDesc, long tcount)
|
||||
switch (operation)
|
||||
{
|
||||
case CMD_SELECT:
|
||||
if (queryDesc->plannedstmt->into) /* select into table? */
|
||||
Assert(queryDesc->plannedstmt->utilityStmt == NULL);
|
||||
if (queryDesc->plannedstmt->intoClause) /* select into table? */
|
||||
res = SPI_OK_SELINTO;
|
||||
else if (queryDesc->dest->mydest != DestSPI)
|
||||
{
|
||||
|
Reference in New Issue
Block a user