Re: SOLVED - RE: Poor performance using CTE - Mailing list pgsql-performance

From Tom Lane
Subject Re: SOLVED - RE: Poor performance using CTE
Date
Msg-id 15381.1353446809@sss.pgh.pa.us
Whole thread Raw
In response to Re: SOLVED - RE: Poor performance using CTE  (Jon Nelson <jnelson+pgsql@jamponi.net>)
List pgsql-performance
Jon Nelson <jnelson+pgsql@jamponi.net> writes:
> ... Perhaps even including a
> small blurb about what an optimization barrier even means (my
> understanding is that it merely forces materialization of that part of
> the query).

FWIW, it has nothing to do with materialization; it means that we don't
push conditions down into that subquery, nor pull subexpressions up out
of it, nor rearrange join order across the subquery boundary.  In short
the subquery is planned separately from the outer query.  But it could
then be run by the executor in the usual tuple-at-a-time fashion,
without materializing the whole subquery result.

It is true that CTEScan nodes materialize the subquery output (ie copy
it into a tuplestore), but that's to support multiple CTEScans reading
the same CTE.  One of the optimizations we *should* put in place
sometime is skipping the tuplestore if there's only one CTEScan on the
CTE.

            regards, tom lane


pgsql-performance by date:

Previous
From: Claudio Freire
Date:
Subject: Re: SOLVED - RE: Poor performance using CTE
Next
From: Craig Ringer
Date:
Subject: Re: SOLVED - RE: Poor performance using CTE