summaryrefslogtreecommitdiff
path: root/src/backend/commands/prepare.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-01-02 20:42:00 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-01-02 20:42:00 +0000
commitbbeb0bbf6b3e5fdb7cff1a87885f43139ace5c4b (patch)
tree61f8c7f089cc1e35f20b76831bd388848c212799 /src/backend/commands/prepare.c
parentccd31eb861e727671e4a771d4bcc37f1179caec9 (diff)
downloadpostgresql-bbeb0bbf6b3e5fdb7cff1a87885f43139ace5c4b.tar.gz
Include a pointer to the query's source text in QueryDesc structs. This is
practically free given prior 8.4 changes in plancache and portal management, and it makes it a lot easier for ExecutorStart/Run/End hooks to get at the query text. Extracted from Itagaki Takahiro's pg_stat_statements patch, with minor editorialization.
Diffstat (limited to 'src/backend/commands/prepare.c')
-rw-r--r--src/backend/commands/prepare.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 29f3df711a..e1c0edb8e8 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -10,7 +10,7 @@
* Copyright (c) 2002-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.95 2009/01/01 17:23:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.96 2009/01/02 20:42:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -636,6 +636,9 @@ DropAllPreparedStatements(void)
/*
* Implements the 'EXPLAIN EXECUTE' utility statement.
+ *
+ * Note: the passed-in queryString is that of the EXPLAIN EXECUTE,
+ * not the original PREPARE; we get the latter string from the plancache.
*/
void
ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt,
@@ -643,6 +646,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt,
ParamListInfo params, TupOutputState *tstate)
{
PreparedStatement *entry;
+ const char *query_string;
CachedPlan *cplan;
List *plan_list;
ListCell *p;
@@ -659,6 +663,8 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt,
if (!entry->plansource->fixed_result)
elog(ERROR, "EXPLAIN EXECUTE does not support variable-result cached plans");
+ query_string = entry->plansource->query_string;
+
/* Replan if needed, and acquire a transient refcount */
cplan = RevalidateCachedPlan(entry->plansource, true);
@@ -701,11 +707,12 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt,
pstmt->intoClause = execstmt->into;
}
- ExplainOnePlan(pstmt, paramLI, stmt, tstate);
+ ExplainOnePlan(pstmt, stmt, query_string,
+ paramLI, tstate);
}
else
{
- ExplainOneUtility((Node *) pstmt, stmt, queryString,
+ ExplainOneUtility((Node *) pstmt, stmt, query_string,
params, tstate);
}