Skip to content

Commit 02490d4

Browse files
committed
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.
1 parent 6b45e3b commit 02490d4

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

contrib/auto_explain/auto_explain.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.8 2009/12/11 01:33:35 adunstan Exp $
9+
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.9 2009/12/12 00:35:33 rhaas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -223,7 +223,9 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
223223
es.verbose = auto_explain_log_verbose;
224224
es.format = auto_explain_log_format;
225225

226+
ExplainBeginOutput(&es);
226227
ExplainPrintPlan(&es, queryDesc);
228+
ExplainEndOutput(&es);
227229

228230
/* Remove last line break */
229231
if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n')

src/backend/commands/explain.c

Lines changed: 3 additions & 5 deletions
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.194 2009/12/11 01:33:35 adunstan Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.195 2009/12/12 00:35:33 rhaas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -91,8 +91,6 @@ static void ExplainCloseGroup(const char *objtype, const char *labelname,
9191
bool labeled, ExplainState *es);
9292
static void ExplainDummyGroup(const char *objtype, const char *labelname,
9393
ExplainState *es);
94-
static void ExplainBeginOutput(ExplainState *es);
95-
static void ExplainEndOutput(ExplainState *es);
9694
static void ExplainXMLTag(const char *tagname, int flags, ExplainState *es);
9795
static void ExplainJSONLineEnding(ExplainState *es);
9896
static void ExplainYAMLLineStarting(ExplainState *es);
@@ -1791,7 +1789,7 @@ ExplainDummyGroup(const char *objtype, const char *labelname, ExplainState *es)
17911789
* This is just enough different from processing a subgroup that we need
17921790
* a separate pair of subroutines.
17931791
*/
1794-
static void
1792+
void
17951793
ExplainBeginOutput(ExplainState *es)
17961794
{
17971795
switch (es->format)
@@ -1822,7 +1820,7 @@ ExplainBeginOutput(ExplainState *es)
18221820
/*
18231821
* Emit the end-of-output boilerplate.
18241822
*/
1825-
static void
1823+
void
18261824
ExplainEndOutput(ExplainState *es)
18271825
{
18281826
switch (es->format)

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-2009, 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.42 2009/12/11 01:33:35 adunstan Exp $
9+
* $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.43 2009/12/12 00:35:34 rhaas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -65,6 +65,8 @@ extern void ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es,
6565

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

68+
extern void ExplainBeginOutput(ExplainState *es);
69+
extern void ExplainEndOutput(ExplainState *es);
6870
extern void ExplainSeparatePlans(ExplainState *es);
6971

7072
#endif /* EXPLAIN_H */

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