Skip to content

Commit 850f4b4

Browse files
committed
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/631e3084-c5d9-8463-7540-fcff4674caa5@gmail.com
1 parent 6eefe2c commit 850f4b4

File tree

1 file changed

+29
-97
lines changed

1 file changed

+29
-97
lines changed

src/backend/utils/adt/pgstatfuncs.c

+29-97
Original file line numberDiff line numberDiff line change
@@ -1498,50 +1498,42 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
14981498
return (Datum) 0;
14991499
}
15001500

1501-
Datum
1502-
pg_stat_get_xact_numscans(PG_FUNCTION_ARGS)
1503-
{
1504-
Oid relid = PG_GETARG_OID(0);
1505-
int64 result;
1506-
PgStat_TableStatus *tabentry;
1507-
1508-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1509-
result = 0;
1510-
else
1511-
result = (int64) (tabentry->counts.numscans);
1512-
1513-
PG_RETURN_INT64(result);
1501+
#define PG_STAT_GET_XACT_RELENTRY_INT64(stat) \
1502+
Datum \
1503+
CppConcat(pg_stat_get_xact_,stat)(PG_FUNCTION_ARGS) \
1504+
{ \
1505+
Oid relid = PG_GETARG_OID(0); \
1506+
int64 result; \
1507+
PgStat_TableStatus *tabentry; \
1508+
\
1509+
if ((tabentry = find_tabstat_entry(relid)) == NULL) \
1510+
result = 0; \
1511+
else \
1512+
result = (int64) (tabentry->counts.stat); \
1513+
\
1514+
PG_RETURN_INT64(result); \
15141515
}
15151516

1516-
Datum
1517-
pg_stat_get_xact_tuples_returned(PG_FUNCTION_ARGS)
1518-
{
1519-
Oid relid = PG_GETARG_OID(0);
1520-
int64 result;
1521-
PgStat_TableStatus *tabentry;
1517+
/* pg_stat_get_xact_numscans */
1518+
PG_STAT_GET_XACT_RELENTRY_INT64(numscans)
15221519

1523-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1524-
result = 0;
1525-
else
1526-
result = (int64) (tabentry->counts.tuples_returned);
1520+
/* pg_stat_get_xact_tuples_returned */
1521+
PG_STAT_GET_XACT_RELENTRY_INT64(tuples_returned)
15271522

1528-
PG_RETURN_INT64(result);
1529-
}
1523+
/* pg_stat_get_xact_tuples_fetched */
1524+
PG_STAT_GET_XACT_RELENTRY_INT64(tuples_fetched)
15301525

1531-
Datum
1532-
pg_stat_get_xact_tuples_fetched(PG_FUNCTION_ARGS)
1533-
{
1534-
Oid relid = PG_GETARG_OID(0);
1535-
int64 result;
1536-
PgStat_TableStatus *tabentry;
1526+
/* pg_stat_get_xact_tuples_hot_updated */
1527+
PG_STAT_GET_XACT_RELENTRY_INT64(tuples_hot_updated)
15371528

1538-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1539-
result = 0;
1540-
else
1541-
result = (int64) (tabentry->counts.tuples_fetched);
1529+
/* pg_stat_get_xact_tuples_newpage_updated */
1530+
PG_STAT_GET_XACT_RELENTRY_INT64(tuples_newpage_updated)
15421531

1543-
PG_RETURN_INT64(result);
1544-
}
1532+
/* pg_stat_get_xact_blocks_fetched */
1533+
PG_STAT_GET_XACT_RELENTRY_INT64(blocks_fetched)
1534+
1535+
/* pg_stat_get_xact_blocks_hit */
1536+
PG_STAT_GET_XACT_RELENTRY_INT64(blocks_hit)
15451537

15461538
Datum
15471539
pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS)
@@ -1606,66 +1598,6 @@ pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS)
16061598
PG_RETURN_INT64(result);
16071599
}
16081600

1609-
Datum
1610-
pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS)
1611-
{
1612-
Oid relid = PG_GETARG_OID(0);
1613-
int64 result;
1614-
PgStat_TableStatus *tabentry;
1615-
1616-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1617-
result = 0;
1618-
else
1619-
result = (int64) (tabentry->counts.tuples_hot_updated);
1620-
1621-
PG_RETURN_INT64(result);
1622-
}
1623-
1624-
Datum
1625-
pg_stat_get_xact_tuples_newpage_updated(PG_FUNCTION_ARGS)
1626-
{
1627-
Oid relid = PG_GETARG_OID(0);
1628-
int64 result;
1629-
PgStat_TableStatus *tabentry;
1630-
1631-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1632-
result = 0;
1633-
else
1634-
result = (int64) (tabentry->counts.tuples_newpage_updated);
1635-
1636-
PG_RETURN_INT64(result);
1637-
}
1638-
1639-
Datum
1640-
pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS)
1641-
{
1642-
Oid relid = PG_GETARG_OID(0);
1643-
int64 result;
1644-
PgStat_TableStatus *tabentry;
1645-
1646-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1647-
result = 0;
1648-
else
1649-
result = (int64) (tabentry->counts.blocks_fetched);
1650-
1651-
PG_RETURN_INT64(result);
1652-
}
1653-
1654-
Datum
1655-
pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS)
1656-
{
1657-
Oid relid = PG_GETARG_OID(0);
1658-
int64 result;
1659-
PgStat_TableStatus *tabentry;
1660-
1661-
if ((tabentry = find_tabstat_entry(relid)) == NULL)
1662-
result = 0;
1663-
else
1664-
result = (int64) (tabentry->counts.blocks_hit);
1665-
1666-
PG_RETURN_INT64(result);
1667-
}
1668-
16691601
Datum
16701602
pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
16711603
{

0 commit comments

Comments
 (0)