|
14 | 14 | *
|
15 | 15 | *
|
16 | 16 | * IDENTIFICATION
|
17 |
| - * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.36 2004/09/16 16:58:28 tgl Exp $ |
| 17 | + * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.37 2004/11/28 22:16:31 tgl Exp $ |
18 | 18 | *
|
19 | 19 | *-------------------------------------------------------------------------
|
20 | 20 | */
|
@@ -61,13 +61,22 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
|
61 | 61 | if (!(stmt->options & CURSOR_OPT_HOLD))
|
62 | 62 | RequireTransactionChain((void *) stmt, "DECLARE CURSOR");
|
63 | 63 |
|
| 64 | + /* |
| 65 | + * Because the planner is not cool about not scribbling on its input, |
| 66 | + * we make a preliminary copy of the source querytree. This prevents |
| 67 | + * problems in the case that the DECLARE CURSOR is in a portal and is |
| 68 | + * executed repeatedly. XXX the planner really shouldn't modify its |
| 69 | + * input ... FIXME someday. |
| 70 | + */ |
| 71 | + query = copyObject(stmt->query); |
| 72 | + |
64 | 73 | /*
|
65 | 74 | * The query has been through parse analysis, but not rewriting or
|
66 | 75 | * planning as yet. Note that the grammar ensured we have a SELECT
|
67 | 76 | * query, so we are not expecting rule rewriting to do anything
|
68 | 77 | * strange.
|
69 | 78 | */
|
70 |
| - rewritten = QueryRewrite((Query *) stmt->query); |
| 79 | + rewritten = QueryRewrite(query); |
71 | 80 | if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query))
|
72 | 81 | elog(ERROR, "unexpected rewrite result");
|
73 | 82 | query = (Query *) linitial(rewritten);
|
|
0 commit comments