($INBOX_DIR/description missing)
help / color / mirror / Atom feedFrom: Andres Freund <[email protected]>
Subject: [PATCH v69 13/28] pgstat: add pg_stat_exists_stat() for easier testing.
Date: Sat, 2 Apr 2022 14:21:58 -0700
Useful for tests.
Author: Melanie Plageman <[email protected]>
---
src/include/catalog/pg_proc.dat | 6 ++++++
src/include/pgstat.h | 2 ++
src/backend/catalog/system_functions.sql | 2 ++
src/backend/postmaster/pgstat.c | 9 +++++++++
src/backend/utils/adt/pgstatfuncs.c | 17 +++++++++++++++++
5 files changed, 36 insertions(+)
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 12526c599e0..948e6504da0 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -5376,6 +5376,12 @@
proargmodes => '{i,o,o,o,o,o,o,o,o,o,o}',
proargnames => '{slot_name,slot_name,spill_txns,spill_count,spill_bytes,stream_txns,stream_count,stream_bytes,total_txns,total_bytes,stats_reset}',
prosrc => 'pg_stat_get_replication_slot' },
+
+{ oid => '8384', descr => 'statistics: check if a stats object exists',
+ proname => 'pg_stat_exists_stat', provolatile => 'v', proparallel => 'r',
+ prorettype => 'bool', proargtypes => 'text oid oid',
+ prosrc => 'pg_stat_exists_stat' },
+
{ oid => '8523', descr => 'statistics: information about subscription stats',
proname => 'pg_stat_get_subscription_stats',
provolatile => 's', proparallel => 'r',
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 8386fb5f10d..79e5a579d03 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -438,6 +438,8 @@ extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot);
/* helpers */
extern PgStat_Kind pgstat_kind_from_str(char *kind_str);
+extern bool pgstat_exists_entry(PgStat_Kind kind, Oid dboid, Oid objoid);
+
/*
* Functions in pgstat_archiver.c
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 81bac6f5812..07386f97f95 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -639,6 +639,8 @@ REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_function_counters(oid) FROM publ
REVOKE EXECUTE ON FUNCTION pg_stat_reset_replication_slot(text) FROM public;
+REVOKE EXECUTE ON FUNCTION pg_stat_exists_stat(text, oid, oid) FROM public;
+
REVOKE EXECUTE ON FUNCTION pg_stat_reset_subscription_stats(oid) FROM public;
REVOKE EXECUTE ON FUNCTION lo_import(text) FROM public;
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index bafbcff1eef..6727dc26db5 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -891,6 +891,15 @@ pgstat_get_stat_snapshot_timestamp(bool *have_snapshot)
return 0;
}
+bool
+pgstat_exists_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
+{
+ if (pgstat_kind_info_for(kind)->fixed_amount)
+ return true;
+
+ return pgstat_get_entry_ref(kind, dboid, objoid, false, NULL) != NULL;
+}
+
/*
* Ensure snapshot for a kind of global stats exist.
*
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index caaf0c5a672..2660bd1eb07 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -2395,3 +2395,20 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
}
+
+/*
+ * Checks for presence of stats for object with provided kind, database oid,
+ * object oid.
+ *
+ * This is useful for regression tests, but not much more.
+ */
+Datum
+pg_stat_exists_stat(PG_FUNCTION_ARGS)
+{
+ char *stats_type = text_to_cstring(PG_GETARG_TEXT_P(0));
+ Oid dboid = PG_GETARG_OID(1);
+ Oid objoid = PG_GETARG_OID(2);
+ PgStat_Kind kind = pgstat_kind_from_str(stats_type);
+
+ PG_RETURN_BOOL(pgstat_exists_entry(kind, dboid, objoid));
+}
--
2.35.1.677.gabf474a5dd
--be3jiks7ge4r32o3
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v69-0014-pgstat-test-transaction-behaviour-2PC-function-s.patch"
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v69 13/28] pgstat: add pg_stat_exists_stat() for easier testing.
In-Reply-To: <no-message-id-1859826@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox