Commit 839484f9 authored by Tom Lane's avatar Tom Lane

Avoid scribbling on original parsetree during DECLARE CURSOR. This

prevents problems when the DECLARE is in a portal and is executed
repeatedly, as is possible in v3 protocol.  Per analysis by Oliver
Jowett, though I didn't use his patch exactly.
parent 3ad9f45c
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.36 2004/09/16 16:58:28 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.37 2004/11/28 22:16:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,13 +61,22 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params) ...@@ -61,13 +61,22 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
if (!(stmt->options & CURSOR_OPT_HOLD)) if (!(stmt->options & CURSOR_OPT_HOLD))
RequireTransactionChain((void *) stmt, "DECLARE CURSOR"); RequireTransactionChain((void *) stmt, "DECLARE CURSOR");
/*
* Because the planner is not cool about not scribbling on its input,
* we make a preliminary copy of the source querytree. This prevents
* problems in the case that the DECLARE CURSOR is in a portal and is
* executed repeatedly. XXX the planner really shouldn't modify its
* input ... FIXME someday.
*/
query = copyObject(stmt->query);
/* /*
* The query has been through parse analysis, but not rewriting or * The query has been through parse analysis, but not rewriting or
* planning as yet. Note that the grammar ensured we have a SELECT * planning as yet. Note that the grammar ensured we have a SELECT
* query, so we are not expecting rule rewriting to do anything * query, so we are not expecting rule rewriting to do anything
* strange. * strange.
*/ */
rewritten = QueryRewrite((Query *) stmt->query); rewritten = QueryRewrite(query);
if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query)) if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query))
elog(ERROR, "unexpected rewrite result"); elog(ERROR, "unexpected rewrite result");
query = (Query *) linitial(rewritten); query = (Query *) linitial(rewritten);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment