On Fri, Nov 20, 2026 at 8:36 AM Andreas <[email protected]> wrote:
> I can confirm it is a real issue, we have it in a real application. The 
> application generates its SQL, and a typical statement has 250 scalar 
> sublinks (expr_N), around 100 subqueries with the same alias, around 170 CTEs 
> and a UNION ALL with about 100 arms.
>
> With 19.0 this statement needs about 78 ms for planning, with 18.7 about 40 
> ms. Same data, statistics and build options, and the execution time is the 
> same in both. In a profile about 40% of the planning time is strcmp() in 
> choose_plan_name(). For the whole application this makes the requests 3.5% 
> slower, the heavier ones 5-9%.

Well, that sucks. Sorry about that.

> You wrote that with a list also distinct names can make it O(N^2). We see 
> this too. When I change the statement so most subqueries have their own alias 
> and most scalar sublinks are gone, it still needs about 52 ms on 19.0 (40 ms 
> on 18.7), and most of the difference is still in choose_plan_name(). As far 
> as I see, your hash table idea would solve both cases for us.
>
> So for us this is for sure a real world use case. Generated SQL gets to these 
> numbers in normal use.

OK. Can you test Manu's latest patch and see how that does with your workload?

I would normally be somewhat reluctant to back-patch anything here,
but if people are hitting this on real workloads within days of
release, I think we should.

-- 
Robert Haas
Databricks


Reply via email to