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 1swF7Q-002d0x-Ec for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Oct 2024 06:15:21 +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 1swF7P-009zkp-D8 for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Oct 2024 06:15:19 +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 1swF7P-009zkh-4k for pgsql-bugs@lists.postgresql.org; Thu, 03 Oct 2024 06:15:19 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1swF7M-002FO9-Lu for pgsql-bugs@lists.postgresql.org; Thu, 03 Oct 2024 06:15:17 +0000 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2e188185365so499425a91.1 for ; Wed, 02 Oct 2024 23:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727936116; x=1728540916; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=P3Rz5S1Okh+uOsrc8pKSBlvuB9SxpfCqzNM7i/mwyU8=; b=QCOfotHn9zsKvZwtEaRe4jja0AAxdHWYMGDzpa6P5yLpfVTznum8bjnX5exa1PLQAk 6r5LKR97BB9t0DxAKF5fXj7mQkf3vASBHrFxAJWhpJOxWkwL3gmZzKTFwWN4YjRQqS+I 4hQWsymO5Yf1/wK2Yxv19+gH1XYRwDhtAK1ChN+9kZRB45gI+L90/AWla/6uGOXnZ+p6 JMGev7BTmB5+8mkRLqdtYwAxMXJHClzztNVr+0enrsF4f/qKLM2a3XvCgQH3Ekb3ZpVz gqgRrTqx5Di94U+WQGV/u+I8gTMLyMYv9ApNFwyX6pzqbOKAZv8y+zcRD7j10g3X46pZ dU3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727936116; x=1728540916; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P3Rz5S1Okh+uOsrc8pKSBlvuB9SxpfCqzNM7i/mwyU8=; b=Vkn6DEiljxuL+7uLsOHPD7yqgnejNC6LeplQNIJbhgZlVmmqbwwTnpVrEdpEqrHnde IBH0L1alJrfn0aTgoFHPioHZaieQ4TPlVl5h4rrPruH8Hn94byrr80l+BCT6p6/5eRLm C1UWjZyjBS8tJi9CiYh9mjcVTZptz7qD27zpEkl6DpCD6HSqGP3PPZ9Tv3hAE8h1N6oj qqe7nhBmLfY/AzA+t+VK3Zx/T+X8z1h1Jse7/fAquejZrs3mdyJYS/lnl6InxUkeN+Yq Fqlu9y8EgtUK5IgzC/cQXSxGKXo7MyfG1ZIrhf21XumDWvbXd7ieBzw50qoXAH7UiuLj HJ9A== X-Forwarded-Encrypted: i=1; AJvYcCWfN/wthdpfqhFfZP8ItZiGcc5SuvMlTrhnvxdgqHKK5nXXg9wzpFUfNVFdxMOUcNpbnqDf3fdmLS13@lists.postgresql.org X-Gm-Message-State: AOJu0Yw5md8FvM8NE9DDRThgtKxGj12so1oWmDb0uflAn/iDhTdSrRvn llOuDQVIuLrdDfwfHLFWAIMkpHaKLrjlAdRe+7M1A2hR+AXtjayP X-Google-Smtp-Source: AGHT+IFnXCKQbgpmDiVwWFqto0H4+4G4tlEeOJ9OpLtpty/MzmBdmIV+MKBfEKITXAcQs9FVMfxfKw== X-Received: by 2002:a17:90b:164f:b0:2e0:927a:6928 with SMTP id 98e67ed59e1d1-2e1846c5140mr7494719a91.24.1727936115518; Wed, 02 Oct 2024 23:15:15 -0700 (PDT) Received: from [10.10.20.99] (node-on7.pool-125-26.dynamic.totinternet.net. [125.26.124.195]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e1bff5347asm625791a91.49.2024.10.02.23.15.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Oct 2024 23:15:14 -0700 (PDT) Message-ID: <5abff03e-5eb5-482e-bbd5-809451ff24cb@gmail.com> Date: Thu, 3 Oct 2024 13:15:10 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18643: EXPLAIN estimated rows mismatch To: Tom Lane Cc: David Rowley , ming wei tan , pgsql-bugs@lists.postgresql.org References: <18643-8d455145acd8243e@postgresql.org> <1860123.1727801026@sss.pgh.pa.us> <27ac7e14-05bb-40c6-85ad-ca6a0b61f512@gmail.com> <240412.1727930402@sss.pgh.pa.us> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: <240412.1727930402@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 10/3/24 11:40, Tom Lane wrote: > 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.) I don't oppose your arguments at first. I want to say that ORMs and any APIs (I sometimes see data analysts who use an AI to request a database) are already essential to development (at least in startups). It may not be suitable to deal with such cases in the core, but it is too costly to do it in an extension right now. In this sense 'silicon' users aren't equal to more smart carbon-made ones. And here I see two options: 1. canonicalize_qual_hook - the most blunt approach. Of course, we will need more hooks in the near future with this approach. 2. An 'ORM' GUC to enable multiple optimisations in the core, 'smoothing' users' mistakes. It would be great to discuss other options. > 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. Thanks, this explanation is quite valuable for me. -- regards, Andrei Lepikhov