OSDN Git Service

Add new columns to pg_store_plans view master 1.7
authorKyotaro Horiguchi <horikyota.ntt@gmail.com>
Wed, 14 Dec 2022 06:52:34 +0000 (15:52 +0900)
committerKyotaro Horiguchi <horikyota.ntt@gmail.com>
Wed, 14 Dec 2022 06:57:55 +0000 (15:57 +0900)
Likewise pg_stat_statements, add temp_blk_read_time and
temp_blk_write_time to pg_store_plans view.
Version is changed to 1.7.

Makefile
SPECS/pg_store_plans15.spec [moved from SPECS/pg_store_plans14.spec with 76% similarity]
docs/index.html
pg_store_plans--1.6--1.6.1.sql [deleted file]
pg_store_plans--1.7.sql [moved from pg_store_plans--1.6.sql with 94% similarity]
pg_store_plans.c
pg_store_plans.control

index c429cab..ace7fe6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 # pg_stat_plan/Makefile
 
 MODULES = pg_store_plans
-STOREPLANSVER = 1.6.1
+STOREPLANSVER = 1.7
 
 MODULE_big = pg_store_plans
 OBJS = pg_store_plans.o pgsp_json.o pgsp_json_text.o pgsp_explain.o
@@ -10,7 +10,7 @@ EXTENSION = pg_store_plans
 
 PG_VERSION := $(shell pg_config --version | sed "s/^PostgreSQL //" | sed "s/\.[0-9]*$$//")
 
-DATA = pg_store_plans--1.6.sql pg_store_plans--1.6--1.6.1.sql
+DATA = pg_store_plans--1.7.sql
 
 REGRESS = convert store
 REGRESS_OPTS = --temp-config=regress.conf
@@ -25,8 +25,8 @@ include $(top_builddir)/src/Makefile.global
 include $(top_srcdir)/contrib/contrib-global.mk
 endif
 
-STARBALL14 = pg_store_plans14-$(STOREPLANSVER).tar.gz
-STARBALLS = $(STARBALL14)
+STARBALL15 = pg_store_plans15-$(STOREPLANSVER).tar.gz
+STARBALLS = $(STARBALL15)
 
 TARSOURCES = Makefile *.c  *.h \
        pg_store_plans--*.sql \
@@ -40,7 +40,7 @@ endif
 ## These entries need running server
 DBNAME = postgres
 
-rpms: rpm14
+rpms: rpm15
 
 $(STARBALLS): $(TARSOURCES)
        if [ -h $(subst .tar.gz,,$@) ]; then rm $(subst .tar.gz,,$@); fi
@@ -52,8 +52,8 @@ $(STARBALLS): $(TARSOURCES)
        tar -chzf $@ $(addprefix $(subst .tar.gz,,$@)/, $^)
        rm $(subst .tar.gz,,$@)
 
-rpm14: $(STARBALL14)
-       MAKE_ROOT=`pwd` rpmbuild -bb SPECS/pg_store_plans14.spec
+rpm15: $(STARBALL15)
+       MAKE_ROOT=`pwd` rpmbuild -bb SPECS/pg_store_plans15.spec
 
 testfiles: convert.out convert.sql
 
similarity index 76%
rename from SPECS/pg_store_plans14.spec
rename to SPECS/pg_store_plans15.spec
index 651b5f9..243a35d 100644 (file)
@@ -1,7 +1,7 @@
 # SPEC file for pg_store_plans
-# Copyright(c) 2021, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+# Copyright(c) 2022, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
 
-%define _pgdir   /usr/pgsql-14
+%define _pgdir   /usr/pgsql-15
 %define _bindir  %{_pgdir}/bin
 %define _libdir  %{_pgdir}/lib
 %define _datadir %{_pgdir}/share
@@ -14,9 +14,9 @@
 %endif
 
 ## Set general information for pg_store_plans.
