Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8363102

Browse files
committed
pgstat: introduce pgstat_relation_should_count().
A later commit will make the check more complicated than thecurrent (rel)->pgstat_info != NULL. It also just seems nicer to have a centralcopy of the logic, even while still simple.Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
1 parent2d655a0 commit8363102

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

‎src/backend/catalog/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
17431743
tabentry=pgstat_fetch_stat_tabentry(oldIndexId);
17441744
if (tabentry)
17451745
{
1746-
if (newClassRel->pgstat_info)
1746+
if (pgstat_relation_should_count(newClassRel))
17471747
{
17481748
newClassRel->pgstat_info->t_counts.t_numscans=tabentry->numscans;
17491749
newClassRel->pgstat_info->t_counts.t_tuples_returned=tabentry->tuples_returned;

‎src/backend/postmaster/pgstat.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ pgstat_report_analyze(Relation rel,
17091709
*
17101710
* Waste no time on partitioned tables, though.
17111711
*/
1712-
if (rel->pgstat_info!=NULL&&
1712+
if (pgstat_relation_should_count(rel)&&
17131713
rel->rd_rel->relkind!=RELKIND_PARTITIONED_TABLE)
17141714
{
17151715
PgStat_TableXactStatus*trans;
@@ -2359,13 +2359,12 @@ add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
23592359
void
23602360
pgstat_count_heap_insert(Relationrel,PgStat_Countern)
23612361
{
2362-
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
2363-
2364-
if (pgstat_info!=NULL)
2362+
if (pgstat_relation_should_count(rel))
23652363
{
2366-
/* We have to log the effect at the proper transactional level */
2364+
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
23672365
intnest_level=GetCurrentTransactionNestLevel();
23682366

2367+
/* We have to log the effect at the proper transactional level */
23692368
if (pgstat_info->trans==NULL||
23702369
pgstat_info->trans->nest_level!=nest_level)
23712370
add_tabstat_xact_level(pgstat_info,nest_level);
@@ -2380,13 +2379,12 @@ pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
23802379
void
23812380
pgstat_count_heap_update(Relationrel,boolhot)
23822381
{
2383-
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
2384-
2385-
if (pgstat_info!=NULL)
2382+
if (pgstat_relation_should_count(rel))
23862383
{
2387-
/* We have to log the effect at the proper transactional level */
2384+
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
23882385
intnest_level=GetCurrentTransactionNestLevel();
23892386

2387+
/* We have to log the effect at the proper transactional level */
23902388
if (pgstat_info->trans==NULL||
23912389
pgstat_info->trans->nest_level!=nest_level)
23922390
add_tabstat_xact_level(pgstat_info,nest_level);
@@ -2405,13 +2403,12 @@ pgstat_count_heap_update(Relation rel, bool hot)
24052403
void
24062404
pgstat_count_heap_delete(Relationrel)
24072405
{
2408-
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
2409-
2410-
if (pgstat_info!=NULL)
2406+
if (pgstat_relation_should_count(rel))
24112407
{
2412-
/* We have to log the effect at the proper transactional level */
2408+
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
24132409
intnest_level=GetCurrentTransactionNestLevel();
24142410

2411+
/* We have to log the effect at the proper transactional level */
24152412
if (pgstat_info->trans==NULL||
24162413
pgstat_info->trans->nest_level!=nest_level)
24172414
add_tabstat_xact_level(pgstat_info,nest_level);
@@ -2463,13 +2460,12 @@ pgstat_truncdrop_restore_counters(PgStat_TableXactStatus *trans)
24632460
void
24642461
pgstat_count_truncate(Relationrel)
24652462
{
2466-
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
2467-
2468-
if (pgstat_info!=NULL)
2463+
if (pgstat_relation_should_count(rel))
24692464
{
2470-
/* We have to log the effect at the proper transactional level */
2465+
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
24712466
intnest_level=GetCurrentTransactionNestLevel();
24722467

2468+
/* We have to log the effect at the proper transactional level */
24732469
if (pgstat_info->trans==NULL||
24742470
pgstat_info->trans->nest_level!=nest_level)
24752471
add_tabstat_xact_level(pgstat_info,nest_level);
@@ -2492,10 +2488,12 @@ pgstat_count_truncate(Relation rel)
24922488
void
24932489
pgstat_update_heap_dead_tuples(Relationrel,intdelta)
24942490
{
2495-
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
2491+
if (pgstat_relation_should_count(rel))
2492+
{
2493+
PgStat_TableStatus*pgstat_info=rel->pgstat_info;
24962494

2497-
if (pgstat_info!=NULL)
24982495
pgstat_info->t_counts.t_delta_dead_tuples-=delta;
2496+
}
24992497
}
25002498

25012499
/*

‎src/include/pgstat.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,41 +1104,44 @@ extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
11041104

11051105
externvoidpgstat_initstats(Relationrel);
11061106

1107+
#definepgstat_relation_should_count(rel) \
1108+
(likely((rel)->pgstat_info != NULL))
1109+
11071110
/* nontransactional event counts are simple enough to inline */
11081111

11091112
#definepgstat_count_heap_scan(rel)\
11101113
do {\
1111-
if ((rel)->pgstat_info != NULL)\
1114+
if (pgstat_relation_should_count(rel))\
11121115
(rel)->pgstat_info->t_counts.t_numscans++;\
11131116
} while (0)
11141117
#definepgstat_count_heap_getnext(rel)\
11151118
do {\
1116-
if ((rel)->pgstat_info != NULL)\
1119+
if (pgstat_relation_should_count(rel))\
11171120
(rel)->pgstat_info->t_counts.t_tuples_returned++;\
11181121
} while (0)
11191122
#definepgstat_count_heap_fetch(rel)\
11201123
do {\
1121-
if ((rel)->pgstat_info != NULL)\
1124+
if (pgstat_relation_should_count(rel))\
11221125
(rel)->pgstat_info->t_counts.t_tuples_fetched++;\
11231126
} while (0)
11241127
#definepgstat_count_index_scan(rel)\
11251128
do {\
1126-
if ((rel)->pgstat_info != NULL)\
1129+
if (pgstat_relation_should_count(rel))\
11271130
(rel)->pgstat_info->t_counts.t_numscans++;\
11281131
} while (0)
11291132
#definepgstat_count_index_tuples(rel,n)\
11301133
do {\
1131-
if ((rel)->pgstat_info != NULL)\
1134+
if (pgstat_relation_should_count(rel))\
11321135
(rel)->pgstat_info->t_counts.t_tuples_returned += (n);\
11331136
} while (0)
11341137
#definepgstat_count_buffer_read(rel)\
11351138
do {\
1136-
if ((rel)->pgstat_info != NULL)\
1139+
if (pgstat_relation_should_count(rel))\
11371140
(rel)->pgstat_info->t_counts.t_blocks_fetched++;\
11381141
} while (0)
11391142
#definepgstat_count_buffer_hit(rel)\
11401143
do {\
1141-
if ((rel)->pgstat_info != NULL)\
1144+
if (pgstat_relation_should_count(rel))\
11421145
(rel)->pgstat_info->t_counts.t_blocks_hit++;\
11431146
} while (0)
11441147
#definepgstat_count_buffer_read_time(n)\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp