model-writtenrun 9722 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
Jul - Aug 2018 · 4 entries
- Andrew Gierth opened the thread with an older proof of concept that replaced CTE references with subqueries and assumed future syntax for forcing materialization, inviting others to continue development in #1.
- The initial discussion weighed compatibility against optimization: Tom Lane favored preserving materialization for multiply referenced CTEs in #5, while Andres Freund advocated explicit MATERIALIZED syntax instead of relying on OFFSET tricks in #9.
- David Fetter rebased the prototype and updated regression expectations in #13; Andrew Gierth traced remaining wrong results to repeated evaluation of volatile functions in #14, leading to the guard in #19.
- Thomas Munro found a postgres_fdw regression failure in #22, which David Fetter addressed in #23, and later demonstrated that CTE inlining enabled parallel plans with substantially faster execution in #25.
Oct 2018 - Apr 2019 · 14 entries
- Andreas Karlsson resumed development, questioning volatile-function semantics and the complicated traversal in #27, then added AS MATERIALIZED syntax in #28.
- Tom Lane's detailed review in #35 called for safe query copying, clearing obsolete RTE fields, explicit traversal order, preserved materialized test coverage, deparsing support, and better documentation; Andrew Gierth opposed forcing materialization merely because OFFSET or LIMIT appeared in #37.
- After a development gap, Andreas Karlsson implemented the BEFORE/AFTER walker interface and rewrote the inlining traversal in #41, while adding deparsing and dedicated regression coverage.
- Andrew Gierth clarified locking compatibility in #42 and #43; Andreas Karlsson then excluded volatile functions and nested row-locking queries in #46, and added materialization-sensitive pg_stat_statements fingerprints in #65.
- The policy discussion moved toward explicit control in both directions: Robert Haas argued for a NOT MATERIALIZED option in #48 and explained how separately optimizing multiple references could outperform materialization in #60.
- Tom Lane extracted Andreas Karlsson's query-walker work into 18c0da88a5, with comment and flag-layout adjustments, then posted the cleaned-up CTE remainder in #67.
- Tom Lane settled on inlining safe singly referenced CTEs by default, preserving materialization for multiple references unless explicitly overridden, and implemented those rules with documentation and tests in #68.
- Andrew Gierth explained that existing queries could use CTEs deliberately to constrain bad plans and proposed leaving room for future cost-based choices in #70; Tom Lane's later revision documented optimization fences but retained the guarantee against default duplicate evaluation in #88.
- Tom Lane also tried extensible MATERIALIZE ON/OFF syntax in #88, but the final discussion favored the simpler MATERIALIZED / NOT MATERIALIZED spelling, including Peter Eisentraut's reasoning in #96 and #97.
- The main feature landed as 608b167f9f, combining the latest implementation and documentation with the earlier keyword syntax and a catalog-version bump; Tom Lane announced the landing in #103.
- Andrew Gierth relayed Yaroslav Schekin's wrong-results example in #107: forcing a multiply referenced CTE to inline inside a recursive query created multiple worktable scans and changed the result from twenty-two rows to four.
- Tom Lane considered lifting the multiple-worktable restriction and raised a separate concern about nested materialization directives in #108; Andrew Gierth argued in #111 that explicitly inlining an outer CTE should permit separate materializations of its inner CTE.
- After the feature landed, Tatsuo Ishii reported a substantial TPC-DS query improvement in #112, while observing that other slow queries still suffered from poor plan choices.
- Tom Lane fixed the recursive case in 9476131278 by detecting outer recursive self-references and prohibiting their duplication, with regression tests; the closing message #113 confirms the fix and leaves conflicting nested materialization directives as a separate unresolved topic.