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 1uOhOJ-009ABw-Qz for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Jun 2025 18:38:40 +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 1uOhOG-00CAxP-OQ for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Jun 2025 18:38:37 +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 1uOhOG-00CAwq-91 for pgsql-hackers@lists.postgresql.org; Mon, 09 Jun 2025 18:38:37 +0000 Received: from forward501b.mail.yandex.net ([178.154.239.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uOhOE-0016EM-1W for pgsql-hackers@lists.postgresql.org; Mon, 09 Jun 2025 18:38:36 +0000 Received: from mail-nwsmtp-smtp-production-main-87.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-87.sas.yp-c.yandex.net [IPv6:2a02:6b8:c23:2ea3:0:640:da3e:0]) by forward501b.mail.yandex.net (Yandex) with ESMTPS id 4197461037; Mon, 9 Jun 2025 21:38:32 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-87.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id ScmgM5xLd0U0-libuzicm; Mon, 09 Jun 2025 21:38:31 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1749494311; bh=L9v39PiRjMpc/gIxDOOV7XQC7bQ3SqTzTNrhKi1zpBU=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=gTJYcmDN89taPrbdOCngwMHS9qIxAG8J9I9NVb496P3Lb8iWZMiEKmO1LZTxhaOp7 qwMdec+xgI13ZKpDpJF1r/3dtVHSa9c8MVtDgFEZ5AbT/zdgrDc5hP8wWxYqGM/JuM pXBsEntyuNMnIdGZyTBcOcA5vqcs6v0c/GWxcxOY= Authentication-Results: mail-nwsmtp-smtp-production-main-87.sas.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Message-ID: <2c54b453-dc12-4717-997f-b51370215139@tantorlabs.com> Date: Mon, 9 Jun 2025 21:38:27 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: using extended statistics to improve join estimates To: Tomas Vondra , Andrei Lepikhov , Andy Fan Cc: Julien Rouhaud , Andres Freund , pgsql-hackers@postgresql.org, Justin Pryzby , pgsql-hackers@lists.postgresql.org References: <2ed75657-e084-9539-c6de-597e5675014c@enterprisedb.com> <20211122012315.GH17618@telsasoft.com> <0213d237-efd5-8e7e-fa29-3f36e6e26023@enterprisedb.com> <1ea3bf2b-57f9-e632-251a-e718623d7a72@enterprisedb.com> <20220104235550.dgr4rz6zkjx2rykz@alap3.anarazel.de> <20220119101809.wzrjvh4jsnoakgny@jrouhaud> <20220302173821.GG15744@telsasoft.com> <20220302173943.GA28810@telsasoft.com> <87cyr89nk5.fsf@163.com> <2a9604a5-520d-48ee-b3c8-5f3342b607d3@enterprisedb.com> <866452b8-67b3-4f67-b85c-c3bb8e831ff2@postgrespro.ru> <87o790kgj3.fsf@163.com> <87a5khi8as.fsf@163.com> <5c9a1eee-c8ac-408b-95c4-ff388e5e12f0@postgrespro.ru> Content-Language: en-US From: Ilia Evdokimov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi hackers Еhank you for your work. Let me start my review from the top — specifically, in clausesel.c, the function clauselist_selectivity_ext(): 1. About check clauses == NULL. In my opinion, this check should be kept. This issue has already been discussed previously[0], and I think it's better to keep the safety check. 2. I noticed that the patch applies extended statistics to OR clauses as well. There's an example from regression tests illustrating this: Before applying ext stats: SELECT * FROM check_estimated_rows('select * from join_test_1 j1 join join_test_2 j2 on ((j1.a + 1 = j2.a + 1) or (j1.b = j2.b))');  estimated | actual -----------+--------     104500 | 100000 After applying ext stats: SELECT * FROM check_estimated_rows('select * from join_test_1 j1 join join_test_2 j2 on ((j1.a + 1 = j2.a + 1) or (j1.b = j2.b))');  estimated | actual -----------+--------     190000 | 100000 (1 row) I agree that, at least for now, we should focus solely on AND clauses. To do that, we should impose the same restriction in clauselist_selectivity_or() as we already do in clauselist_selectivity_ext(). What do you think? Or shall we consider OR-clauses as well? [0]: https://www.postgresql.org/message-id/flat/016e33b7-2830-4300-bc89-e7ce9e613bad%40tantorlabs.com -- Best regards, Ilia Evdokimov, Tantor Labs LLC.