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 1kXFZY-0007Qq-R8 for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Oct 2020 03:22:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kXFZX-0001Z6-PH for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Oct 2020 03:22:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kXFZX-0001Yy-Ie for pgsql-hackers@lists.postgresql.org; Tue, 27 Oct 2020 03:22:55 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kXFZV-0007jf-GQ for pgsql-hackers@lists.postgresql.org; Tue, 27 Oct 2020 03:22:55 +0000 Received: by mail-io1-xd41.google.com with SMTP id u19so7143ion.3 for ; Mon, 26 Oct 2020 20:22:53 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ae7h1To5xxNDShdyH2AKGvowGs0KVUvB0Z8sg2SUN9E=; b=reRPRvjQQxDsSye45sZAFYk2HPZNjH/bEPhgRk1Say2la4se9oGnzOdIOl1U+6i+Yt uHzJ35AyDKFsjen7n+F7RJJWYoTAxExhamlOLrn+SkVYGRzyPCZKp/V8VpYyZ52FHs2z pfCdXOZ+NZoHpTlRWBLC/vhS+oqVdsDCMsJIIlNTyE5wUp7u4yhotCj/wSqJa2mKfThy h9AQlbzklk0VprXF4k/pexE+ODM0Fqy4AjzWV5a/Pg0xm7QFtcF7bH+g7UdmnFuunYua E/YegRdrMIevo2jPRzmnDMSHtphzdSu0w8bWBgvAdX7PN0WTpzDGNVTGbjGYG1Fj7tqg /ggQ== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ae7h1To5xxNDShdyH2AKGvowGs0KVUvB0Z8sg2SUN9E=; b=km0vSDu5+UlBVNVnQ/3RyBuhvUG7p4lgFozF8PSWdTrit16CoQTtls9fehyQ50kEbI D3zCOKKQUlFu2iyryjQztAXxd/5fuAseCpUbunUHaY/CRzluQCdkF8BuRsMfELrHYuJC nmKuVozRRjW8/ka7Ve3bswGbvMeJKjHJ5DC6EBeUyEtmOgrVniTn9tCWrcH5d3szdEf5 NYiLczbQ1hztr74PVJeB5YF038d0S5+w6TbmFvDDGxOESFANtb7zlG752yuNZEfyIEAl 2QJewpp6a+5CP8OmcP5c2RdRCRffflQfWdIJjSrcCIQPovXeeDzJF8FrcEj2vutqHHAt j2tw== X-Gm-Message-State: AOAM532sJGRKO/l6J/VLWEOXxRle7vNyqpM/B3TxSiv+6L6y8eD/GeGO 6H61Zjp2AkcKMa6LqRi/T1EQmw== X-Google-Smtp-Source: ABdhPJxda+u3OJCxdE0Yw0OBeghmbaH/StKKWsU8NHOIpfGb+GHOAl0HkaYDf2FivIdZ2GNW4w4nzg== X-Received: by 2002:a5d:9758:: with SMTP id c24mr246558ioo.166.1603768971912; Mon, 26 Oct 2020 20:22:51 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 186sm75337ile.4.2020.10.26.20.22.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2020 20:22:51 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 3265680067E; Mon, 26 Oct 2020 22:22:50 -0500 (CDT) Date: Mon, 26 Oct 2020 22:22:50 -0500 From: Justin Pryzby To: yuzuko Cc: Kyotaro Horiguchi , Daniel Gustafsson , Amit Langote , Alvaro Herrera , Masahiko Sawada , Laurenz Albe , PostgreSQL Hackers , Greg Stark Subject: Re: Autovacuum on partitioned table (autoanalyze) Message-ID: <20201027032249.GE9241@telsasoft.com> References: <20200915.190135.1065752215377064117.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Oct 23, 2020 at 03:12:51PM +0900, yuzuko wrote: > Hello, > > I reconsidered a way based on the v5 patch in line with > Horiguchi-san's comment. > > This approach is as follows: > - A partitioned table is checked whether it needs analyze like a plain > table in relation_needs_vacanalyze(). To do this, we should store > partitioned table's stats (changes_since_analyze). > - Partitioned table's changes_since_analyze is updated when > analyze a leaf partition by propagating its changes_since_analyze. > In the next scheduled analyze time, it is used in the above process. > That is, the partitioned table is analyzed behind leaf partitions. > - The propagation process differs between autoanalyze or plain analyze. > In autoanalyze, a leaf partition's changes_since_analyze is propagated > to *all* ancestors. Whereas, in plain analyze on an inheritance tree, > propagates to ancestors not included the tree to avoid needless counting. + * Get its all ancestors to propagate changes_since_analyze count. + * However, when ANALYZE inheritance tree, we get ancestors of + * toprel_oid to avoid needless counting. => I don't understand that comment. + /* Find all members of inheritance set taking AccessShareLock */ + children = find_all_inheritors(relid, AccessShareLock, NULL); => Do you know that returns the table itself ? And in pg14dev, each partitioned table has reltuples = -1, not zero... + /* Skip foreign partitions */ + if (childclass->relkind == RELKIND_FOREIGN_TABLE) + continue; => Michael's suggrestion is to use RELKIND_HAS_STORAGE to skip both foreign and partitioned tables. Also, you called SearchSysCacheCopy1, but didn't free the tuple. I don't think you need to copy it anyway - just call ReleaseSysCache(). Regarding the counters in pg_stat_all_tables: maybe some of these should be null rather than zero ? Or else you should make an 0001 patch to fully implement this view, with all relevant counters, not just n_mod_since_analyze, last_*analyze, and *analyze_count. These are specifically misleading: last_vacuum | last_autovacuum | n_ins_since_vacuum | 0 vacuum_count | 0 autovacuum_count | 0 -- Justin