Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id AF3EF64FD10 for ; Fri, 18 Jul 2008 17:42:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 75254-03 for ; Fri, 18 Jul 2008 17:42:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4A0F16500D5 for ; Fri, 18 Jul 2008 17:42:56 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m6IKgaIt009776; Fri, 18 Jul 2008 16:42:37 -0400 (EDT) To: ITAGAKI Takahiro cc: Simon Riggs , pgsql-hackers@postgresql.org Subject: Re: [PATCHES] WIP: executor_hook for pg_stat_statements In-reply-to: <20080716104154.7860.52131E4D@oss.ntt.co.jp> References: <20080715150758.3016.52131E4D@oss.ntt.co.jp> <19450.1216133815@sss.pgh.pa.us> <20080716104154.7860.52131E4D@oss.ntt.co.jp> Comments: In-reply-to ITAGAKI Takahiro message dated "Wed, 16 Jul 2008 11:49:13 +0900" Date: Fri, 18 Jul 2008 16:42:36 -0400 Message-ID: <9775.1216413756@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.072 tagged_above=0 required=5 tests=AWL=0.072 X-Spam-Level: X-Archive-Number: 200807/880 X-Sequence-Number: 121140 ITAGAKI Takahiro writes: > The attached patch is the proposal. It adds two global symbols: > * ExecutorRun_hook - replacing behavior of ExecutorRun() > * standard_ExecutorRun() - default behavior of ExecutorRun() Applied. > And also modifies one funtion: > * ExecuteQuery() - It passes prepared query's text to portal so that > the prepared query's text is available at the executor level. > This change is almost free because it copys only string pointer, > not the string buffer. This patch is unsafe because the portal could outlive the cached plan source (consider the case that a called function does a DEALLOCATE). However, I don't see any compelling argument against doing a pstrdup here. I did that and also went around and made assumptions uniform about always having a source string for a cached plan or Portal. So ActivePortal->sourceText should be a safe thing to consult to see the source text of the most closely nested query being executed. (Inside a plpgsql function, for instance, this would be the current SQL statement of the function.) > The attached archive pg_stat_statements.tar.gz is a demonstration of > ExecutorRun_hook. It collect per-statement statistics of number of planned > and executed, plan cost, execution time, and buffer gets/reads/writes. I don't think this works yet --- you are still using debug_query_string, and you're assuming it will be consistent with ActivePortal->sourceText, which it won't be in function calls and other situations. regards, tom lane