Re: Very slow query performance when using CTE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chris Joysn <joysn71(at)gmail(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Very slow query performance when using CTE
Date: 2025-04-01 14:28:58
Message-ID: 348393.1743517738@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Renan Alves Fonseca 2025-04-01 20:03:29 Re: Very slow query performance when using CTE
Previous Message Chris Joysn 2025-04-01 13:37:51 Very slow query performance when using CTE