From: | Justin Pryzby <pryzby(at)telsasoft(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Zhihong Yu <zyu(at)yugabyte(dot)com> |
Subject: | Re: pgsql: autovacuum: handle analyze for partitioned tables |
Date: | 2021-04-11 01:55:37 |
Message-ID: | 20210411015537.GA14564@telsasoft.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers pgsql-hackers |
On Thu, Apr 08, 2021 at 04:11:49PM -0400, Alvaro Herrera wrote:
> On 2021-Apr-08, Tom Lane wrote:
>
> > > So I tend to think that my initial instinct was the better direction: we
> > > should not be doing any find_all_inheritors() here at all, but instead
> > > rely on pg_class.reltuples to be set for the partitioned table.
> >
> > +1
>
> This patch does that.
|commit 0e69f705cc1a3df273b38c9883fb5765991e04fe
|Author: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
|Date: Fri Apr 9 11:29:08 2021 -0400
|
| Set pg_class.reltuples for partitioned tables
|
| When commit 0827e8af70f4 added auto-analyze support for partitioned
| tables, it included code to obtain reltuples for the partitioned table
| as a number of catalog accesses to read pg_class.reltuples for each
| partition. That's not only very inefficient, but also problematic
| because autovacuum doesn't hold any locks on any of those tables -- and
| doesn't want to. Replace that code with a read of pg_class.reltuples
| for the partitioned table, and make sure ANALYZE and TRUNCATE properly
| maintain that value.
|
| I found no code that would be affected by the change of relpages from
| zero to non-zero for partitioned tables, and no other code that should
| be maintaining it, but if there is, hopefully it'll be an easy fix.
+ else if (onerel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+ {
+ /*
+ * Partitioned tables don't have storage, so we don't set any fields in
+ * their pg_class entries except for relpages, which is necessary for
+ * auto-analyze to work properly.
+ */
+ vac_update_relstats(onerel, -1, totalrows,
+ 0, false, InvalidTransactionId,
+ InvalidMultiXactId,
+ in_outer_xact);
+ }
This refers to "relpages", but I think it means "reltuples".
src/include/commands/vacuum.h:extern void vac_update_relstats(Relation relation,
src/include/commands/vacuum.h- BlockNumber num_pages,
src/include/commands/vacuum.h- double num_tuples,
src/include/commands/vacuum.h- BlockNumber num_all_visible_pages,
I'm adding it for the next round of "v14docs" patch if you don't want to make a
separate commit for that.
--
Justin
From | Date | Subject | |
---|---|---|---|
Next Message | Fujii Masao | 2021-04-11 15:05:32 | pgsql: Remove COMMIT_TS_SETTS record. |
Previous Message | Tomas Vondra | 2021-04-10 21:22:53 | Re: pgsql: autovacuum: handle analyze for partitioned tables |
From | Date | Subject | |
---|---|---|---|
Next Message | Zhihong Yu | 2021-04-11 02:22:39 | Re: Add header support to text format and matching feature |
Previous Message | Dave Cramer | 2021-04-11 01:11:01 | Re: PL/R regression on windows, but not linux with master. |