From 08f8d478ebc37e42f3ced07d17dae83d6a9a3810 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 15 Jan 2010 22:36:35 +0000 Subject: 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. --- src/backend/commands/explain.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/backend/commands/explain.c') 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 */ } } -- cgit v1.2.3