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 1svnKn-00HXmb-5m for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Oct 2024 00:35:17 +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 1svnKm-007ItD-CZ for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Oct 2024 00:35:16 +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 1svnKm-007It5-43 for pgsql-bugs@lists.postgresql.org; Wed, 02 Oct 2024 00:35:16 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1svnKf-0022fM-PB for pgsql-bugs@lists.postgresql.org; Wed, 02 Oct 2024 00:35:14 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7d666fb3fb9so199449a12.0 for ; Tue, 01 Oct 2024 17:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727829309; x=1728434109; 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=TgrPCSrdrKOp/q1ZR9nNNMVCV5Ezou3R5j2gzqDJTvU=; b=a2T1JUirmSMigHO5wzDtq91xg2m5UqsajvOp+xKHWZoJvUwTd6hNKBqkIIg7EzMg74 wuWoMr/Ryb+QBbjaOerHOk6J57v4biHDX5Co4jBjeMHuAya6y6L91hfH7+c/ru0Unr5g 3IHk4nd/rTDcXzhzIKtWvzKN5KV+bt//AHo3ilOo2KzDc3jvWHqJcqFFQITX2Ki5A9aP gI8hNP3YBAL0WwvP6y5KAEAJw7yJ5Op5rInR1Q+AbtnlK77aH7tDClUVqO+7n5dg6alN V+dtwF9AxP1sO0uwt3V099CLHfZP3baHiDnfJJVMLxV5v+iHV68Dy0PJjW0citZMCfX6 PtjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727829309; x=1728434109; 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=TgrPCSrdrKOp/q1ZR9nNNMVCV5Ezou3R5j2gzqDJTvU=; b=BdUB2CF8qPz/H/to/7av04d39noJ1rPUfQD/7cXQQJtCYsFG6SYXtNAWBhhVcHW8HQ +ARkQ5A6XmcMn3MJeOluqgZx3rndy6SWW8CKz8kGU2FsBxAXwWnwcwvlt0lxxn/Uh/kH CqzrWoERSGfUkr7PSm9no+ls6n6uCOCk5y/pAfLAGd3fhX7Mi7QwHVl+YTMTGVopAYJh v2Kgr3j9mqp2pz9YOK6I5XdvnvwaA2lff4fsdtr+Ip0mzb4kmDzEQZq9hP6iNdYHFYnJ r7Pr8iH1H64ZVyok6D6P4XXWE7XY6NRlnyJ5nr7t76BNzRx40FX5o8g4EX5yK0fmY0bB xwgQ== X-Gm-Message-State: AOJu0Yzvy3sh6XnRUkDSpgU1tT+XpESfdmSIo0E1peSRppTt/wgDYN9M e0J6KTVWRS4lVqP8/X/Aaq/gfQ4NWm68v0d23W2euTQDSMsoIRPw X-Google-Smtp-Source: AGHT+IEMeEULdTROL9Nq8biw1Lm5iGdAJQyL+8jiCQr3Lv86Ip7ACsSJ02/USCjQt7kQmyBUueHjeg== X-Received: by 2002:a05:6a20:2588:b0:1ce:d403:612d with SMTP id adf61e73a8af0-1d538980884mr3319879637.13.1727829308510; Tue, 01 Oct 2024 17:35:08 -0700 (PDT) Received: from [192.168.1.49] (cm-171-100-240-255.revip10.asianet.co.th. [171.100.240.255]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db2bce30sm7806325a12.38.2024.10.01.17.35.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 17:35:07 -0700 (PDT) Message-ID: <27ac7e14-05bb-40c6-85ad-ca6a0b61f512@gmail.com> Date: Wed, 2 Oct 2024 07:35:04 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18643: EXPLAIN estimated rows mismatch To: Tom Lane , mingwei.tc@gmail.com Cc: pgsql-bugs@lists.postgresql.org References: <18643-8d455145acd8243e@postgresql.org> <1860123.1727801026@sss.pgh.pa.us> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <1860123.1727801026@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 1/10/2024 18:43, Tom Lane wrote: > PG Bug reporting form writes: >> Given predicate A and B, it is expected that size (SELECT X where A) <= >> size (SELECT X WHERE A or B) >> However, `EXPLAIN SELECT t2.c0 FROM t2 WHERE t2.c0 IN (t2.c0)` returns >> rows=2537 > > I don't see any particular bug here. If you look closely at the > EXPLAIN output, you'll see that "t2.c0 IN (t2.c0)" is transformed > to "c0 IS NOT NULL" --- but only if it's at top level. So we're > estimating selectivities for two quite different conditions in > this example. > > The NOT NULL bit happens because a top-level equality clause > is transformed into an "EquivalenceClass", and then when we > notice the class has only one member, we prefer to spit out > "x IS NOT NULL" rather than "x = x". That has the same effect > (at top level of WHERE, anyway) and tends to be estimated > more accurately. I think their question was about why 'x IN (x)' transforms differently at the top and inside the OR clause. It is pretty typical question. -- regards, Andrei Lepikhov