Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500 - Mailing list pgsql-hackers

From Laurenz Albe
Subject Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500
Date
Msg-id c7d386a5042b074f7228c9b47b2774b1239ba54c.camel@cybertec.at
Whole thread Raw
In response to Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Thu, 2023-11-16 at 22:38 -0500, Tom Lane wrote:
> That line of argument also leads to the conclusion that it'd be
> okay to expose info about the ordering of the CTE result to the
> upper planner.  [...]  The fence is sort of one-way
> in this line of thinking: information can propagate up to the outer
> planner level, but not down into the CTE plan.
>
> Thoughts?

That agrees with my intuition about MATERIALIZED CTEs.
I think of them as "first calculate the CTE, then calculate the
rest of the query" or an ad-hoc temporary table for the duration
of a query.  I would expect the upper planner to know estimates
and other data about the result of the CTE.

Yours,
Laurenz Albe



pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500
Next
From: Andres Freund
Date:
Subject: Use of backup_label not noted in log