Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bYAxE-0006PT-65 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Aug 2016 11:48:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bYAxD-0004dG-03 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Aug 2016 11:48:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bYAvp-00034X-0s for pgsql-hackers@postgresql.org; Fri, 12 Aug 2016 11:47:21 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bYAvg-0002Cv-KF for pgsql-hackers@postgresql.org; Fri, 12 Aug 2016 11:47:19 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id B371621C2CC5 for ; Fri, 12 Aug 2016 14:47:10 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BVMPJ37_Q_3I for ; Fri, 12 Aug 2016 14:47:10 +0300 (MSK) Received: from [192.168.27.101] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 88BA521C2CC0 for ; Fri, 12 Aug 2016 14:47:10 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1471002430; bh=3S3IScYAoXnIsH5CALtJJ5s6hwzvKfsjCKz5K5BQ4Kw=; h=Subject:References:To:From:Date:In-Reply-To; b=Mv3OAviD9ySS2ot5otRwp/MN/axBdJV1AuEfBfDmUOsWSriQohr38I7l5pYWgoZHb isNRs/DtwoUHpGfTwzyCXUpV+LVK66Ur+2Or/jjmcOQRD6/3AeXM2FqW4kBkXCe3Dh 6MaKRI1z6uCjYKFzqva6Ue8isSrL4bZ3SYDFFuOw= Subject: Fwd: [BUG] Print timing statistics of trigger execution under turned off timing option of EXPLAIN ANALYZE References: <57bd66d9-551f-3191-ff1f-88d554cac3b2@postgrespro.ru> To: pgsql-hackers@postgresql.org From: maksim X-Forwarded-Message-Id: <57bd66d9-551f-3191-ff1f-88d554cac3b2@postgrespro.ru> Message-ID: <081c0540-ecaa-bd29-3fd2-6358f3b359a9@postgrespro.ru> Date: Fri, 12 Aug 2016 14:47:06 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <57bd66d9-551f-3191-ff1f-88d554cac3b2@postgrespro.ru> Content-Type: multipart/mixed; boundary="------------E4A581ED538EAB51FE204C88" X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------E4A581ED538EAB51FE204C88 Content-Type: multipart/alternative; boundary="------------1DC4A7A1DC3B81482260CCA6" --------------1DC4A7A1DC3B81482260CCA6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello, hackers! At this moment EXPLAIN ANALYZE with turned off timing option after execution query that expires trigger prints time of total execution of trigger function: postgres=# EXPLAIN (ANALYZE, timing false) insert INTO foo values(1000001, ''); QUERY PLAN -------------------------------------------------------------------------- Insert on foo (cost=0.00..0.01 rows=1 width=36) (actual rows=0 loops=1) -> Result (cost=0.00..0.01 rows=1 width=36) (actual rows=1 loops=1) Planning time: 0.038 ms Trigger unique_foo_c1:*/time=0.000/* calls=1 Execution time: 340.766 ms (5 rows) My patch fixes this problem. -- Maksim Milyutin Postgres Professional:http://www.postgrespro.com Russian Postgres Company --------------1DC4A7A1DC3B81482260CCA6 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hello, hackers!


At this moment EXPLAIN ANALYZE with turned off timing option after execution query that expires trigger prints time of total execution of trigger function:

postgres=# EXPLAIN (ANALYZE, timing false) insert INTO foo values(1000001, '');
                                QUERY PLAN                               
--------------------------------------------------------------------------
 Insert on foo  (cost=0.00..0.01 rows=1 width=36) (actual rows=0 loops=1)
   ->  Result  (cost=0.00..0.01 rows=1 width=36) (actual rows=1 loops=1)
 Planning time: 0.038 ms
 Trigger unique_foo_c1: time=0.000 calls=1
 Execution time: 340.766 ms
(5 rows)

My patch fixes this problem.

-- 
Maksim Milyutin
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
--------------1DC4A7A1DC3B81482260CCA6-- --------------E4A581ED538EAB51FE204C88 Content-Type: text/x-patch; name="trigger_timing.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="trigger_timing.patch" diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index dbd27e5..808e23e 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -698,8 +698,11 @@ report_triggers(ResultRelInfo *rInfo, bool show_relname, ExplainState *es) appendStringInfo(es->str, " for constraint %s", conname); if (show_relname) appendStringInfo(es->str, " on %s", relname); - appendStringInfo(es->str, ": time=%.3f calls=%.0f\n", - 1000.0 * instr->total, instr->ntuples); + if (es->timing) + appendStringInfo(es->str, ": time=%.3f calls=%.0f\n", + 1000.0 * instr->total, instr->ntuples); + else + appendStringInfo(es->str, ": calls=%.0f\n", instr->ntuples); } else { @@ -707,7 +710,8 @@ report_triggers(ResultRelInfo *rInfo, bool show_relname, ExplainState *es) if (conname) ExplainPropertyText("Constraint Name", conname, es); ExplainPropertyText("Relation", relname, es); - ExplainPropertyFloat("Time", 1000.0 * instr->total, 3, es); + if (es->timing) + ExplainPropertyFloat("Time", 1000.0 * instr->total, 3, es); ExplainPropertyFloat("Calls", instr->ntuples, 0, es); } --------------E4A581ED538EAB51FE204C88 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------E4A581ED538EAB51FE204C88--