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 1svvq5-000nSo-QH for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Oct 2024 09:40:10 +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 1svvq5-00DOX7-4i for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Oct 2024 09:40:09 +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 1svvq4-00DOWy-QL for pgsql-bugs@lists.postgresql.org; Wed, 02 Oct 2024 09:40:08 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1svvq1-0027Am-Se for pgsql-bugs@lists.postgresql.org; Wed, 02 Oct 2024 09:40:07 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-71788bfe60eso4805630b3a.1 for ; Wed, 02 Oct 2024 02:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727862005; x=1728466805; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=gE9Ls1Lt4gUPLcvJ1Lemg+wbNC6OG7hb8/ZqB7Fq87c=; b=BteUXrMoqUmGPFEavnVgKixOcRpj/EZpq82jEI+5tX8P1KYqAyRX3a3z13R2ol2PAC xmKSLfRneD9Zk0rReEcpFh25L+ui1AwAe9r6SCN3tAqm4wI5aEXbe8KQT9CG2DzTS187 Cc1+nR7v0An86vbe6LhVb6A4ROGHRnklYhLQIq0JNwZa7r+m6dhHGYtQhIVtPKxZKFlk P/pb5vkLZa7b/03wGePWL4k+IQZ3n77F/dIrYGuwiVPd0yxuycZNEe4ncPFQcEZ76Xy7 CcNMoAiU36RCUj7rMtCZYHT/1pvG4yFoBCK/+NS10vZ2JQItv26BTD+Z1gMjBua3EcAR 1b9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727862005; x=1728466805; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gE9Ls1Lt4gUPLcvJ1Lemg+wbNC6OG7hb8/ZqB7Fq87c=; b=EKCGS9j+NoNQd/I6p7TDXrjVGKdhoK5nscaAOGWIbPnByZJVKnIbL0ypZS6Z1l7spn xiFzYnuMM1qMBrx/zxci90DPKPjbZ5FL1/K9RQfiJKnU1DoTayEwoAe52UmlQjndhbsK tFbbxvJK5SOPe5OS2hIZzxIH0SCTMsS/u6XFhI4akZe/zU3/vq09vdWUmBxv3TKzuE8G KuN0zh5+eUJeXZa6zz13Grooo64bf3tSONCCG30UP+KzYCwQV0OHYe4LgYAtA7oyoghO LuO2ZskELyN4xoBRIIPX2t+mv1HKFmRMA7CyLqFfcB2hJdCojrynmv4UKNSgzx6CLJ0g xw2Q== X-Forwarded-Encrypted: i=1; AJvYcCUQGZFuBm0EWmexJolzmg09BFgcfv0XJWHTPnwORQtsDvR9Kew/u7rVEtKK2bvACB/ssy3WV9igJqeN@lists.postgresql.org X-Gm-Message-State: AOJu0YyfnqrERpP4ld/likFNGH0SoeqvLVYzttHgzSLvrUaO8L/my865 FFMM9AC8tk7S+ktJJXH63TYEZj+PEI0ycwSzZcxTklrIdD7nw7Qu X-Google-Smtp-Source: AGHT+IHMFfOxYtTKrB20+0Od24psSW7x8hQdoXubYfADtj5I4TjeAAe7fSaJ/3KZ8/9vIIUQwP6MfA== X-Received: by 2002:a05:6a00:21c2:b0:70d:2725:ebe4 with SMTP id d2e1a72fcca58-71dc5c8f72fmr3948880b3a.13.1727862004897; Wed, 02 Oct 2024 02:40:04 -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 d2e1a72fcca58-71b2649c2bfsm9396613b3a.28.2024.10.02.02.40.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Oct 2024 02:40:04 -0700 (PDT) Message-ID: <6ea4b223-43c3-43f9-b405-b2bdc3e14445@gmail.com> Date: Wed, 2 Oct 2024 16:40:01 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18643: EXPLAIN estimated rows mismatch To: mingwei.tc@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form References: <18643-8d455145acd8243e@postgresql.org> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <18643-8d455145acd8243e@postgresql.org> 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 09:47, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18643 > Logged by: ming wei tan > Email address: mingwei.tc@gmail.com > PostgreSQL version: 12.20 > Operating system: Debian 12.20-1.pgdg120+1 (Docker) > Description: > > 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 > QUERY PLAN > ------------------------------------------------------ > Seq Scan on t2 (cost=0.00..35.50 rows=2537 width=4) > Filter: (c0 IS NOT NULL) > > > While, `EXPLAIN SELECT t2.c0 FROM t2 WHERE (t2.c0 IN (t2.c0)) OR (t2.c0 > > 4)` returns rows=858 > QUERY PLAN > ----------------------------------------------------- > Seq Scan on t2 (cost=0.00..48.25 rows=858 width=4) > Filter: ((c0 = c0) OR (c0 > 4)) I found one link, which is connected to your case: https://www.postgresql.org/message-id/flat/CAMjNa7cC4X9YR-vAJS-jSYCajhRDvJQnN7m2sLH1wLh-_Z2bsw%40mail.gmail.com there you can find answer to your question. In general - it is too expensive to test each clause (especially non-top level one) on possible evaluation into constant expression. -- regards, Andrei Lepikhov