From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Query plan regression between CTE and views
Date: Mon, 14 Aug 2023 10:44:35 -0500
Message-ID: <30357cd7-d085-88b3-ad33-47636578911c@gmail.com> (raw)
In-Reply-To: <CALBH9DDEFesJy-hS33dvS88krG0+XZDiPr1iG2_YQNyJZRwa-w@mail.gmail.com>
References: <CALBH9DDEFesJy-hS33dvS88krG0+XZDiPr1iG2_YQNyJZRwa-w@mail.gmail.com>
On 8/14/23 09:54, David Gilman wrote:
> I have a query that was originally written as a handful of CTEs out of
> convenience. It is producing a reasonable query plan because the CTE
> materialization was kicking in at an appropriate place. The CTEs
> aren't totally linear. The graph looks like this, where A, B, C and D
> are CTEs, and B -> A means B selects from A. In Graphviz format:
>
> G {
> B -> A;
> C -> A;
> C -> B;
> D -> C;
> }
>
> Out of curiosity I tried turning the query into a series of views and
> ran that query. The query plan is vastly different, there is no
> materialization and it runs much slower.
>
> My question is: is this a valid bug? I am not sure if I should expect
> the view version to find a way to materialize and produce a comparable
> query plan. Also, making a minimal test case is going to take a bit
> and I don't want to start unless this smells like a genuine bug.
What version of Postgresql?
(Also, back before, I think, v12, CTEs were optimizer fences. You were
better using views or sub-queries.)
--
Born in Arizona, moved to Babylonia.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: Query plan regression between CTE and views
In-Reply-To: <30357cd7-d085-88b3-ad33-47636578911c@gmail.com>
References: <CALBH9DDEFesJy-hS33dvS88krG0+XZDiPr1iG2_YQNyJZRwa-w@mail.gmail.com> <30357cd7-d085-88b3-ad33-47636578911c@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox