From: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #10404: auto_explain for EXPLAIN ANLYZE.
Date: Wed, 21 May 2014 11:37:21 +0900
Message-ID: <537C1161.40809@po.ntts.co.jp> (raw)
In-Reply-To: <11712.1400586687@sss.pgh.pa.us>
References: <20140520074209.20346.37609@wrigleys.postgresql.org>
<11712.1400586687@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Hi Tom,
Thank you for checking it.
(2014/05/20 20:51), Tom Lane wrote:
> katsumata.tomonari@po.ntts.co.jp writes:
>> [ auto_explain changes the user-visible behavior of EXPLAIN ]
>> Is this an intentional thing? or bug?
>
> Yeah, that's a bug. The code in explain.c is looking at whether it got
> timing results, not whether it asked for them ...
>
I made a patch for this bug.
Please see the attached patch.
According to my understanding,
explain.c flows like below.
ExplainOnePlan
- call ExecutorStart(explain_ExecutorStart)
- call ExecutorRun(explain_ExecutorRun)
- call ExecutorFinish(explain_ExecutorFinish)
- call ExplainPrintPlan *A*
- call ExecutorEnd(explain_ExecutorEnd) *B*
The query result is printed at *A*, and then
auto_explain log message is printed at *B*.
So I add a check in explain_ExecutorFinish if the query has
"EXPLAIN ANALYZE TIMING OFF" or not to supress timing output
at *A*.
And I add a check in explain_ExecutorEnd if the setting of
auto_explain need timing information or not.
To distinguish "EXPLAIN ANALYZE TIMING OFF" or not, I use
queryDesc->instrument_options has INSTRUMENT_ROWS flag or not.
And also to distinguish if auto_explain needs timing info or not,
I use queryDesc->instrument_options has INSTRUMENT_TIMING flag or not.
This works fine, but I'm not sure I should to use INSTRUMENT_ROWS flag
for this. Because it seems that the flags is used but not referenced
from anywhere in current code.
Will this flag be obsoleted?
regards,
--------------------
Tomonari Katsumata
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:fix-auto_explain-explain-analyze-timing-off.patch (text/x-patch, 784B) downloaddiff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.cindex 57dfbe2..408fa84 100644--- a/contrib/auto_explain/auto_explain.c+++ b/contrib/auto_explain/auto_explain.c@@ -255,6 +255,9 @@ explain_ExecutorFinish(QueryDesc *queryDesc)
else
standard_ExecutorFinish(queryDesc);
nesting_level--;
++ if (queryDesc->instrument_options & INSTRUMENT_ROWS)+ queryDesc->planstate->instrument->need_timer = false;
}
PG_CATCH();
{
@@ -270,6 +273,9 @@ explain_ExecutorFinish(QueryDesc *queryDesc)
static void
explain_ExecutorEnd(QueryDesc *queryDesc)
{
+ if (queryDesc->instrument_options & INSTRUMENT_TIMER)+ queryDesc->planstate->instrument->need_timer = true;+
if (queryDesc->totaltime && auto_explain_enabled())
{
double msec;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: katsumata.tomonari@po.ntts.co.jp, tgl@sss.pgh.pa.us
Subject: Re: BUG #10404: auto_explain for EXPLAIN ANLYZE.
In-Reply-To: <537C1161.40809@po.ntts.co.jp>
References: <20140520074209.20346.37609@wrigleys.postgresql.org> <11712.1400586687@sss.pgh.pa.us> <537C1161.40809@po.ntts.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox