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 1704236.1782746228@sss.pgh.pa.us
Whole thread
In response to PostgreSQL select-only CTE removal is too aggressive?  (Kirill Reshke <reshkekirill@gmail.com>)
Responses Re: PostgreSQL select-only CTE removal is too aggressive?
List pgsql-hackers
Kirill Reshke <reshkekirill@gmail.com> writes:
> I don't find where this behaviour is actually explicitly documented.

> For data-modifying CTEs we have this[1]:

> Data-modifying statements in WITH are executed exactly once, and
> always to completion, independently of whether the primary query reads
> all (or indeed any) of their output. Notice that this is different
> from the rule for SELECT in WITH: as stated in the previous section,
> execution of a SELECT is carried only as far as the primary query
> demands its output.

I don't see how this is not a direct, obvious consequence of that
rule.  The primary query demands none of the unreferenced CTE's
output, therefore it is not executed at all.

The referenced text in the "previous section" is

   This works because PostgreSQL's implementation
   evaluates only as many rows of a WITH query as are actually
   fetched by the parent query.

which is the same thing in slightly different words.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Why clearing the VM doesn't require registering vm buffer in wal record
Next
From: Bharath Rupireddy
Date:
Subject: Re: Report oldest xmin source when autovacuum cannot remove tuples