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 1qDiQG-0004jH-ER for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jun 2023 09:22:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qDiQF-0007AB-Cr for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jun 2023 09:22:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qDiQE-00074w-Uc for pgsql-hackers@lists.postgresql.org; Mon, 26 Jun 2023 09:22:11 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qDiQB-000WG3-E5 for pgsql-hackers@lists.postgresql.org; Mon, 26 Jun 2023 09:22:09 +0000 Received: from [192.168.28.143] (unknown [192.168.28.143]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 8603AE20FD7; Mon, 26 Jun 2023 12:22:04 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1687771324; bh=cTEFAJe3O/0x6kr+JFYuQMOY3xMDZEsIEfJOYIevULk=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=R6CWsMe1Bur+Uqj0qT/rAnF+nqGuS3L/ApZuPZVhVMzBdZaZQ7mCVIGAh1zBHxwoD MOPYYlL2tMVRkqB0pc+/NHXrmK35V4jLSlam8KZJArpkae+5trWhfl/XN/XDmZ0W9M XcWqrpYQM+4DX/87/Vrr6qKB1QbEIDbkqmDrQMRouXP53cTCmf2zST8JOQrRQxHXLO M+N3OU+k3Cg8IDe//3jsfSIipbRxmIx0eGidctg9e9u7HapisJml24Eo6+yzdO1Bf6 LPCZBO6Tit7XVLStOlsX6sRFVSup7hN06MYuPambdw1zNVCHd92Z7cPOB0DzuS4+FS VtDaAaxVwELDg== Message-ID: <6ed3a29e-b4b9-e4b6-e8a1-b1d7d00bbd88@postgrespro.ru> Date: Mon, 26 Jun 2023 15:22:03 +0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: Problems with estimating OR conditions, IS NULL on LEFT JOINs To: Tomas Vondra , Tom Lane Cc: PostgreSQL Hackers References: <52b55b53-420a-722c-adbd-706922fc059b@enterprisedb.com> <104950.1687565314@sss.pgh.pa.us> <6dce55f4-e8f6-8e8e-b2af-b45ccff13598@enterprisedb.com> Content-Language: en-US From: Andrey Lepikhov Organization: Postgres Professional In-Reply-To: <6dce55f4-e8f6-8e8e-b2af-b45ccff13598@enterprisedb.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 24/6/2023 17:23, Tomas Vondra wrote: > I really hope what I just wrote makes at least a little bit of sense. Throw in one more example: SELECT i AS id INTO l FROM generate_series(1,100000) i; CREATE TABLE r (id int8, v text); INSERT INTO r (id, v) VALUES (1, 't'), (-1, 'f'); ANALYZE l,r; EXPLAIN ANALYZE SELECT * FROM l LEFT OUTER JOIN r ON (r.id = l.id) WHERE r.v IS NULL; Here you can see the same kind of underestimation: Hash Left Join (... rows=500 width=14) (... rows=99999 ...) So the eqjoinsel_unmatch_left() function should be modified for the case where nd1