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

Commite1efc5b

Browse files
alvherreYuzuko Hosoyajustinpryzby
committed
Keep stats up to date for partitioned tables
In the long-going saga for analyze on partitioned tables, one thing Imissed while reverting0827e8a is the maintenance of analyze countand last analyze time for partitioned tables. This is a mostly trivialchange that enables users assess the need for invoking manual ANALYZE onpartitioned tables.This patch, posted by Justin and modified a bit by me (Álvaro), can bemostly traced back to Hosoya-san, though any problems introduced withthe scissors are mine.Backpatch to 14, in line with6f8127b.Co-authored-by: Yuzuko Hosoya <yuzukohosoya@gmail.com>Co-authored-by: Justin Pryzby <pryzby@telsasoft.com>Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>Reported-by: Justin Pryzby <pryzby@telsasoft.com>Discussion:https://postgr.es/m/20210816222810.GE10479@telsasoft.com
1 parent359bcf7 commite1efc5b

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

‎src/backend/commands/analyze.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
626626
PROGRESS_ANALYZE_PHASE_FINALIZE_ANALYZE);
627627

628628
/*
629-
* Update pages/tuples stats in pg_class, and report ANALYZE to the stats
630-
*collector ... but not if we're doinginherited stats.
629+
* Update pages/tuples stats in pg_class ... but not if we're doing
630+
* inherited stats.
631631
*
632632
* We assume that VACUUM hasn't set pg_class.reltuples already, even
633633
* during a VACUUM ANALYZE. Although VACUUM often updates pg_class,
@@ -668,20 +668,33 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
668668
InvalidMultiXactId,
669669
in_outer_xact);
670670
}
671-
671+
}
672+
elseif (onerel->rd_rel->relkind==RELKIND_PARTITIONED_TABLE)
673+
{
672674
/*
673-
* Now report ANALYZE to the stats collector.
674-
*
675-
* We deliberately don't report to the stats collector when doing
676-
* inherited stats, because the stats collector only tracks per-table
677-
* stats.
678-
*
679-
* Reset the changes_since_analyze counter only if we analyzed all
680-
* columns; otherwise, there is still work for auto-analyze to do.
675+
* Partitioned tables don't have storage, so we don't set any fields
676+
* in their pg_class entries except for reltuples and relhasindex.
681677
*/
678+
vac_update_relstats(onerel,-1,totalrows,
679+
0,hasindex,InvalidTransactionId,
680+
InvalidMultiXactId,
681+
in_outer_xact);
682+
}
683+
684+
/*
685+
* Now report ANALYZE to the stats collector. For regular tables, we do
686+
* it only if not doing inherited stats. For partitioned tables, we only
687+
* do it for inherited stats. (We're never called for not-inherited stats
688+
* on partitioned tables anyway.)
689+
*
690+
* Reset the changes_since_analyze counter only if we analyzed all
691+
* columns; otherwise, there is still work for auto-analyze to do.
692+
*/
693+
if (!inh)
682694
pgstat_report_analyze(onerel,totalrows,totaldeadrows,
683695
(va_cols==NIL));
684-
}
696+
elseif (onerel->rd_rel->relkind==RELKIND_PARTITIONED_TABLE)
697+
pgstat_report_analyze(onerel,0,0, (va_cols==NIL));
685698

686699
/*
687700
* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup.

‎src/backend/postmaster/pgstat.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,8 +1618,11 @@ pgstat_report_analyze(Relation rel,
16181618
* be double-counted after commit. (This approach also ensures that the
16191619
* collector ends up with the right numbers if we abort instead of
16201620
* committing.)
1621+
*
1622+
* Waste no time on partitioned tables, though.
16211623
*/
1622-
if (rel->pgstat_info!=NULL)
1624+
if (rel->pgstat_info!=NULL&&
1625+
rel->rd_rel->relkind!=RELKIND_PARTITIONED_TABLE)
16231626
{
16241627
PgStat_TableXactStatus*trans;
16251628

@@ -1981,8 +1984,10 @@ pgstat_initstats(Relation rel)
19811984
Oidrel_id=rel->rd_id;
19821985
charrelkind=rel->rd_rel->relkind;
19831986

1984-
/* We only count stats for things that have storage */
1985-
if (!RELKIND_HAS_STORAGE(relkind))
1987+
/*
1988+
* We only count stats for relations with storage and partitioned tables
1989+
*/
1990+
if (!RELKIND_HAS_STORAGE(relkind)&&relkind!=RELKIND_PARTITIONED_TABLE)
19861991
{
19871992
rel->pgstat_info=NULL;
19881993
return;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp