From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | mingwei(dot)tc(at)gmail(dot)com |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #18643: EXPLAIN estimated rows mismatch |
Date: | 2024-10-01 16:43:46 |
Message-ID: | 1860123.1727801026@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
PG Bug reporting form <noreply(at)postgresql(dot)org> 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.
In any case, in this toy example that lacks an ANALYZE step,
the selectivity estimates are mostly going to be garbage.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Ariel Tejera | 2024-10-01 18:17:47 | Linux OOM killer |
Previous Message | PG Bug reporting form | 2024-10-01 13:50:17 | BUG #18644: ALTER PUBLICATION ... SET (publish_via_partition_root) wrong/undocumented behavior. |