Re: BUG #18935: The optimiser's choice of sort doubles the execution time. - Mailing list pgsql-bugs

From Laurenz Albe
Subject Re: BUG #18935: The optimiser's choice of sort doubles the execution time.
Date
Msg-id 4d33efcf76aa2a7d48c90c74e1889f4a571a787e.camel@cybertec.at
Whole thread Raw
In response to BUG #18935: The optimiser's choice of sort doubles the execution time.  (PG Bug reporting form <noreply@postgresql.org>)
List 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



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #18935: The optimiser's choice of sort doubles the execution time.
Next
From: Alena Rybakina
Date:
Subject: Re: BUG #18935: The optimiser's choice of sort doubles the execution time.