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 1swDNA-002Slj-Te for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Oct 2024 04:23:29 +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 1swDNA-008Y6M-5B for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Oct 2024 04:23:28 +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 1swDN9-008Y39-So for pgsql-bugs@lists.postgresql.org; Thu, 03 Oct 2024 04:23:27 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1swDN7-002EiP-E5 for pgsql-bugs@lists.postgresql.org; Thu, 03 Oct 2024 04:23:26 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5399041167cso713418e87.0 for ; Wed, 02 Oct 2024 21:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727929402; x=1728534202; 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=wVQ+ucbwZCoek55WZqME4OBky1RJDDSOAH6vT2Ew6oA=; b=WQxKwtWVnA37MKsCwHdQhdHIdwbHJ3EL/iTrulQdhPZ4VMUajhd/vvik0FUO2FyU7H BFhyrM9d67JWAULPRmKjPiybpvBv9MYtlq7hb3WWQQp8cIXy4mgWb6uQUa7zSdHaijZm YNoR6dgvgMdsZc8K4Z6iCOEagkYNyhIz+zzyB9o9F67GaG8HJReITT0vC93YZFPB2uOv YMhpNfKYms3o+gG5Fk3bkRvzHBQIZyAFFIzTtT2eyk0kaqQohOukPjVLuITax0FUj3Iz KdvwesqdR0I0xiEeJ/TJqaLZfwq6pUzP7LmsFBFinAeHsYZ2qpha0aNqMVleur3RZ0E4 fzkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727929402; x=1728534202; 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=wVQ+ucbwZCoek55WZqME4OBky1RJDDSOAH6vT2Ew6oA=; b=rTMqyw8XkEUcB7GfxVW5hnUdjMnO9PksqDjZX9l5j1RQm7D/OJFFav5BYAacj3s6tZ dVVzUkoJL0N53Y/Qq0Exi5NEgkOTQebwnBTzDXXMLcN5p2ZrTralVh5jyHr7+qIRQtix ktISoMKgoTITXNLZ26P/0itEi/WD0P46/+0wgZ3dtgSPz/X0YKjfSDp3LXi6ZDRA2Adf qlLzkJVkI9g69Y2wl2CFp/+5qz9Etj7CxTol5hMsw7yZQlzEDfy9ShbDnL+caezklftC E6I7h3IP+Kw+LoQfqdxb/SgZ8PmX2sD7vcwdQ4Swpo7dR4kH6+O22EV4FowlljwUTlxW iYIA== X-Forwarded-Encrypted: i=1; AJvYcCXEwW1+Q6Zm7+Y4aGnE8Zj/NbDSQj+3uSFADMtdh/xxG9xVsBXwcekfJKWZGOUmGrPxg20eWzfIoz51@lists.postgresql.org X-Gm-Message-State: AOJu0YwcaeunqNSoucdjEkiF4dMKZ3lUeEWrVz61NQgfcTM2BO3Hs9jK tcJRP6r14wBhc3WiiMYl0N7kehbiYT851ccrcqq81c5b+UX5mn4p X-Google-Smtp-Source: AGHT+IHNBngHNBFGAyJmMC98NtM4N8lo8gDcG0gb0Fw+OXa7woINh9ynRRdby8WT4YoiDWJQLiZEuw== X-Received: by 2002:a05:6512:224a:b0:531:8f2f:8ae7 with SMTP id 2adb3069b0e04-539a0677474mr4744410e87.25.1727929401206; Wed, 02 Oct 2024 21:23:21 -0700 (PDT) Received: from [172.30.32.242] ([93.174.131.138]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-539a82abc2asm63870e87.301.2024.10.02.21.23.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Oct 2024 21:23:20 -0700 (PDT) Message-ID: Date: Thu, 3 Oct 2024 11:23:14 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18643: EXPLAIN estimated rows mismatch To: David Rowley , ming wei tan Cc: Tom Lane , pgsql-bugs@lists.postgresql.org References: <18643-8d455145acd8243e@postgresql.org> <1860123.1727801026@sss.pgh.pa.us> <27ac7e14-05bb-40c6-85ad-ca6a0b61f512@gmail.com> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: 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 03:57, David Rowley wrote: > On Thu, 3 Oct 2024 at 07:17, ming wei tan wrote: >> >> On 1/10/2024 18:43, Tom Lane wrote: >>> In any case, in this toy example that lacks an ANALYZE step, >>> the selectivity estimates are mostly going to be garbage. >> >> Thanks for the replies. I'm just checking if a bug is present here >> is a bug. Even with ANALYZE, the first EXPLAIN estimates more rows >> compared to the second, even though the second WHERE clause is >> less restrictive. > > I think you already checked that and Tom answered mentioning the > reason that this happens. > > We certainly could do better here, but, as Tom mentioned your example > does not seem convincing enough to warrant much effort. > > You should read the commit message in [1] as that might help you > understand the project's point of view for these sort of > optimisations. See in particular the first sentence of the second > paragraph. I can agree with the source reason. But presence of prepqual.c makes it less clear: Optimiser already attempts to remove duplicated ORs by the find_duplicate_ors function. And does it in some strange manner: explain SELECT oid,relname FROM pg_class WHERE oid=1 OR oid=1; Index Scan using pg_class_oid_index on pg_class Index Cond: (oid = '1'::oid) explain SELECT oid,relname FROM pg_class WHERE oid=1 OR oid=1 OR oid=2; Seq Scan on pg_class Filter: ((oid = '1'::oid) OR (oid = '1'::oid) OR (oid = 2)) 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. -- regards, Andrei Lepikhov