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 1qCf1S-000184-5W for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jun 2023 11:32:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qCf1R-0007XD-0m for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jun 2023 11:32:13 +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 1qCeyL-00012q-Nh for pgsql-hackers@lists.postgresql.org; Fri, 23 Jun 2023 11:29:01 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qCeyI-003njW-FZ for pgsql-hackers@postgreSQL.org; Fri, 23 Jun 2023 11:29:00 +0000 Received: from [10.4.15.91] (unknown [93.174.131.141]) (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 74146E20F0A; Fri, 23 Jun 2023 14:28:55 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1687519735; bh=fE4PncA93saFpZQWsgLiN768kuNWuNq7DI0nnC9+YbA=; h=Message-ID:Date:User-Agent:Subject:To:References:From:In-Reply-To: From; b=M8sgXUhkHXmcVWhbHdASHRGgJQZwloKZDt6v5CHHgIaxtOAAF5oSVma67RCfd5lrv YNm/DLuffRO9VP/kCAQyg1l0LcoqG3CU3PoUOQMy31o1UWyqjvQUlFTh2agbTGdeqa iay6vZnsdxHZ7rkb5tQ8vvRH1wkEULa56vtgTZZS1cTyOIDO70sJm3Lwrcddcez4wL 07Zbg/0jPOF9+0zhyGYEK9o9sb6JWwIBeRuj9as32YHz7jDfhx/VmofLn546RZuBtB GtQr/SR/ikHNpdzgsk7+olD1C4VGdWKEyeej2n+tbmYGWgmnneba72uK/w9IYzXIJt Xkvdlk+K5FiGg== Message-ID: <296c33dd-0523-b91a-36ce-6f5f470aae2c@postgrespro.ru> Date: Fri, 23 Jun 2023 14:28:55 +0300 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: eqjoinsel_semi still sucks ... Content-Language: en-US To: Tom Lane , pgsql-hackers@postgreSQL.org References: <13290.1335976455@sss.pgh.pa.us> From: Andrey Lepikhov Organization: Postgres Professional In-Reply-To: <13290.1335976455@sss.pgh.pa.us> 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 2/5/2012 20:34, Tom Lane wrote: > On reflection I think that the idea of clamping ndistinct beforehand is > just wrong, and what we ought to do instead is apply a multiplier to the > selectivity estimate afterwards. In the case of a base rel we could > just multiply by the selectivity of its baserestrictinfo list. For join > rels it's a bit harder to guess how much a given input relation might > have been decimated, but if the join's estimated size is smaller than > the output size of the base rel the correlation var came from, we could > multiply by that ratio (on top of whatever correction came from the base > rel's restriction clauses). I got stuck in some cases where (due to a tree of filters) the planner underestimates the JOIN just because the ndistinct conveys a huge number to the selectivity estimation formula. However, the estimation of both input relations is made correctly and is limited. I've tried to understand the logic through commits 0d3b231eebf, 97930cf578e and 7f3eba30c9d. But it is still not clear. So, why the idea of clamping ndistinct is terrible in general? Could you explain your reasons a bit more? -- regards, Andrey Lepikhov Postgres Professional