Re: BUG #18643: EXPLAIN estimated rows mismatch

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: mingwei(dot)tc(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, PG Bug reporting form <noreply(at)postgresql(dot)org>
Subject: Re: BUG #18643: EXPLAIN estimated rows mismatch
Date: 2024-10-02 09:40:01
Message-ID: 6ea4b223-43c3-43f9-b405-b2bdc3e14445@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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(dot)tc(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Ariel Tejera 2024-10-02 15:55:15 Re: Linux OOM killer
Previous Message Tomas Vondra 2024-10-02 08:47:42 Re: what are the things that occupy the session memory.