-Summary:    Record executed plans on PostgreSQL 14
-Name:       pg_store_plans14
-Version:    1.6.1
+Summary:    Record executed plans on PostgreSQL 15
+Name:       pg_store_plans15
+Version:    1.7
 Release:    1%{?dist}
 License:    BSD
 Group:      Applications/Databases
@@ -26,8 +26,8 @@ BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
 Vendor:     NIPPON TELEGRAPH AND TELEPHONE CORPORATION
 
 ## We use postgresql-devel package
-BuildRequires:  postgresql14-devel
-Requires:  postgresql14-libs
+BuildRequires:  postgresql15-devel
+Requires:  postgresql15-libs
 
 ## Description for "pg_store_plans"
 %description
@@ -35,19 +35,19 @@ Requires:  postgresql14-libs
 pg_store_plans provides capability to record statistics for every plan
 executed on PostgreSQL.
 
-Note that this package is available for only PostgreSQL 14.
+Note that this package is available for only PostgreSQL 15.
 
 %package llvmjit
-Requires: postgresql14-server, postgresql14-llvmjit
-Requires: pg_store_plans14 = 1.6.1
-Summary:  Just-in-time compilation support for pg_store_plans14
+Requires: postgresql15-server, postgresql15-llvmjit
+Requires: pg_store_plans15 = 1.7
+Summary:  Just-in-time compilation support for pg_store_plans15
 
 %description llvmjit
-Just-in-time compilation support for pg_store_plans14
+Just-in-time compilation support for pg_store_plans15
 
 ## pre work for build pg_store_plans
 %prep
-PATH=/usr/pgsql-14/bin:$PATH
+PATH=/usr/pgsql-15/bin:$PATH
 if [ "${MAKE_ROOT}" != "" ]; then
   pushd ${MAKE_ROOT}
   make clean %{name}-%{version}.tar.gz
@@ -58,14 +58,14 @@ if [ ! -d %{_rpmdir} ]; then mkdir -p %{_rpmdir}; fi
 
 ## Set variables for build environment
 %build
-PATH=/usr/pgsql-14/bin:$PATH
+PATH=/usr/pgsql-15/bin:$PATH
 pg_config
 make USE_PGXS=1 %{?_smp_mflags}
 
 ## Set variables for install
 %install
 rm -rf %{buildroot}
-PATH=/usr/pgsql-14/bin:$PATH
+PATH=/usr/pgsql-15/bin:$PATH
 make install DESTDIR=%{buildroot}
 
 %clean
@@ -75,8 +75,7 @@ rm -rf %{buildroot}
 %defattr(0755,root,root)
 %{_libdir}/pg_store_plans.so
 %defattr(0644,root,root)
-%{_datadir}/extension/pg_store_plans--1.6.sql
-%{_datadir}/extension/pg_store_plans--1.6--1.6.1.sql
+%{_datadir}/extension/pg_store_plans--1.7.sql
 %{_datadir}/extension/pg_store_plans.control
 
 %files llvmjit
@@ -86,6 +85,8 @@ rm -rf %{buildroot}
 
 # History of pg_store_plans.
 %changelog
+* Wed Dec 14 2022 Kyotaro Horiguchi
+- Version 1.7. Support PostgreSQL 15.
 * Thu Feb 03 2022 Kyotaro Horiguchi
 - Version 1.6.1.
 * Mon Jan 17 2022 Tatsuro Yamada, Julien Rouhaud, Kyotaro Horiguchi
index 7abf25f..afed0fa 100644 (file)
@@ -168,6 +168,18 @@ View</H2>
 
     <TD>Total time the statement using the plan spent writing blocks, in milliseconds (if <A HREF="http://www.postgresql.org/docs/current/static/runtime-config-statistics.html#GUC-TRACK-IO-TIMING">track_io_timing</A> is enabled, otherwise zero)</TD>
     </TR>
