Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVPKi-0003Bp-TB for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Apr 2021 01:56:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lVPKB-0003Bz-4D for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Apr 2021 01:55:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVPKA-0003Br-Os for pgsql-hackers@lists.postgresql.org; Sun, 11 Apr 2021 01:55:42 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lVPK8-0002dZ-3g for pgsql-hackers@lists.postgresql.org; Sun, 11 Apr 2021 01:55:41 +0000 Received: by mail-io1-xd2c.google.com with SMTP id z3so9831489ioc.8 for ; Sat, 10 Apr 2021 18:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to:user-agent; bh=GjI4JB+1m0cG7swiiKBi8ZNGLvAQkaetVNVNAqlN18E=; b=RYyW4mKV10OfwwSUFipn6wY+Kp9xz9kg1flQsl3lHhA+DbUX++ltJoiNNUDKcvyZ1R DJizcUKZLyhRxxr8LISWfw2rk7bTTh+yooKHdoICt3gjFI7osQuBLFz+XXMOpVEKzdfr sZZhUKVnzqUY06+ef245thpn5FAt1gPFzYpRs7EMYtXIuuCj9HNZmW/kqDjc7BlFNG5n 0gPEE/BPW4k4KA5G8rzWGcgkH7oQoOUP67cN1QFuPAXlPnshUQxYyllQearFJ6JE0mwY 0WAcmZxonQcqH/XprUgHqQkdENy1DWlgkoVfqOD7Wq0YS+cs1QKVaGnY7vNlouJJNN21 uT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=GjI4JB+1m0cG7swiiKBi8ZNGLvAQkaetVNVNAqlN18E=; b=O8cWa1SXFuhqSOGJLYP/spk08KWwBAaz6HwiSJCV3oXulDStmEDYMgvpElP43l0JT1 qpnDEjREGBc7EDgvXnXxtvhIO85dfDQmX6WKXLpXO4Qs4fLVRWzLPFNqV6XCgBurvHY+ +dY9OnY8H7VNKyx1AHK4cXZTtQGh8N+u1mPOpOnV3oRJjV82gehvx66FIbuCnqeuS3/6 1tqkw8rE+f7ETtV7nMrwvLgJqfyCwwuhRCxzAuGpEDUufk3asjQR13m4Cn65+U3gut8x v83QpH5PUjOXqcq7hCL94hMBN0TPyizKMcsibC6aYCealI97/Pds0DG0iUMborT1IGPS x5XA== X-Gm-Message-State: AOAM531/F/VkqLBWtjGJ6NJAW6gc/mnzhEPIlbrCk0bXVLisMtwGR1U/ X2xj+oU2bpkDOGducgBLgMlBYw== X-Google-Smtp-Source: ABdhPJy7v8bdv5HT8M8gbDxJZyZk4PCqvyCwRSf/hC4TheUswtuexhWEqxEimCq21LmI2hyn3HC6Qg== X-Received: by 2002:a5d:9149:: with SMTP id y9mr17062899ioq.159.1618106139262; Sat, 10 Apr 2021 18:55:39 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d3sm3242709ilv.80.2021.04.10.18.55.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Apr 2021 18:55:38 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 7B97E802191; Sat, 10 Apr 2021 20:55:37 -0500 (CDT) Date: Sat, 10 Apr 2021 20:55:37 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Tom Lane , pgsql-hackers@lists.postgresql.org, Zhihong Yu Subject: Re: pgsql: autovacuum: handle analyze for partitioned tables Message-ID: <20210411015537.GA14564@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210409155430.GA9512@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 |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