mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
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
This commit is contained in:
parent
cc96373cf3
commit
8ea7963fc7
@ -1734,30 +1734,8 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
|
|||||||
changeDependenciesOf(RelationRelationId, oldIndexId, newIndexId);
|
changeDependenciesOf(RelationRelationId, oldIndexId, newIndexId);
|
||||||
changeDependenciesOn(RelationRelationId, oldIndexId, newIndexId);
|
changeDependenciesOn(RelationRelationId, oldIndexId, newIndexId);
|
||||||
|
|
||||||
/*
|
/* copy over statistics from old to new index */
|
||||||
* Copy over statistics from old to new index
|
pgstat_copy_relation_stats(newClassRel, oldClassRel);
|
||||||
*/
|
|
||||||
{
|
|
||||||
PgStat_StatTabEntry *tabentry;
|
|
||||||
|
|
||||||
tabentry = pgstat_fetch_stat_tabentry(oldIndexId);
|
|
||||||
if (tabentry)
|
|
||||||
{
|
|
||||||
if (pgstat_relation_should_count(newClassRel))
|
|
||||||
{
|
|
||||||
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_fetched = tabentry->tuples_fetched;
|
|
||||||
newClassRel->pgstat_info->t_counts.t_blocks_fetched = tabentry->blocks_fetched;
|
|
||||||
newClassRel->pgstat_info->t_counts.t_blocks_hit = tabentry->blocks_hit;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The data will be sent by the next pgstat_report_stat()
|
|
||||||
* call.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy data of pg_statistic from the old index to the new one */
|
/* Copy data of pg_statistic from the old index to the new one */
|
||||||
CopyStatistics(oldIndexId, newIndexId);
|
CopyStatistics(oldIndexId, newIndexId);
|
||||||
|
@ -95,6 +95,38 @@ bool have_relation_stats;
|
|||||||
static HTAB *pgStatTabHash = NULL;
|
static HTAB *pgStatTabHash = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy stats between relations. This is used for things like REINDEX
|
||||||
|
* CONCURRENTLY.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
pgstat_copy_relation_stats(Relation dst, Relation src)
|
||||||
|
{
|
||||||
|
PgStat_StatTabEntry *srcstats;
|
||||||
|
|
||||||
|
srcstats = pgstat_fetch_stat_tabentry(RelationGetRelid(src));
|
||||||
|
|
||||||
|
if (!srcstats)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pgstat_relation_should_count(dst))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* XXX: temporarily this does not actually quite do what the name
|
||||||
|
* says, and just copy index related fields. A subsequent commit will
|
||||||
|
* do more.
|
||||||
|
*/
|
||||||
|
|
||||||
|
dst->pgstat_info->t_counts.t_numscans = srcstats->numscans;
|
||||||
|
dst->pgstat_info->t_counts.t_tuples_returned = srcstats->tuples_returned;
|
||||||
|
dst->pgstat_info->t_counts.t_tuples_fetched = srcstats->tuples_fetched;
|
||||||
|
dst->pgstat_info->t_counts.t_blocks_fetched = srcstats->blocks_fetched;
|
||||||
|
dst->pgstat_info->t_counts.t_blocks_hit = srcstats->blocks_hit;
|
||||||
|
|
||||||
|
/* the data will be sent by the next pgstat_report_stat() call */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize a relcache entry to count access statistics.
|
* Initialize a relcache entry to count access statistics.
|
||||||
* Called whenever a relation is opened.
|
* Called whenever a relation is opened.
|
||||||
|
@ -1053,6 +1053,8 @@ extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
|
|||||||
* Functions in pgstat_relation.c
|
* Functions in pgstat_relation.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern void pgstat_copy_relation_stats(Relation dstrel, Relation srcrel);
|
||||||
|
|
||||||
extern void pgstat_relation_init(Relation rel);
|
extern void pgstat_relation_init(Relation rel);
|
||||||
|
|
||||||
extern void pgstat_report_vacuum(Oid tableoid, bool shared,
|
extern void pgstat_report_vacuum(Oid tableoid, bool shared,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user