Skip to content

Commit fc5173a

Browse files
committed
Add query text to auto_explain output.
Still to be done: fix docs and fix regression failures under auto_explain.
1 parent 56adf37 commit fc5173a

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

contrib/auto_explain/auto_explain.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2008-2010, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.12 2010/01/06 18:07:19 tgl Exp $
9+
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.13 2010/02/16 22:19:59 adunstan Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -240,6 +240,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
240240
es.format = auto_explain_log_format;
241241

242242
ExplainBeginOutput(&es);
243+
ExplainQueryText(&es, queryDesc);
243244
ExplainPrintPlan(&es, queryDesc);
244245
ExplainEndOutput(&es);
245246

@@ -255,7 +256,8 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
255256
*/
256257
ereport(LOG,
257258
(errmsg("duration: %.3f ms plan:\n%s",
258-
msec, es.str->data)));
259+
msec, es.str->data),
260+
errhidestmt(true)));
259261

260262
pfree(es.str->data);
261263
}

src/backend/commands/explain.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994-5, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.202 2010/02/16 20:07:13 stark Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.203 2010/02/16 22:19:59 adunstan Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -487,6 +487,21 @@ ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
487487
NULL, NULL, NULL, es);
488488
}
489489

490+
/*
491+
* ExplainQueryText -
492+
* add a "Query Text" node that contains the actual text of the query
493+
*
494+
* The caller should have set up the options fields of *es, as well as
495+
* initializing the output buffer es->str.
496+
*
497+
*/
498+
void
499+
ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
500+
{
501+
if (queryDesc->sourceText)
502+
ExplainPropertyText("Query Text", queryDesc->sourceText, es);
503+
}
504+
490505
/*
491506
* report_triggers -
492507
* report execution stats for a single relation's triggers

src/include/commands/explain.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994-5, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.45 2010/01/02 16:58:03 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.46 2010/02/16 22:19:59 adunstan Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -66,6 +66,8 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es,
6666

6767
extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
6868

69+
extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
70+
6971
extern void ExplainBeginOutput(ExplainState *es);
7072
extern void ExplainEndOutput(ExplainState *es);
7173
extern void ExplainSeparatePlans(ExplainState *es);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy