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 1mWBjd-0004j5-TC for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Oct 2021 06:09:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mWBjc-0007nk-93 for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Oct 2021 06:09:28 +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 1mWBjc-0007nc-2F for pgsql-bugs@lists.postgresql.org; Fri, 01 Oct 2021 06:09:28 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mWBjZ-0004rN-T7 for pgsql-bugs@lists.postgresql.org; Fri, 01 Oct 2021 06:09:27 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 9415E5C019A; Fri, 1 Oct 2021 02:09:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 01 Oct 2021 02:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=vUFNEi7YTpdRTBfm7Nvfv425cYP NMKxvqZWNoX+MI5Y=; b=bCdNqyACbKle9rBPd+tJTUgZCD6ytEAA1yAhheuDmlZ K8D3WRa4mHlKl9zVv9wV9dQ1JDekB3Z+GvXvWqBcJt+C5iVGHlK/Kc3KAMCElBU8 ls0uQdKmSYEB1TEqienH7kx1F7/iEAtd2Te3epuIVX38+CUbWeRwe8xnWnPbWwzz qpGZNciys5Pvt82ytRUA+VpKYy6jpdFR9AEtR9HYRygPcv8pv+wJWsJJIVEMfZx1 ZtyaXmaxARCfeSMpGISPPFMJ6tRAQ+3eFewkj2ZlKlsWQX4MuCoVlEeF5CY69LF/ 1dpiJ9cs+eJHKjEuZa3rSGcJv5CSs+LI4mhmRT2GfAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=vUFNEi 7YTpdRTBfm7Nvfv425cYPNMKxvqZWNoX+MI5Y=; b=BBrReUpxvh881ab5+EgaXS y5dZduQiZUb4/NsqSinq9Invf9zhqXuWeaebTOHHvEZR6j8a974rsxDZX7zkC0+H DVCNtyrDKKQ+aEkOrTm6by+UHecsSEK1jlJECL40IGnwZz+bqRJ7u7CsAlXJI5to 8U9mrqpJV67vyJt/FBr0FMC1bxPssc5zUqRfcO7Qs06psrPffLJkXwwOucX4WAoS OXAcLAHJ2HkphE01QmRv3U1Ie1UyuXlqRmmw3mbVJVp59hY3Jjb4vk/y2nqcF7yI YGIO4xYUlgots28z32JXFOeh9NufQQkQL1ImRIXdjpaQyKTpE5Iyv3YoBSmk8hOg == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudekhedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhepff fhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepvdegudeuhfdtueeltedtveejheehieevueeigeelteegleejleeiueeiheegvefh necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitg hhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Oct 2021 02:09:22 -0400 (EDT) Date: Fri, 1 Oct 2021 15:09:19 +0900 From: Michael Paquier To: maxim.boguk@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17205: pg_class.reltuples vakue wrong for brin indexes after vacuum (by many orders of magnitude) Message-ID: References: <17205-42b1d8f131f0cf97@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="kZCWU+LvNhjqXPBk" Content-Disposition: inline In-Reply-To: <17205-42b1d8f131f0cf97@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --kZCWU+LvNhjqXPBk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 30, 2021 at 07:19:53AM +0000, PG Bug reporting form wrote: > pg_class.reltuples wrong by many order of magnitude after (auto)vacuum ta= ble > for brin indexes. > Analyze table set corrent value back, and following vacuum set it wrong > again (so correctness of value in production db depend on exact sequence = of > autovacuu/autoanalyze runs). >=20 > mboguk=3D# vacuum t; > VACUUM > mboguk=3D# select reltuples from pg_class where relname=3D't_brin'; > reltuples=20 > ----------- > 345 > (1 row) This information comes from the index cleanup done within vacuums, gets updated during vac_update_relstats() and computed by each index AM with their optional vacuum cleanup callback. For brin, that means calling brinvacuumcleanup where the summarization of the page ranges counts one tuple for each range tracked (see *numSummarized and *numExisting pointing at the same area to make sure that no tuples are missed), so this result of 345 is I guess correct. > mboguk=3D# analyze t; > ANALYZE > mboguk=3D# select reltuples from pg_class where relname=3D't_brin'; > reltuples =20 > -------------- > 9.999977e+06 > (1 row) This one is updated again with a vac_update_relstats(), but the number of index tuples is derived from the number of the parent's relation with the number updated based on a fractal number (here that would be 1.0 as the index is not partial). The thing is that we call index_vacuum_cleanup() for analyze runs that are not part of VACUUM, meaning that we do have the stats at hand, but just don't save them back into each the pg_class entry of the impacted index. It seems to me that we would finish with incorrect stats if we keep calling blindly vac_update_relstats() all the time for an analyze path. Even out-of-core AMs would not have their stats saved even if they pushed some numbers into their IndexBulkDeleteResult(), numbers that differ a bit with GIN actually, as it is the only in-core index AM that does some work during an analyze-only operation. Thoughts? -- Michael --kZCWU+LvNhjqXPBk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmFWpg8ACgkQnvQgOdby QH2GRg/+IhpTmJh7R/YYBaxNd2tqp96a2DqE3uM9gcm+skeEIzB2ars4LcK8uAWw Tc+2Oi60SAoONjrXEqjP+xhvBZf5t9pMGOC0b5ifvyBeLTO7Y8Tnku791JSxkTf/ sl6mgY7WE4VIL4vjVJdViqpOKWPxuqjksnuqgnVuth9+tENUs3X7/pr0Pl3PNqu9 syaNVuaBygzaqRmMfJFepoU+YUDpWcFvppn3RScsLXVRO0peJH/04KxmPkikFkfs u27i7Kntv/RohzaI5J0P6QpyRBCdZ+TkqY6H7GGlnOPuw2qwnxh+jZyuOe5/xf+z 4ozS7gw+XgqztoubbG4osUb3dQUYfyToZ8ZUup9MquVRcAgqFBMpl/5Y7nEC5r/f 7tX8EHDwoDlLrdE/O104b7zk9xPjPXxyA1jUe9dB7PqR+XgwG8ljFDBUax63Iq2J nmSMJnZ76kTf7aIAJdrRMcf5SnbOZaP3M83ROUDCNgctqAhtcxj+eY3Pe+xjn86S d7K5D6iOjDySQsHs4OOjfRryXG1ikb6LOJWT+A+lShzHzkh0QP/sVdCmodyawTBg hm2e8iAXy6iHUfhhirtAi7Wicr0wwhr9MLpLepkH4bdETjhk6lngut9UlE25g3Vk B6yb0xsYo+b3OIpRzHBxHifUAwG1ZcA/RjCANvmKBL4Z4+6DV3E= =theN -----END PGP SIGNATURE----- --kZCWU+LvNhjqXPBk--