| From: | 陈列行 <2320415112(at)qq(dot)com> |
|---|---|
| To: | Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: BUG #19572: Redundant predicate changes JIT decision and causes an 18x performance difference |
| Date: | 2026-07-30 06:44:29 |
| Message-ID: | tencent_10669405A4B4ACADC37A29811DDD81AC260A@qq.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Thanks for the detailed analysis.
You are completely right—the query produces correct results, so it's an estimation/costing issue rather than a correctness bug.
Regarding whether it's worth addressing:
In real-world applications, especially those using ORMs or complex auto-generated SQL, redundant predicates (or transitive quals across joins) are actually quite common. When a redundant qual causes the estimated row count to drop significantly, it can severely distort the plan choice or prematurely cross cost thresholds (like JIT enablement, as seen here).
If exact duplicate qual detection (or a quick check via list membership before adding clauses) can be done at negligible planning cost, it seems like a very beneficial optimization for generator-heavy workloads.
Thanks again!
原始邮件
发件人:Matheus Alcantara <matheusssilv97(at)gmail(dot)com>
发件时间:2026年7月30日 01:44
收件人:2320415112 <2320415112(at)qq(dot)com>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>
主题:Re: BUG #19572: Redundant predicate changes JIT decision and causes an 18x performance difference
On Wed Jul 22, 2026 at 4:34 AM -03, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference: 19572
> Logged by: cl hl
> Email address: 2320415112(at)qq(dot)com
> PostgreSQL version: 17.10
> Operating system: Linux LAPTOP-2SQAVLB0 6.6.87.2-microsoft-standard-
> Description:
>
> ## Description
>
> This issue concerns a predicate that already applies to one side of an inner
> join and is redundantly copied into the join condition. The transformation
> is semantics-preserving. PostgreSQL retains both copies and treats their
> selectivities as independent, even though they are identical. The
> underestimated row count lowers the total plan cost enough to change whether
> expensive JIT inlining and optimization are enabled.
>
> ### Expected Behaviour
>
> PostgreSQL should recognize identical predicates or account for their
> complete correlation. Adding a redundant copy should not change cardinality
> estimates, cross a JIT threshold, or produce a large execution-time
> difference between equivalent queries.
>
AFAICT the planner treats each AND clause as an independent condition
and multiplies their selectivities together. So in the duplicated case
it estimates that the Seq Scan on redundant_join_fact returns fewer rows
because there are "more" filters, even though the two are identical.
Note the actual row counts are the same in both plans, only the estimate
changes, so the results are correct. This is a cardinality-estimation
that happens to cross the JIT cost threshold. So I think that this is an
expected behavior rather than a bug, though I may be wrong.
But I'm wondering whether the planner should detect duplicated quals and
drop the redundant qual, or more generally recognize when one qual
implies another (if qual1 is true, qual2 is always true) and remove
qual2. We already have predicate_implied_by() in predtest.c, but IIUC
it's currently only used for partial indexes, partition pruning, and
constraint exclusion, but I'm not sure if it can be used for such case.
I'm not sure it's worth doing for the general case given the possible
added planning time, but exact duplicate detection might be cheap enough
to be worthwhile, but also I'm not sure if it's a common pattern to make
it worh implementing it. Any thoughts?
--
Matheus Alcantara
EDB: https://www.enterprisedb.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tristan Partin | 2026-07-30 06:53:28 | Re: BUG #19587: hashchar (internal "char" type) depends on platform char signedness |
| Previous Message | Michael Paquier | 2026-07-30 06:26:11 | Re: BUG #19586: money division overflow |