summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2023-03-27 00:57:41 +0000
committerMichael Paquier2023-03-27 00:57:41 +0000
commit850f4b4c8cab03a084ccc89245df061639ad1769 (patch)
treebf45012c236d3032a5d5b84fc71fe94bc6873a3e
parent6eefe2ce463f55bb3b8da7d561ad2f75053189e0 (diff)
Generate pg_stat_get_xact*() functions for relations using macros
This change replaces seven functions definitions by macros. This is the same idea as 8018ffb or 83a1a1b, taking advantage of the variable rename done in 8089517 for relation entries. Author: Bertrand Drouvot Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c126
1 files changed, 29 insertions, 97 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index c7ba86b3dc..e1dd1e0ad3 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -1498,50 +1498,42 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
return (Datum) 0;
}
-Datum
-pg_stat_get_xact_numscans(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
-
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.numscans);
-
- PG_RETURN_INT64(result);
+#define PG_STAT_GET_XACT_RELENTRY_INT64(stat) \
+Datum \
+CppConcat(pg_stat_get_xact_,stat)(PG_FUNCTION_ARGS) \
+{ \
+ Oid relid = PG_GETARG_OID(0); \
+ int64 result; \
+ PgStat_TableStatus *tabentry; \
+ \
+ if ((tabentry = find_tabstat_entry(relid)) == NULL) \
+ result = 0; \
+ else \
+ result = (int64) (tabentry->counts.stat); \
+ \
+ PG_RETURN_INT64(result); \
}
-Datum
-pg_stat_get_xact_tuples_returned(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
+/* pg_stat_get_xact_numscans */
+PG_STAT_GET_XACT_RELENTRY_INT64(numscans)
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.tuples_returned);
+/* pg_stat_get_xact_tuples_returned */
+PG_STAT_GET_XACT_RELENTRY_INT64(tuples_returned)
- PG_RETURN_INT64(result);
-}
+/* pg_stat_get_xact_tuples_fetched */
+PG_STAT_GET_XACT_RELENTRY_INT64(tuples_fetched)
-Datum
-pg_stat_get_xact_tuples_fetched(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
+/* pg_stat_get_xact_tuples_hot_updated */
+PG_STAT_GET_XACT_RELENTRY_INT64(tuples_hot_updated)
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.tuples_fetched);
+/* pg_stat_get_xact_tuples_newpage_updated */
+PG_STAT_GET_XACT_RELENTRY_INT64(tuples_newpage_updated)
- PG_RETURN_INT64(result);
-}
+/* pg_stat_get_xact_blocks_fetched */
+PG_STAT_GET_XACT_RELENTRY_INT64(blocks_fetched)
+
+/* pg_stat_get_xact_blocks_hit */
+PG_STAT_GET_XACT_RELENTRY_INT64(blocks_hit)
Datum
pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS)
@@ -1607,66 +1599,6 @@ pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS)
}
Datum
-pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
-
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.tuples_hot_updated);
-
- PG_RETURN_INT64(result);
-}
-
-Datum
-pg_stat_get_xact_tuples_newpage_updated(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
-
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.tuples_newpage_updated);
-
- PG_RETURN_INT64(result);
-}
-
-Datum
-pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
-
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.blocks_fetched);
-
- PG_RETURN_INT64(result);
-}
-
-Datum
-pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS)
-{
- Oid relid = PG_GETARG_OID(0);
- int64 result;
- PgStat_TableStatus *tabentry;
-
- if ((tabentry = find_tabstat_entry(relid)) == NULL)
- result = 0;
- else
- result = (int64) (tabentry->counts.blocks_hit);
-
- PG_RETURN_INT64(result);
-}
-
-Datum
pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
{
Oid funcid = PG_GETARG_OID(0);