Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8ea7963

Browse files
committed
pgstat: add pgstat_copy_relation_stats().
Until now index_concurrently_swap() directly modified pgstat internal datastructures. That will break with the introduction of shared memory statistics and seems off architecturally. This is done separately from the - quite large - shared memory statistics patch to make review easier. Author: Andres Freund <andres@anarazel.de> Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
1 parent cc96373 commit 8ea7963

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

src/backend/catalog/index.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,30 +1734,8 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
17341734
changeDependenciesOf(RelationRelationId, oldIndexId, newIndexId);
17351735
changeDependenciesOn(RelationRelationId, oldIndexId, newIndexId);
17361736

1737-
/*
1738-
* Copy over statistics from old to new index
1739-
*/
1740-
{
1741-
PgStat_StatTabEntry *tabentry;
1742-
1743-
tabentry = pgstat_fetch_stat_tabentry(oldIndexId);
1744-
if (tabentry)
1745-
{
1746-
if (pgstat_relation_should_count(newClassRel))
1747-
{
1748-
newClassRel->pgstat_info->t_counts.t_numscans = tabentry->numscans;
1749-
newClassRel->pgstat_info->t_counts.t_tuples_returned = tabentry->tuples_returned;
1750-
newClassRel->pgstat_info->t_counts.t_tuples_fetched = tabentry->tuples_fetched;
1751-
newClassRel->pgstat_info->t_counts.t_blocks_fetched = tabentry->blocks_fetched;
1752-
newClassRel->pgstat_info->t_counts.t_blocks_hit = tabentry->blocks_hit;
1753-
1754-
/*
1755-
* The data will be sent by the next pgstat_report_stat()
1756-
* call.
1757-
*/
1758-
}
1759-
}
1760-
}
1737+
/* copy over statistics from old to new index */
1738+
pgstat_copy_relation_stats(newClassRel, oldClassRel);
17611739

17621740
/* Copy data of pg_statistic from the old index to the new one */
17631741
CopyStatistics(oldIndexId, newIndexId);

src/backend/utils/activity/pgstat_relation.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,38 @@ bool have_relation_stats;
9595
static HTAB *pgStatTabHash = NULL;
9696

9797

98+
/*
99+
* Copy stats between relations. This is used for things like REINDEX
100+
* CONCURRENTLY.
101+
*/
102+
void
103+
pgstat_copy_relation_stats(Relation dst, Relation src)
104+
{
105+
PgStat_StatTabEntry *srcstats;
106+
107+
srcstats = pgstat_fetch_stat_tabentry(RelationGetRelid(src));
108+
109+
if (!srcstats)
110+
return;
111+
112+
if (pgstat_relation_should_count(dst))
113+
{
114+
/*
115+
* XXX: temporarily this does not actually quite do what the name
116+
* says, and just copy index related fields. A subsequent commit will
117+
* do more.
118+
*/
119+
120+
dst->pgstat_info->t_counts.t_numscans = srcstats->numscans;
121+
dst->pgstat_info->t_counts.t_tuples_returned = srcstats->tuples_returned;
122+
dst->pgstat_info->t_counts.t_tuples_fetched = srcstats->tuples_fetched;
123+
dst->pgstat_info->t_counts.t_blocks_fetched = srcstats->blocks_fetched;
124+
dst->pgstat_info->t_counts.t_blocks_hit = srcstats->blocks_hit;
125+
126+
/* the data will be sent by the next pgstat_report_stat() call */
127+
}
128+
}
129+
98130
/*
99131
* Initialize a relcache entry to count access statistics.
100132
* Called whenever a relation is opened.

src/include/pgstat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,8 @@ extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
10531053
* Functions in pgstat_relation.c
10541054
*/
10551055

1056+
extern void pgstat_copy_relation_stats(Relation dstrel, Relation srcrel);
1057+
10561058
extern void pgstat_relation_init(Relation rel);
10571059

10581060
extern void pgstat_report_vacuum(Oid tableoid, bool shared,

0 commit comments

Comments
 (0)