Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7Ldx-0055e9-1x for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Nov 2023 20:22:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r7Ldv-009IAa-ID for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Nov 2023 20:22:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7Ldv-009IAJ-8O for pgsql-hackers@lists.postgresql.org; Sun, 26 Nov 2023 20:22:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7Ldo-008ffw-Mo for pgsql-hackers@lists.postgresql.org; Sun, 26 Nov 2023 20:22:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3AQKM4WP3699084; Sun, 26 Nov 2023 15:22:04 -0500 From: Tom Lane To: Laurenz Albe cc: Paul A Jungwirth , PostgreSQL Hackers Subject: Re: Improve rowcount estimate for UNNEST(column) In-reply-to: References: Comments: In-reply-to Laurenz Albe message dated "Sun, 26 Nov 2023 21:11:59 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3699082.1701030124.1@sss.pgh.pa.us> Date: Sun, 26 Nov 2023 15:22:04 -0500 Message-ID: <3699083.1701030124@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Sat, 2023-11-25 at 09:19 -0800, Paul A Jungwirth wrote: >> Here is a patch to improve rowcount estimates for >> `UNNEST(some_array_column)`. Today we hard code this to 10, but we >> have statistics about array size, so it's easy to use them. > The idea sounds good to me. I didn't read the patch either yet, but it seems like a reasonable idea. > I didn't test or scrutinize the code, but I noticed that you use > EXPLAIN in the regression tests. I think that makes the tests vulnerable > to changes in the parameters or in the block size. Yes, this regression test is entirely unacceptable; the numbers will not be stable enough. Even aside from the different-settings issue, you can't rely on ANALYZE deriving exactly the same stats every time. Usually what we try to do is devise a query where the plan shape changes because of the better estimate. That typically will provide some insulation against small changes in the numerical estimates. regards, tom lane