Commit 02490d46 authored by Robert Haas's avatar Robert Haas

Export ExplainBeginOutput() and ExplainEndOutput() for auto_explain.

Without these functions, anyone outside of explain.c can't actually use
ExplainPrintPlan, because the ExplainState won't be initialized properly.
The user-visible result of this was a crash when using auto_explain with
the JSON output format.

Report by Euler Taveira de Oliveira.  Analysis by Tom Lane.  Patch by me.
parent 6b45e3b7
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2008-2009, PostgreSQL Global Development Group * Copyright (c) 2008-2009, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.8 2009/12/11 01:33:35 adunstan Exp $ * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.9 2009/12/12 00:35:33 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -223,7 +223,9 @@ explain_ExecutorEnd(QueryDesc *queryDesc) ...@@ -223,7 +223,9 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
es.verbose = auto_explain_log_verbose; es.verbose = auto_explain_log_verbose;
es.format = auto_explain_log_format; es.format = auto_explain_log_format;
ExplainBeginOutput(&es);
ExplainPrintPlan(&es, queryDesc); ExplainPrintPlan(&es, queryDesc);
ExplainEndOutput(&es);
/* Remove last line break */ /* Remove last line break */
if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n') if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n')
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California * Portions Copyright (c) 1994-5, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.194 2009/12/11 01:33:35 adunstan Exp $ * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.195 2009/12/12 00:35:33 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -91,8 +91,6 @@ static void ExplainCloseGroup(const char *objtype, const char *labelname, ...@@ -91,8 +91,6 @@ static void ExplainCloseGroup(const char *objtype, const char *labelname,
bool labeled, ExplainState *es); bool labeled, ExplainState *es);
static void ExplainDummyGroup(const char *objtype, const char *labelname, static void ExplainDummyGroup(const char *objtype, const char *labelname,
ExplainState *es); ExplainState *es);
static void ExplainBeginOutput(ExplainState *es);
static void ExplainEndOutput(ExplainState *es);
static void ExplainXMLTag(const char *tagname, int flags, ExplainState *es); static void ExplainXMLTag(const char *tagname, int flags, ExplainState *es);
static void ExplainJSONLineEnding(ExplainState *es); static void ExplainJSONLineEnding(ExplainState *es);
static void ExplainYAMLLineStarting(ExplainState *es); static void ExplainYAMLLineStarting(ExplainState *es);
...@@ -1791,7 +1789,7 @@ ExplainDummyGroup(const char *objtype, const char *labelname, ExplainState *es) ...@@ -1791,7 +1789,7 @@ ExplainDummyGroup(const char *objtype, const char *labelname, ExplainState *es)
* This is just enough different from processing a subgroup that we need * This is just enough different from processing a subgroup that we need
* a separate pair of subroutines. * a separate pair of subroutines.
*/ */
static void void
ExplainBeginOutput(ExplainState *es) ExplainBeginOutput(ExplainState *es)
{ {
switch (es->format) switch (es->format)
...@@ -1822,7 +1820,7 @@ ExplainBeginOutput(ExplainState *es) ...@@ -1822,7 +1820,7 @@ ExplainBeginOutput(ExplainState *es)
/* /*
* Emit the end-of-output boilerplate. * Emit the end-of-output boilerplate.
*/ */
static void void
ExplainEndOutput(ExplainState *es) ExplainEndOutput(ExplainState *es)
{ {
switch (es->format) switch (es->format)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994-5, Regents of the University of California * Portions Copyright (c) 1994-5, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.42 2009/12/11 01:33:35 adunstan Exp $ * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.43 2009/12/12 00:35:34 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -65,6 +65,8 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es, ...@@ -65,6 +65,8 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es,
extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc); extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
extern void ExplainBeginOutput(ExplainState *es);
extern void ExplainEndOutput(ExplainState *es);
extern void ExplainSeparatePlans(ExplainState *es); extern void ExplainSeparatePlans(ExplainState *es);
#endif /* EXPLAIN_H */ #endif /* EXPLAIN_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment