Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bDeGL-0005sb-HX for pgsql-committers@arkaria.postgresql.org; Thu, 16 Jun 2016 20:51:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bDeGL-0000vt-47 for pgsql-committers@arkaria.postgresql.org; Thu, 16 Jun 2016 20:51:41 +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 1bDeGK-0000sU-0I for pgsql-committers@postgresql.org; Thu, 16 Jun 2016 20:51:40 +0000 Received: from fr1.2ndquadrant.fr ([94.23.17.124]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bDeGG-0001NL-A9; Thu, 16 Jun 2016 20:51:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by fr1.2ndquadrant.fr (Postfix) with ESMTP id BFD8F6059F; Thu, 16 Jun 2016 22:51:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at fr1.2ndquadrant.fr Received: from fr1.2ndquadrant.fr ([127.0.0.1]) by localhost (fr1.2ndquadrant.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J7O3wbm4Yual; Thu, 16 Jun 2016 22:51:34 +0200 (CEST) Received: from [192.168.0.3] (ath91-3-88-167-161-184.fbx.proxad.net [88.167.161.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: charles) by fr1.2ndquadrant.fr (Postfix) with ESMTPSA id 6D70C6039F; Thu, 16 Jun 2016 22:51:34 +0200 (CEST) Subject: Re: pgsql: Update pg_stat_statements extension for parallel query. To: Robert Haas , pgsql-committers@postgresql.org References: From: Vik Fearing Message-ID: <57631155.8080504@2ndquadrant.fr> Date: Thu, 16 Jun 2016 22:51:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------040305010009080008020404" X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-committers Precedence: bulk Sender: pgsql-committers-owner@postgresql.org This is a multi-part message in MIME format. --------------040305010009080008020404 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 10/06/16 17:01, Robert Haas wrote: > Update pg_stat_statements extension for parallel query. I couldn't readily find a review for this patch, and I am unsatisfied with it. I think it's very strange that a 1.4 version would call a function labeled 1.3, and when we make a 1.5 the code will look really weird because it'll be missing a version. Attached is my attempt to fix this. It might not be the best way to do it, but I feel that *something* should be done. -- Vik Fearing +33 6 46 75 15 36 http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support --------------040305010009080008020404 Content-Type: text/x-patch; name="pss14.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pss14.patch" diff --git a/contrib/pg_stat_statements/pg_stat_statements--1.3--1.4.sql b/contrib/pg_stat_statements/pg_stat_statements--1.3--1.4.sql index ae70c1f..fd54aa8 100644 --- a/contrib/pg_stat_statements/pg_stat_statements--1.3--1.4.sql +++ b/contrib/pg_stat_statements/pg_stat_statements--1.3--1.4.sql @@ -3,5 +3,52 @@ -- complain if script is sourced in psql, rather than via ALTER EXTENSION \echo Use "ALTER EXTENSION pg_stat_statements UPDATE TO '1.4'" to load this file. \quit +/* First we have to remove them from the extension */ +ALTER EXTENSION pg_stat_statements DROP VIEW pg_stat_statements; +ALTER EXTENSION pg_stat_statements DROP FUNCTION pg_stat_statements(boolean); + +/* Then we can drop them */ +DROP VIEW pg_stat_statements; +DROP FUNCTION pg_stat_statements(boolean); + +/* Now redefine */ +CREATE FUNCTION pg_stat_statements(IN showtext boolean, + OUT userid oid, + OUT dbid oid, + OUT queryid bigint, + OUT query text, + OUT calls int8, + OUT total_time float8, + OUT min_time float8, + OUT max_time float8, + OUT mean_time float8, + OUT stddev_time float8, + OUT rows int8, + OUT shared_blks_hit int8, + OUT shared_blks_read int8, + OUT shared_blks_dirtied int8, + OUT shared_blks_written int8, + OUT local_blks_hit int8, + OUT local_blks_read int8, + OUT local_blks_dirtied int8, + OUT local_blks_written int8, + OUT temp_blks_read int8, + OUT temp_blks_written int8, + OUT blk_read_time float8, + OUT blk_write_time float8 +) +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'pg_stat_statements_1_4' +LANGUAGE C STRICT VOLATILE PARALLEL SAFE; + +CREATE VIEW pg_stat_statements AS + SELECT * FROM pg_stat_statements(true); + +GRANT SELECT ON pg_stat_statements TO PUBLIC; + +/* + * Given the general prohibition against write operations in parallel queries, + * it is perhaps a bit surprising that pg_stat_statements_reset() is parallel + * safe. But since it only modifies shared memory, not the database, it's OK. + */ ALTER FUNCTION pg_stat_statements_reset() PARALLEL SAFE; -ALTER FUNCTION pg_stat_statements(boolean) PARALLEL SAFE; diff --git a/contrib/pg_stat_statements/pg_stat_statements--1.4.sql b/contrib/pg_stat_statements/pg_stat_statements--1.4.sql index 58cdf60..86bfb6b 100644 --- a/contrib/pg_stat_statements/pg_stat_statements--1.4.sql +++ b/contrib/pg_stat_statements/pg_stat_statements--1.4.sql @@ -35,7 +35,7 @@ CREATE FUNCTION pg_stat_statements(IN showtext boolean, OUT blk_write_time float8 ) RETURNS SETOF record -AS 'MODULE_PATHNAME', 'pg_stat_statements_1_3' +AS 'MODULE_PATHNAME', 'pg_stat_statements_1_4' LANGUAGE C STRICT VOLATILE PARALLEL SAFE; -- Register a view on the function for ease of use. diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 3d9b8e4..552ffb8 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -117,7 +117,8 @@ typedef enum pgssVersion PGSS_V1_0 = 0, PGSS_V1_1, PGSS_V1_2, - PGSS_V1_3 + PGSS_V1_3, + PGSS_V1_4 } pgssVersion; /* @@ -281,6 +282,7 @@ void _PG_fini(void); PG_FUNCTION_INFO_V1(pg_stat_statements_reset); PG_FUNCTION_INFO_V1(pg_stat_statements_1_2); PG_FUNCTION_INFO_V1(pg_stat_statements_1_3); +PG_FUNCTION_INFO_V1(pg_stat_statements_1_4); PG_FUNCTION_INFO_V1(pg_stat_statements); static void pgss_shmem_startup(void); @@ -1282,6 +1284,7 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS) #define PG_STAT_STATEMENTS_COLS_V1_1 18 #define PG_STAT_STATEMENTS_COLS_V1_2 19 #define PG_STAT_STATEMENTS_COLS_V1_3 23 +#define PG_STAT_STATEMENTS_COLS_V1_4 23 /* only parallel safety was changed */ #define PG_STAT_STATEMENTS_COLS 23 /* maximum of above */ /* @@ -1295,6 +1298,16 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS) * function. Unfortunately we weren't bright enough to do that for 1.1. */ Datum +pg_stat_statements_1_4(PG_FUNCTION_ARGS) +{ + bool showtext = PG_GETARG_BOOL(0); + + pg_stat_statements_internal(fcinfo, PGSS_V1_4, showtext); + + return (Datum) 0; +} + +Datum pg_stat_statements_1_3(PG_FUNCTION_ARGS) { bool showtext = PG_GETARG_BOOL(0); @@ -1393,8 +1406,9 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, if (api_version != PGSS_V1_2) elog(ERROR, "incorrect number of output arguments"); break; - case PG_STAT_STATEMENTS_COLS_V1_3: - if (api_version != PGSS_V1_3) + case PG_STAT_STATEMENTS_COLS_V1_3 || PG_STAT_STATEMENTS_COLS_V1_4: + /* version 1.4 only changed parallel safety */ + if ((api_version != PGSS_V1_3) || (api_version != PGSS_V1_4)) elog(ERROR, "incorrect number of output arguments"); break; default: @@ -1598,6 +1612,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo, api_version == PGSS_V1_1 ? PG_STAT_STATEMENTS_COLS_V1_1 : api_version == PGSS_V1_2 ? PG_STAT_STATEMENTS_COLS_V1_2 : api_version == PGSS_V1_3 ? PG_STAT_STATEMENTS_COLS_V1_3 : + api_version == PGSS_V1_4 ? PG_STAT_STATEMENTS_COLS_V1_4 : -1 /* fail if you forget to update this assert */ )); tuplestore_putvalues(tupstore, tupdesc, values, nulls); --------------040305010009080008020404 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers --------------040305010009080008020404--