Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WmwPk-00010x-L9 for pgsql-bugs@arkaria.postgresql.org; Wed, 21 May 2014 02:37:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WmwPj-0001fU-W9 for pgsql-bugs@arkaria.postgresql.org; Wed, 21 May 2014 02:37:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WmwPi-0001fM-Sw for pgsql-bugs@postgresql.org; Wed, 21 May 2014 02:37:55 +0000 Received: from mail12.ics.ntts.co.jp ([210.232.35.65]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WmwPg-000060-C8 for pgsql-bugs@postgresql.org; Wed, 21 May 2014 02:37:54 +0000 Received: from sadoku34.silk.ntts.co.jp (sadoku34 [10.7.18.34]) by mail12.ics.ntts.co.jp (8.14.4/8.14.4/NTTSOFT) with ESMTP id s4L2bnY5020586; Wed, 21 May 2014 11:37:49 +0900 (JST) Received: (from root@localhost) by sadoku34.silk.ntts.co.jp (8.13.8/NTTSOFT) id s4L2bn2l022236; Wed, 21 May 2014 11:37:49 +0900 (JST) Received: from ccmds32.silk.ntts.co.jp [10.107.0.32] by sadoku34.silk.ntts.co.jp with SMTP id MAA22235; Wed, 21 May 2014 11:37:49 +0900 Received: from mail147.silk.ntts.co.jp (ccmds32.silk.ntts.co.jp [127.0.0.1]) by ccmds32.silk.ntts.co.jp (8.14.3/8.14.3) with ESMTP id s4L2bmNU026257; Wed, 21 May 2014 11:37:48 +0900 Received: from mail147.silk.ntts.co.jp (localhost.localdomain [127.0.0.1]) by mail147.silk.ntts.co.jp (8.14.5/8.14.5/NTTSOFT) with ESMTP id s4L2bjKp007666; Wed, 21 May 2014 11:37:45 +0900 Received: from ccmds32 (mail145.silk.ntts.co.jp [10.107.0.145]) by mail147.silk.ntts.co.jp (8.14.5/8.14.5/NTTSOFT) with SMTP id s4L2bjNx007663; Wed, 21 May 2014 11:37:45 +0900 Message-ID: <537C1161.40809@po.ntts.co.jp> Date: Wed, 21 May 2014 11:37:21 +0900 From: Tomonari Katsumata User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Tom Lane , pgsql-bugs@postgresql.org Subject: Re: BUG #10404: auto_explain for EXPLAIN ANLYZE. References: <20140520074209.20346.37609@wrigleys.postgresql.org> <11712.1400586687@sss.pgh.pa.us> In-Reply-To: <11712.1400586687@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------040004060708020904040904" X-CC-Mail-RelayStamp: CC-Mail-V4.3-Client X-CC-Mail-RelayStamp: CC-Mail-V4.3-Server X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------040004060708020904040904 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit 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 --------------040004060708020904040904 Content-Type: text/x-patch; name="fix-auto_explain-explain-analyze-timing-off.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-auto_explain-explain-analyze-timing-off.patch" diff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.c index 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; --------------040004060708020904040904 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------040004060708020904040904--