2020-11-27 21:37 に Seino Yuki さんは書きました:
2020-11-16 12:28 に Seino Yuki さんは書きました:
Due to similar fixed, we have also merged the patches discussed in the
following thread.
https://commitfest.postgresql.org/30/2736/
The patch is posted on the 2736 side of the thread.
Regards.
I forgot the attachment and will resend it.
The following patches have been committed and we have created a
compliant patch for them.
https://commitfest.postgresql.org/30/2736/
Please confirm.
Regards.
diff --git a/contrib/pg_stat_statements/pg_stat_statements--1.8--1.9.sql b/contrib/pg_stat_statements/pg_stat_statements--1.8--1.9.sql
index 2019a4ffe0..21a4b6c36f 100644
--- a/contrib/pg_stat_statements/pg_stat_statements--1.8--1.9.sql
+++ b/contrib/pg_stat_statements/pg_stat_statements--1.8--1.9.sql
@@ -5,9 +5,10 @@
--- Define pg_stat_statements_info
CREATE FUNCTION pg_stat_statements_info(
- OUT dealloc bigint
+ OUT dealloc bigint,
+ OUT reset_exec_time TIMESTAMP WITH TIME ZONE
)
-RETURNS bigint
+RETURNS record
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 70cfdb2c9d..fd90aab471 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -81,6 +81,7 @@
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
+#include "utils/timestamp.h"
PG_MODULE_MAGIC;
@@ -199,6 +200,8 @@ typedef struct Counters
typedef struct pgssGlobalStats
{
int64 dealloc; /* # of times entries were deallocated */
+ TimestampTz reset_exec_time; /* timestamp with all stats reset */
+ bool reset_exec_time_isnull; /* if true last_dealloc is null */
} pgssGlobalStats;
/*
@@ -565,6 +568,8 @@ pgss_shmem_startup(void)
pgss->n_writers = 0;
pgss->gc_count = 0;
pgss->stats.dealloc = 0;
+ pgss->stats.reset_exec_time = 0;
+ pgss->stats.reset_exec_time_isnull = true;
}
memset(&info, 0, sizeof(info));
@@ -1510,6 +1515,7 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
#define PG_STAT_STATEMENTS_COLS_V1_3 23
#define PG_STAT_STATEMENTS_COLS_V1_8 32
#define PG_STAT_STATEMENTS_COLS 32 /* maximum of above */
+#define PG_STAT_STATEMENTS_INFO_COLS 2
/*
* Retrieve statement statistics.
@@ -1889,7 +1895,17 @@ Datum
pg_stat_statements_info(PG_FUNCTION_ARGS)
{
pgssGlobalStats stats;
+ TupleDesc tupdesc;
+ HeapTuple result_tuple;
+ Datum values[PG_STAT_STATEMENTS_INFO_COLS];
+ bool nulls[PG_STAT_STATEMENTS_INFO_COLS];
+
+ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+ elog(ERROR, "return type must be a row type");
+
+ tupdesc = BlessTupleDesc(tupdesc);
+ memset(nulls, 0, sizeof(nulls));
/* Read global statistics for pg_stat_statements */
{
volatile pgssSharedState *s = (volatile pgssSharedState *) pgss;
@@ -1899,7 +1915,17 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
SpinLockRelease(&s->mutex);
}
- PG_RETURN_INT64(stats.dealloc);
+ /* Read dealloc */
+ values[0] = stats.dealloc;
+
+ /* Read reset_exec_time */
+ if (!stats.reset_exec_time_isnull)
+ values[1] = stats.reset_exec_time;
+ else
+ nulls[1] = true;
+
+ result_tuple = heap_form_tuple(tupdesc, values, nulls);
+ return HeapTupleGetDatum(result_tuple);
}
/*
@@ -2507,6 +2533,9 @@ entry_reset(Oid userid, Oid dbid, uint64 queryid)
long num_entries;
long num_remove = 0;
pgssHashKey key;
+ TimestampTz reset_ts;
+
+ reset_ts = GetCurrentTimestamp();
if (!pgss || !pgss_hash)
ereport(ERROR,
@@ -2559,6 +2588,8 @@ entry_reset(Oid userid, Oid dbid, uint64 queryid)
SpinLockAcquire(&s->mutex);
s->stats.dealloc = 0;
+ s->stats.reset_exec_time = reset_ts; /* reset execution time */
+ s->stats.reset_exec_time_isnull = false;
SpinLockRelease(&s->mutex);
}
}
diff --git a/doc/src/sgml/pgstatstatements.sgml b/doc/src/sgml/pgstatstatements.sgml
index 81915ea69b..821ae1f96e 100644
--- a/doc/src/sgml/pgstatstatements.sgml
+++ b/doc/src/sgml/pgstatstatements.sgml
@@ -523,6 +523,15 @@
<varname>pg_stat_statements.max</varname> were observed
</para></entry>
</row>
+ <row>
+ <entry role="catalog_table_entry"><para role="column_definition">
+ <structfield>reset_exec_time</structfield> <type>timestamp with time zone</type>
+ </para>
+ <para>
+ Shows the time at which <function>pg_stat_statements_reset(0,0,0)</function> was last called.
+ </para></entry>
+ </row>
+
</tbody>
</tgroup>
</table>