diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-01-15 22:36:35 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-01-15 22:36:35 +0000 |
commit | 08f8d478ebc37e42f3ced07d17dae83d6a9a3810 (patch) | |
tree | aedef12bd96c3a789c72ae38e3cfab39801d4556 /src/backend/commands/explain.c | |
parent | 00b5ccebdd0d2925a2e5db0fdf067ea4b7bae799 (diff) | |
download | postgresql-08f8d478ebc37e42f3ced07d17dae83d6a9a3810.tar.gz postgresql-08f8d478ebc37e42f3ced07d17dae83d6a9a3810.zip |
Do parse analysis of an EXPLAIN's contained statement during the normal
parse analysis phase, rather than at execution time. This makes parameter
handling work the same as it does in ordinary plannable queries, and in
particular fixes the incompatibility that Pavel pointed out with plpgsql's
new handling of variable references. plancache.c gets a little bit
grottier, but the alternatives seem worse.
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r-- | src/backend/commands/explain.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 1617dedcef8..37647e57398 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994-5, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.198 2010/01/02 16:57:37 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.199 2010/01/15 22:36:29 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -158,19 +158,19 @@ ExplainQuery(ExplainStmt *stmt, const char *queryString, errmsg("EXPLAIN option BUFFERS requires ANALYZE"))); /* - * Run parse analysis and rewrite. Note this also acquires sufficient - * locks on the source table(s). + * Parse analysis was done already, but we still have to run the rule + * rewriter. We do not do AcquireRewriteLocks: we assume the query + * either came straight from the parser, or suitable locks were + * acquired by plancache.c. * - * Because the parser and planner tend to scribble on their input, we make + * Because the rewriter and planner tend to scribble on the input, we make * a preliminary copy of the source querytree. This prevents problems in * the case that the EXPLAIN is in a portal or plpgsql function and is * executed repeatedly. (See also the same hack in DECLARE CURSOR and * PREPARE.) XXX FIXME someday. */ - rewritten = pg_analyze_and_rewrite_params((Node *) copyObject(stmt->query), - queryString, - (ParserSetupHook) setupParserWithParamList, - params); + Assert(IsA(stmt->query, Query)); + rewritten = QueryRewrite((Query *) copyObject(stmt->query)); /* emit opening boilerplate */ ExplainBeginOutput(&es); @@ -248,6 +248,7 @@ ExplainResultDesc(ExplainStmt *stmt) char *p = defGetString(opt); xml = (strcmp(p, "xml") == 0); + /* don't "break", as ExplainQuery will use the last value */ } } |