Fwd: Very slow query performance when using CTE

From: Chris Joysn <joysn71(at)gmail(dot)com>
To: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Fwd: Very slow query performance when using CTE
Date: 2025-04-03 07:20:40
Message-ID: CAKRYhW1RwatKHzsYFXMjLUOcTONi1ZcLy6NAz12O6HwZQ7Rn7w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

unfortunately that increased the query execution time by a factor of 8:
https://explain.dalibo.com/plan/a6d2443d87fea1ee

On Tue, 1 Apr 2025 at 16:28, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Chris Joysn <joysn71(at)gmail(dot)com> writes:
> > I have an issue when using CTEs. A query, which consists of multiple
> CTEs,
> > runs usually rather fast (~5s on my environment). But it turned out that
> > using one CTE can lead to execution times of up to one minute.
> > That CTE is used two times within the query.
>
> Try labeling that CTE as NOT MATERIALIZED.
>
> regards, tom lane
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Chris Joysn 2025-04-03 07:21:25 Fwd: Very slow query performance when using CTE
Previous Message Andrei Lepikhov 2025-04-03 06:32:44 Re: partition table optimizer join cost misestimation