Re: BUG #18935: The optimiser's choice of sort doubles the execution time.

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: xiaohongjun(at)stu(dot)xidian(dot)edu(dot)cn, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18935: The optimiser's choice of sort doubles the execution time.
Date: 2025-05-19 15:23:58
Message-ID: 4d33efcf76aa2a7d48c90c74e1889f4a571a787e.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, 2025-05-19 at 12:42 +0000, PG Bug reporting form wrote:
> database4=# explain analyze SELECT t0.c0 FROM t0 INNER JOIN t1* ON
> ((t1.c0)=(((t1.c0)-(((((t1.c0)*('(-795716537,-245904803]'::int4range)))-(range_merge(t1.c0,
> t0.c0))))))) GROUP BY t0.c0;
>
> [explicitly disabling sort leads to a faster execution plan]

I see no bug here.
The join condition is so complicated that the planner has a hard
time estimating the number of result rows for the join.
It guesses way to low, so the sort is expensive, and avoiding it is cheaper.

The optimizer cannot be perfect, particularly in the face of complicated
expressions like that.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alena Rybakina 2025-05-19 15:47:05 Re: BUG #18935: The optimiser's choice of sort doubles the execution time.
Previous Message Tom Lane 2025-05-19 15:21:27 Re: BUG #18935: The optimiser's choice of sort doubles the execution time.