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 1kjliD-0004De-7n for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Nov 2020 16:07:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kjliA-0003o8-O2 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Nov 2020 16:07:34 +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 1kjli9-0003o1-TZ for pgsql-hackers@lists.postgresql.org; Mon, 30 Nov 2020 16:07:34 +0000 Received: from [66.111.4.25] (helo=out1-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kjli3-0004Qb-Co for pgsql-hackers@lists.postgresql.org; Mon, 30 Nov 2020 16:07:33 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id D8DC05C0158; Mon, 30 Nov 2020 11:07:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 30 Nov 2020 11:07:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Q3Vxn9zut4r4f/7Tk Y6SEWHapcLlYabbxUMuUSUTdl0=; b=UOnntgfuld3IpeZeI2rpBHyi44SvWgVxM uzYJQFeU6FzZgO1XH1iNxK3MKqxQgEp+TCNoSm9JoQD+v4ZoqVvSKFjEY7SOq6On bdK17OO6mM5yl+Z5O0L7XKDI6BlFchISOtPNTeJPXpmXjLSNohQgSYJqxGDQvJ+m xmQr4waeUOfCGpadw3oFw4fUREmjcvcNbbAeBizpQwihsx/RbSd7TuylXZkaMHE6 p8y2uTjMybJjm2/MoJYaMT2XFSWCLEZEwoVCv1lOZNoKOSc7w+Di7YaExhNgKGoV HrCRplVITTAt3f3LT86+m8tjavDRs/TDvXwK9UXu3ZvuyGu3wZEIg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeitddgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtuggjfgesthdtre dttdervdenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgv segrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepvefgleevgeeuje eghfegteeghfegheeifeehheelteetieduieeihffggfehffetnecukfhppeduledtrdel hedrudekrdejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.18.79]) by mail.messagingengine.com (Postfix) with ESMTPA id 627D83064AB0; Mon, 30 Nov 2020 11:07:14 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 1C5CF2A14FE; Mon, 30 Nov 2020 13:07:12 -0300 (-03) Date: Mon, 30 Nov 2020 13:07:12 -0300 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: yuzukohosoya@gmail.com, pryzby@telsasoft.com, daniel@yesql.se, amitlangote09@gmail.com, masahiko.sawada@2ndquadrant.com, laurenz.albe@cybertec.at, pgsql-hackers@lists.postgresql.org, stark@mit.edu Subject: Re: Autovacuum on partitioned table (autoanalyze) Message-ID: <20201130160712.GA20727@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201110.203557.1420746510378864931.horikyota.ntt@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.25 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I looked at both Yuzuko Hosoya's patch and Kyotaro Horiguchi's, and think we're doing things in a quite complicated manner, which perhaps could be done more easily. Hosoya's patch has pgstat_report_analyze call pgstat_get_tab_entry() for the table being vacuumed, then obtains the list of ancestors, and then sends for each ancestor a new message containing the partition's changes_since_analyze for that ancestor. When stat collector receives that message, it adds the number to the ancestor's m_changed_tuples. Horiguchi's doing a similar thing, only differently: it is do_analyze_rel that reads the count from the collector (this time by calling SQL function pg_stat_get_mod_since_analyze) and then sends number back to the collector for each ancestor. I suggest that a better way to do this, is to forget about the new "partchanges" message completely. Instead, let's add an array of ancestors to the analyze message (borrowing from PgStat_MsgFuncstat). Something like this: #define PGSTAT_NUM_ANCESTORENTRIES \ ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(Oid) - sizeof(bool) - \ sizeof(bool) - sizeof(TimestampTz) - sizeof(PgStat_Counter) - \ sizeof(PgStat_Counter) - sizeof(int)) / sizeof(Oid)) typedef struct PgStat_MsgAnalyze { PgStat_MsgHdr m_hdr; Oid m_databaseid; Oid m_tableoid; bool m_autovacuum; bool m_resetcounter; TimestampTz m_analyzetime; PgStat_Counter m_live_tuples; PgStat_Counter m_dead_tuples; int m_nancestors; Oid m_ancestors[PGSTAT_NUM_ANCESTORENTRIES]; } PgStat_MsgAnalyze; For non-partitions, m_nancestors would be 0, so the message would be handled as today. For partitions, the array carries the OID of all ancestors. When the collector receives this message, first it looks up the pgstat entries for each ancestors in the array, and it adds the partition's current changes_since_analyze to the ancestor's changes_since_analyze. Then it does things as currently, including reset the changes_since_analyze counter for the partition. Key point in this is that we don't need to read the number from collector into the backend executing analyze. We just *send* the data about ancestors, and the collector knows what to do with it. One possible complaint is: what if there are more ancestors that fit in the message? I propose that this problem can be ignored, since in order to hit this, you'd need to have (1000-8-4-4-1-1-8-8-8-4)/4 = 238 ancestors (if my math is right). I doubt we'll hit the need to use 238 levels of partitionings before a stat collector rewrite occurs ... (It is possible to remove that restriction by doing more complicated things such as sending the list of ancestor in a new type of message that can be sent several times, prior to the analyze message itself, but I don't think this is worth the trouble.)