mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
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.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.303 2009/01/01 17:23:37 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.304 2009/01/02 20:42:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1054,7 +1054,8 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
|
||||
((DR_copy *) dest)->cstate = cstate;
|
||||
|
||||
/* Create a QueryDesc requesting no output */
|
||||
cstate->queryDesc = CreateQueryDesc(plan, GetActiveSnapshot(),
|
||||
cstate->queryDesc = CreateQueryDesc(plan, queryString,
|
||||
GetActiveSnapshot(),
|
||||
InvalidSnapshot,
|
||||
dest, NULL, false);
|
||||
|
||||
|
||||
@@ -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.183 2009/01/01 17:23:37 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.184 2009/01/02 20:42:00 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -172,7 +172,7 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, const char *queryString,
|
||||
plan = pg_plan_query(query, 0, params);
|
||||
|
||||
/* run it (if needed) and produce output */
|
||||
ExplainOnePlan(plan, params, stmt, tstate);
|
||||
ExplainOnePlan(plan, stmt, queryString, params, tstate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +218,9 @@ ExplainOneUtility(Node *utilityStmt, ExplainStmt *stmt,
|
||||
* to call it.
|
||||
*/
|
||||
void
|
||||
ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
|
||||
ExplainStmt *stmt, TupOutputState *tstate)
|
||||
ExplainOnePlan(PlannedStmt *plannedstmt, ExplainStmt *stmt,
|
||||
const char *queryString, ParamListInfo params,
|
||||
TupOutputState *tstate)
|
||||
{
|
||||
QueryDesc *queryDesc;
|
||||
instr_time starttime;
|
||||
@@ -234,7 +235,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
|
||||
PushUpdatedSnapshot(GetActiveSnapshot());
|
||||
|
||||
/* Create a QueryDesc requesting no output */
|
||||
queryDesc = CreateQueryDesc(plannedstmt,
|
||||
queryDesc = CreateQueryDesc(plannedstmt, queryString,
|
||||
GetActiveSnapshot(), InvalidSnapshot,
|
||||
None_Receiver, params,
|
||||
stmt->analyze);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user