Re: Early WIP/PoC for inlining CTEs
Mike Rylander <mrylander@gmail.com>
From: Mike Rylander <mrylander@gmail.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Andres Freund <andres@anarazel.de>,
Thomas Munro <thomas.munro@enterprisedb.com>, Andreas Karlsson <andreas@proxel.se>,
Andrew Gierth <andrew@tao11.riddles.org.uk>, Tom Lane <tgl@sss.pgh.pa.us>, David Fetter <david@fetter.org>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2019-01-11T19:39:50Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Prevent inlining of multiply-referenced CTEs with outer recursive refs.
- 9476131278c7 12.0 landed
-
Allow user control of CTE materialization, and change the default behavior.
- 608b167f9f9c 12.0 landed
-
Split QTW_EXAMINE_RTES flag into QTW_EXAMINE_RTES_BEFORE/_AFTER.
- 18c0da88a5d9 12.0 landed
-
document when PREPARE uses generic plans
- fab9d1da4a21 9.6.0 cited
On Fri, Jan 11, 2019 at 2:10 PM Robert Haas <robertmhaas@gmail.com> wrote: > > On Fri, Jan 11, 2019 at 2:04 PM Andres Freund <andres@anarazel.de> wrote: > > > Maybe we could consider a more extensible syntax that is attached to > > > the contained SELECT rather than the containing WITH. Then CTEs would > > > be less special; there'd be a place to put hints controlling top-level > > > queries, subselects, views etc too (perhaps eventually join hints, > > > parallelism hints etc, but "materialize this" would be just another > > > one of those things). That'd be all-in. > > > > I think you have some purity arguments here, but the likelihood of us > > developing a full-blown solution is not that high, and the lack of > > inlinable CTEs is *really* hurting us. As long as the design doesn't > > block a full solution, if we go there, I think it's a very acceptable > > blemish in comparison to the benefits we'd get. > > Also, it seems to me that this is properly a property of the > individual WITH clause, not the query as a whole. > > I mean I suppose we could do > > WITH or_with_out_you OPTIONS (materialized false) AS (SELECT 'mariah > carey') SELECT ... > > That'd allow for extensibility, have the write scope, and look like > what we do elsewhere. It looks a little less elegant than > > WITH cte_name [[NOT] MATERIALIZED] AS (query) main_query... > > ...but maybe elegance for extensibility is a good trade. > Here, have $0.02 from the peanut gallery... I mildly prefer the latter, elegant spelling, but if CTE inlining does become a thing then I would /really/ want some way, any way, of telling Postgres that I want it to materialize a particular CTE. I use that currently-documented property of CTEs to structure large, complicated OLAP queries on a regular basis, for performance. Sometimes, such as when you have dozens of tables in a complex join tree, breaking the query into logically related chunks (which I know about, but the planner does not) via CTE is the only way to give the planner a fighting chance of finding a good plan. Otherwise you get stuck in the GEQO ghetto, or planning time is some non-trivial multiple of execution time. Thanks, -- Mike Rylander | Executive Director | Equinox Open Library Initiative | phone: 1-877-OPEN-ILS (673-6457) | email: miker@equinoxinitiative.org | web: http://equinoxinitiative.org