model-writtenrun 5573 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Tomas Vondra reported an assertion failure during CTE inlining with a view and correlated subquery, reproducible back to PostgreSQL 12 and avoided by MATERIALIZED, in #1.
- Richard Guo showed that a view was unnecessary and traced the stale reference count to removal of unused subquery target-list expressions, suggesting corresponding counter decrements in #2, #3, and #4.
- Tomas Vondra suggested delaying reference counting until after those expressions were removed as another possible solution in #5.
- Tom Lane rejected maintaining exact counts as insufficiently useful and posted a patch removing the cross-check while converting downstream CTE plan assertions into runtime errors in #6.
- Tomas Vondra reported that the patch worked for him and agreed with removing the assertion in #7.
- Tom Lane committed #6 with added regression tests as 92e7a53752, backpatched the fix through PostgreSQL 12, and confirmed completion in #8, leaving no outstanding work in the thread.