|
10 | 10 | * Copyright (c) 2002-2004, PostgreSQL Global Development Group
|
11 | 11 | *
|
12 | 12 | * IDENTIFICATION
|
13 |
| - * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.34 2004/12/03 21:26:31 tgl Exp $ |
| 13 | + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.35 2004/12/12 20:17:06 tgl Exp $ |
14 | 14 | *
|
15 | 15 | *-------------------------------------------------------------------------
|
16 | 16 | */
|
|
48 | 48 | PrepareQuery(PrepareStmt*stmt)
|
49 | 49 | {
|
50 | 50 | constchar*commandTag;
|
| 51 | +Query*query; |
51 | 52 | List*query_list,
|
52 | 53 | *plan_list;
|
53 | 54 |
|
@@ -87,8 +88,18 @@ PrepareQuery(PrepareStmt *stmt)
|
87 | 88 | * the query.
|
88 | 89 | */
|
89 | 90 |
|
| 91 | +/* |
| 92 | + * Because the planner is not cool about not scribbling on its input, |
| 93 | + * we make a preliminary copy of the source querytree. This prevents |
| 94 | + * problems in the case that the PREPARE is in a portal or plpgsql |
| 95 | + * function and is executed repeatedly. (See also the same hack in |
| 96 | + * DECLARE CURSOR and EXPLAIN.) XXX the planner really shouldn't |
| 97 | + * modify its input ... FIXME someday. |
| 98 | + */ |
| 99 | +query=copyObject(stmt->query); |
| 100 | + |
90 | 101 | /* Rewrite the query. The result could be 0, 1, or many queries. */
|
91 |
| -query_list=QueryRewrite(stmt->query); |
| 102 | +query_list=QueryRewrite(query); |
92 | 103 |
|
93 | 104 | /* Generate plans for queries.Snapshot is already set. */
|
94 | 105 | plan_list=pg_plan_queries(query_list,NULL, false);
|
|