Re: PostgreSQL select-only CTE removal is too aggressive? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: PostgreSQL select-only CTE removal is too aggressive?
Date
Msg-id 2028298.1782764526@sss.pgh.pa.us
Whole thread
In response to Re: PostgreSQL select-only CTE removal is too aggressive?  (Kirill Reshke <reshkekirill@gmail.com>)
List pgsql-hackers
Kirill Reshke <reshkekirill@gmail.com> writes:
> I have been thinking for a while about this optimization. The thing is,
> there is currently no way of forcing this CTE evaluation other than
> referencing it from other query parts. I think this is little clumsy. What
> if we use MATERIALIZE here for this purpose? So,
> WITH d as MATERIALIZED (select f()) select 1 ;
> will force evaluation? Does this strike you as good idea?

No.  What is the point?

Also, this would be far from a one-liner change.  Stopping the
planner from throwing away unreferenced CTEs wouldn't cause the
executor to run them.  Currently the executor only pays attention
to running ModifyTable nodes to completion.

The short answer here is that this feature has behaved like this since
we implemented it, in 2008 (cf commit 44d5be0e5).  AFAIR you are the
first to complain about it.  You should seriously consider the
possibility that it's you that are mistaken about the value of doing
things differently.  Even if there is some value, I think that
backwards compatibility would argue against changing the semantics.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: pg_createsubscriber --dry-run logging concerns
Next
From: Bharath Rupireddy
Date:
Subject: Multi-insert for logical replication apply