+<TR><TD><TT CLASS="STRUCTFIELD">temp_blk_read_time</TT></TD>
+    <TD><TT CLASS="TYPE">double precision</TT></TD>
+    <TD>&nbsp;</TD>
+
+    <TD>Total time the statement using the plan spent reading temporary file blocks, in milliseconds (if <A HREF="http://www.postgresql.org/docs/current/static/runtime-config-statistics.html#GUC-TRACK-IO-TIMING">track_io_timing</A> is enabled, otherwise zero)</TD>
+    </TR>
+<TR><TD><TT CLASS="STRUCTFIELD">temp_blk_write_time</TT></TD>
+    <TD><TT CLASS="TYPE">double precision</TT></TD>
+    <TD>&nbsp;</TD>
+
+    <TD>Total time the statement using the plan spent writing temporary file blocks, in milliseconds (if <A HREF="http://www.postgresql.org/docs/current/static/runtime-config-statistics.html#GUC-TRACK-IO-TIMING">track_io_timing</A> is enabled, otherwise zero)</TD>
+    </TR>
 <TR><TD><TT CLASS="STRUCTFIELD">first_call</TT></TD>
     <TD><TT CLASS="TYPE">timestamp with time zone</TT></TD>
     <TD>&nbsp;</TD>
diff --git a/pg_store_plans--1.6--1.6.1.sql b/pg_store_plans--1.6--1.6.1.sql
deleted file mode 100644 (file)
index e7ad3c3..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/* pg_store_plans/pg_store_plans--1.6--1.6.1.sql */
-
--- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION pg_store_plans" to load this file. \quit
similarity index 94%
rename from pg_store_plans--1.6.sql
rename to pg_store_plans--1.7.sql
index 5164d17..8d3a612 100644 (file)
@@ -1,4 +1,4 @@
-/* pg_store_plans/pg_store_plans--1.6.sql */
+/* pg_store_plans/pg_store_plans--1.7.sql */
 
 -- complain if script is sourced in psql, rather than via CREATE EXTENSION
 \echo Use "CREATE EXTENSION pg_store_plans" to load this file. \quit
@@ -82,11 +82,13 @@ CREATE FUNCTION pg_store_plans(
     OUT temp_blks_written int8,
     OUT blk_read_time float8,
     OUT blk_write_time float8,
+    OUT temp_blk_read_time float8,
+    OUT temp_blk_write_time float8,
     OUT first_call timestamptz,
     OUT last_call timestamptz
 )
 RETURNS SETOF record
-AS 'MODULE_PATHNAME', 'pg_store_plans_1_6'
+AS 'MODULE_PATHNAME', 'pg_store_plans_1_7'
 LANGUAGE C
 VOLATILE PARALLEL SAFE;
 
index acbc21b..ce74468 100644 (file)
@@ -71,7 +71,7 @@ PG_MODULE_MAGIC;
 static const uint32 PGSP_PG_MAJOR_VERSION = PG_VERSION_NUM / 100;
 
 /* This constant defines the magic number in the stats file header */
-static const uint32 PGSP_FILE_HEADER = 0x20211125;
+static const uint32 PGSP_FILE_HEADER = 0x20221214;
 static int max_plan_len = 5000;
 
 /* XXX: Should USAGE_EXEC reflect execution time and/or buffer usage? */
@@ -98,7 +98,8 @@ typedef uint32 queryid_t;
 typedef enum pgspVersion
 {
        PGSP_V1_5 = 0,
-       PGSP_V1_6
+       PGSP_V1_6,
+       PGSP_V1_7
 } pgspVersion;
 
 /*
@@ -141,6 +142,10 @@ typedef struct Counters
        int64           temp_blks_written;      /* # of temp blocks written */
        double          blk_read_time;          /* time spent reading, in msec */
        double          blk_write_time;         /* time spent writing, in msec */
+       double          temp_blk_read_time;     /* time spent reading temp blocks,
+                                                                          in msec */
+       double          temp_blk_write_time;/* time spent writing temp blocks,
+                                                                          in msec */
        TimestampTz     first_call;                     /* timestamp of first call  */
        TimestampTz     last_call;                      /* timestamp of last call  */
        double          usage;                          /* usage factor */
@@ -313,6 +318,7 @@ PG_FUNCTION_INFO_V1(pg_store_plans_reset);
 PG_FUNCTION_INFO_V1(pg_store_plans_hash_query);
 PG_FUNCTION_INFO_V1(pg_store_plans);
 PG_FUNCTION_INFO_V1(pg_store_plans_1_6);
+PG_FUNCTION_INFO_V1(pg_store_plans_1_7);
 PG_FUNCTION_INFO_V1(pg_store_plans_shorten);
 PG_FUNCTION_INFO_V1(pg_store_plans_normalize);
 PG_FUNCTION_INFO_V1(pg_store_plans_jsonplan);
@@ -386,7 +392,6 @@ _PG_init(void)
         */
        if (!process_shared_preload_libraries_in_progress)
                return;
-
 #if PG_VERSION_NUM >= 140000
        /*
         * Inform the postmaster that we want to enable query_id calculation if
@@ -1348,8 +1353,12 @@ pgsp_store(char *plan, queryid_t queryId,
        e->counters.local_blks_written += bufusage->local_blks_written;
        e->counters.temp_blks_read += bufusage->temp_blks_read;
        e->counters.temp_blks_written += bufusage->temp_blks_written;
+
        e->counters.blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time);
        e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time);
+       e->counters.temp_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_read_time);
+       e->counters.temp_blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_write_time);
+
        e->counters.last_call = GetCurrentTimestamp();
        e->counters.usage += USAGE_EXEC(total_time);
 
@@ -1380,12 +1389,21 @@ pg_store_plans_reset(PG_FUNCTION_ARGS)
 /* Number of output arguments (columns) for various API versions */
 #define PG_STORE_PLANS_COLS_V1_5       27
 #define PG_STORE_PLANS_COLS_V1_6       26
-#define PG_STORE_PLANS_COLS                    27      /* maximum of above */
+#define PG_STORE_PLANS_COLS_V1_7       28
+#define PG_STORE_PLANS_COLS                    28      /* maximum of above */
 
 /*
  * Retrieve statement statistics.
  */
 Datum
+pg_store_plans_1_7(PG_FUNCTION_ARGS)
+{
+       pg_store_plans_internal(fcinfo, PGSP_V1_7);
+
+       return (Datum) 0;
+}
+
+Datum
 pg_store_plans_1_6(PG_FUNCTION_ARGS)
 {
        pg_store_plans_internal(fcinfo, PGSP_V1_6);
@@ -1637,11 +1655,19 @@ pg_store_plans_internal(FunctionCallInfo fcinfo,
                values[i++] = Int64GetDatumFast(tmp.temp_blks_written);
                values[i++] = Float8GetDatumFast(tmp.blk_read_time);
                values[i++] = Float8GetDatumFast(tmp.blk_write_time);
+
+               if (api_version >= PGSP_V1_7)
+               {
+                       values[i++] = Float8GetDatumFast(tmp.temp_blk_read_time);
+                       values[i++] = Float8GetDatumFast(tmp.temp_blk_write_time);
+               }
+
                values[i++] = TimestampTzGetDatum(tmp.first_call);
                values[i++] = TimestampTzGetDatum(tmp.last_call);
 
                Assert(i == (api_version == PGSP_V1_5 ? PG_STORE_PLANS_COLS_V1_5 :
                                         api_version == PGSP_V1_6 ? PG_STORE_PLANS_COLS_V1_6 :
+                                        api_version == PGSP_V1_7 ? PG_STORE_PLANS_COLS_V1_7 :
                                         -1 /* fail if you forget to update this assert */ ));
 
                tuplestore_putvalues(tupstore, tupdesc, values, nulls);
index b150227..2d2bf85 100644 (file)
@@ -1,5 +1,5 @@
 # pg_store_plans extension
 comment = 'track plan statistics of all SQL statements executed'
-default_version = '1.6.1'
+default_version = '1.7'
 module_pathname = '$libdir/pg_store_plans'
 relocatable = true