mirror of
https://github.com/postgres/postgres.git
synced 2025-05-21 15:54:08 +03:00
pgstat: introduce pgstat_relation_should_count().
A later commit will make the check more complicated than the current (rel)->pgstat_info != NULL. It also just seems nicer to have a central copy of the logic, even while still simple. Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
This commit is contained in:
parent
2d655a08d5
commit
8363102009
@ -1743,7 +1743,7 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
|
|||||||
tabentry = pgstat_fetch_stat_tabentry(oldIndexId);
|
tabentry = pgstat_fetch_stat_tabentry(oldIndexId);
|
||||||
if (tabentry)
|
if (tabentry)
|
||||||
{
|
{
|
||||||
if (newClassRel->pgstat_info)
|
if (pgstat_relation_should_count(newClassRel))
|
||||||
{
|
{
|
||||||
newClassRel->pgstat_info->t_counts.t_numscans = tabentry->numscans;
|
newClassRel->pgstat_info->t_counts.t_numscans = tabentry->numscans;
|
||||||
newClassRel->pgstat_info->t_counts.t_tuples_returned = tabentry->tuples_returned;
|
newClassRel->pgstat_info->t_counts.t_tuples_returned = tabentry->tuples_returned;
|
||||||
|
@ -1709,7 +1709,7 @@ pgstat_report_analyze(Relation rel,
|
|||||||
*
|
*
|
||||||
* Waste no time on partitioned tables, though.
|
* Waste no time on partitioned tables, though.
|
||||||
*/
|
*/
|
||||||
if (rel->pgstat_info != NULL &&
|
if (pgstat_relation_should_count(rel) &&
|
||||||
rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
|
rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
|
||||||
{
|
{
|
||||||
PgStat_TableXactStatus *trans;
|
PgStat_TableXactStatus *trans;
|
||||||
@ -2359,13 +2359,12 @@ add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
|
|||||||
void
|
void
|
||||||
pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
|
pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
|
||||||
{
|
{
|
||||||
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
if (pgstat_relation_should_count(rel))
|
||||||
|
|
||||||
if (pgstat_info != NULL)
|
|
||||||
{
|
{
|
||||||
/* We have to log the effect at the proper transactional level */
|
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
||||||
int nest_level = GetCurrentTransactionNestLevel();
|
int nest_level = GetCurrentTransactionNestLevel();
|
||||||
|
|
||||||
|
/* We have to log the effect at the proper transactional level */
|
||||||
if (pgstat_info->trans == NULL ||
|
if (pgstat_info->trans == NULL ||
|
||||||
pgstat_info->trans->nest_level != nest_level)
|
pgstat_info->trans->nest_level != nest_level)
|
||||||
add_tabstat_xact_level(pgstat_info, nest_level);
|
add_tabstat_xact_level(pgstat_info, nest_level);
|
||||||
@ -2380,13 +2379,12 @@ pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
|
|||||||
void
|
void
|
||||||
pgstat_count_heap_update(Relation rel, bool hot)
|
pgstat_count_heap_update(Relation rel, bool hot)
|
||||||
{
|
{
|
||||||
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
if (pgstat_relation_should_count(rel))
|
||||||
|
|
||||||
if (pgstat_info != NULL)
|
|
||||||
{
|
{
|
||||||
/* We have to log the effect at the proper transactional level */
|
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
||||||
int nest_level = GetCurrentTransactionNestLevel();
|
int nest_level = GetCurrentTransactionNestLevel();
|
||||||
|
|
||||||
|
/* We have to log the effect at the proper transactional level */
|
||||||
if (pgstat_info->trans == NULL ||
|
if (pgstat_info->trans == NULL ||
|
||||||
pgstat_info->trans->nest_level != nest_level)
|
pgstat_info->trans->nest_level != nest_level)
|
||||||
add_tabstat_xact_level(pgstat_info, nest_level);
|
add_tabstat_xact_level(pgstat_info, nest_level);
|
||||||
@ -2405,13 +2403,12 @@ pgstat_count_heap_update(Relation rel, bool hot)
|
|||||||
void
|
void
|
||||||
pgstat_count_heap_delete(Relation rel)
|
pgstat_count_heap_delete(Relation rel)
|
||||||
{
|
{
|
||||||
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
if (pgstat_relation_should_count(rel))
|
||||||
|
|
||||||
if (pgstat_info != NULL)
|
|
||||||
{
|
{
|
||||||
/* We have to log the effect at the proper transactional level */
|
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
||||||
int nest_level = GetCurrentTransactionNestLevel();
|
int nest_level = GetCurrentTransactionNestLevel();
|
||||||
|
|
||||||
|
/* We have to log the effect at the proper transactional level */
|
||||||
if (pgstat_info->trans == NULL ||
|
if (pgstat_info->trans == NULL ||
|
||||||
pgstat_info->trans->nest_level != nest_level)
|
pgstat_info->trans->nest_level != nest_level)
|
||||||
add_tabstat_xact_level(pgstat_info, nest_level);
|
add_tabstat_xact_level(pgstat_info, nest_level);
|
||||||
@ -2463,13 +2460,12 @@ pgstat_truncdrop_restore_counters(PgStat_TableXactStatus *trans)
|
|||||||
void
|
void
|
||||||
pgstat_count_truncate(Relation rel)
|
pgstat_count_truncate(Relation rel)
|
||||||
{
|
{
|
||||||
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
if (pgstat_relation_should_count(rel))
|
||||||
|
|
||||||
if (pgstat_info != NULL)
|
|
||||||
{
|
{
|
||||||
/* We have to log the effect at the proper transactional level */
|
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
||||||
int nest_level = GetCurrentTransactionNestLevel();
|
int nest_level = GetCurrentTransactionNestLevel();
|
||||||
|
|
||||||
|
/* We have to log the effect at the proper transactional level */
|
||||||
if (pgstat_info->trans == NULL ||
|
if (pgstat_info->trans == NULL ||
|
||||||
pgstat_info->trans->nest_level != nest_level)
|
pgstat_info->trans->nest_level != nest_level)
|
||||||
add_tabstat_xact_level(pgstat_info, nest_level);
|
add_tabstat_xact_level(pgstat_info, nest_level);
|
||||||
@ -2492,10 +2488,12 @@ pgstat_count_truncate(Relation rel)
|
|||||||
void
|
void
|
||||||
pgstat_update_heap_dead_tuples(Relation rel, int delta)
|
pgstat_update_heap_dead_tuples(Relation rel, int delta)
|
||||||
{
|
{
|
||||||
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
if (pgstat_relation_should_count(rel))
|
||||||
|
{
|
||||||
|
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
|
||||||
|
|
||||||
if (pgstat_info != NULL)
|
|
||||||
pgstat_info->t_counts.t_delta_dead_tuples -= delta;
|
pgstat_info->t_counts.t_delta_dead_tuples -= delta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1104,41 +1104,44 @@ extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
|
|||||||
|
|
||||||
extern void pgstat_initstats(Relation rel);
|
extern void pgstat_initstats(Relation rel);
|
||||||
|
|
||||||
|
#define pgstat_relation_should_count(rel) \
|
||||||
|
(likely((rel)->pgstat_info != NULL))
|
||||||
|
|
||||||
/* nontransactional event counts are simple enough to inline */
|
/* nontransactional event counts are simple enough to inline */
|
||||||
|
|
||||||
#define pgstat_count_heap_scan(rel) \
|
#define pgstat_count_heap_scan(rel) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_numscans++; \
|
(rel)->pgstat_info->t_counts.t_numscans++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_heap_getnext(rel) \
|
#define pgstat_count_heap_getnext(rel) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_tuples_returned++; \
|
(rel)->pgstat_info->t_counts.t_tuples_returned++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_heap_fetch(rel) \
|
#define pgstat_count_heap_fetch(rel) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_tuples_fetched++; \
|
(rel)->pgstat_info->t_counts.t_tuples_fetched++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_index_scan(rel) \
|
#define pgstat_count_index_scan(rel) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_numscans++; \
|
(rel)->pgstat_info->t_counts.t_numscans++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_index_tuples(rel, n) \
|
#define pgstat_count_index_tuples(rel, n) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
|
(rel)->pgstat_info->t_counts.t_tuples_returned += (n); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_buffer_read(rel) \
|
#define pgstat_count_buffer_read(rel) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_blocks_fetched++; \
|
(rel)->pgstat_info->t_counts.t_blocks_fetched++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_buffer_hit(rel) \
|
#define pgstat_count_buffer_hit(rel) \
|
||||||
do { \
|
do { \
|
||||||
if ((rel)->pgstat_info != NULL) \
|
if (pgstat_relation_should_count(rel)) \
|
||||||
(rel)->pgstat_info->t_counts.t_blocks_hit++; \
|
(rel)->pgstat_info->t_counts.t_blocks_hit++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define pgstat_count_buffer_read_time(n) \
|
#define pgstat_count_buffer_read_time(n) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user