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 1swDdI-002UYf-7z for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Oct 2024 04:40:08 +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 1swDdH-008nB2-DY for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Oct 2024 04:40:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1swDdH-008nAt-4n for pgsql-bugs@lists.postgresql.org; Thu, 03 Oct 2024 04:40:07 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1swDdE-002Eoo-KM for pgsql-bugs@lists.postgresql.org; Thu, 03 Oct 2024 04:40:05 +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 4934e2jp240413; Thu, 3 Oct 2024 00:40:02 -0400 From: Tom Lane To: Andrei Lepikhov cc: David Rowley , ming wei tan , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18643: EXPLAIN estimated rows mismatch In-reply-to: References: <18643-8d455145acd8243e@postgresql.org> <1860123.1727801026@sss.pgh.pa.us> <27ac7e14-05bb-40c6-85ad-ca6a0b61f512@gmail.com> Comments: In-reply-to Andrei Lepikhov message dated "Thu, 03 Oct 2024 11:23:14 +0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <240411.1727930402.1@sss.pgh.pa.us> Date: Thu, 03 Oct 2024 00:40:02 -0400 Message-ID: <240412.1727930402@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrei Lepikhov writes: > So, we already pass through the OR clauses. Why not to check semi-equal > clauses and remove duplicates even if not all clauses are such > duplicates? At least, it continually raises users' questions. It's difficult to justify spending extra planner cycles to optimize what are fundamentally stupidly-written queries. Who writes "X=X" in the first place? (Other than ORM authors who need to spend some time in a re-education camp.) And it would not be a trivial number of extra cycles, either. As pointed out in the commit message David mentioned, it's basically free to make this improvement when we're looking at a potential EquivalenceClass clause. We've already paid the cost of checking that the operator is a btree equality operator, and we know that the clause is at top level of WHERE (else we couldn't fuzz over the difference between false and null results), and besides we have to check whether it's "X=X" because not doing so causes some semantic problems for the EquivalenceClass machinery. In the case of a random clause-underneath-OR, we would have to make a brand new check whether it's btree equality, and we would have to somehow track whether we had descended to an expression level where "false and null are known equivalent" is no longer true. So I really doubt that a case can be made that that is worth doing. regards, tom lane