pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements @ 2025-04-05 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2025-04-05 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH to INSERT/UPDATE/DELETE (and later MERGE). Moreover, since it was coded to deliberately block recursion to a WithClause, even updating raw_expression_tree_walker didn't save it. The upshot of this was that we didn't see references to outer CTE names appearing within an inner WITH, and would neither complain about disallowed recursion nor account for such references when sorting CTEs into a usable order. The lack of complaints about this is perhaps not so surprising, because typical usage of WITH wouldn't hit either case. Still, it's pretty broken; failing to detect recursion here leads to assert failures or worse later on. Fix by factoring out the processing of sub-WITHs into a new function WalkInnerWith, and invoking that for all the statement types that can have WITH. Bug: #18878 Reported-by: Yu Liang <luy70@psu.edu> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/18878-a26fa5ab6be2f2cf@postgresql.org Backpatch-through: 13 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/691836405f1ecae2368a0f2fdbfee3b2cb53375b Modified Files -------------- src/backend/parser/parse_cte.c | 152 ++++++++++++++++++++++++++----------- src/test/regress/expected/with.out | 8 ++ src/test/regress/sql/with.sql | 7 ++ 3 files changed, 124 insertions(+), 43 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements @ 2025-04-05 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2025-04-05 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH to INSERT/UPDATE/DELETE (and later MERGE). Moreover, since it was coded to deliberately block recursion to a WithClause, even updating raw_expression_tree_walker didn't save it. The upshot of this was that we didn't see references to outer CTE names appearing within an inner WITH, and would neither complain about disallowed recursion nor account for such references when sorting CTEs into a usable order. The lack of complaints about this is perhaps not so surprising, because typical usage of WITH wouldn't hit either case. Still, it's pretty broken; failing to detect recursion here leads to assert failures or worse later on. Fix by factoring out the processing of sub-WITHs into a new function WalkInnerWith, and invoking that for all the statement types that can have WITH. Bug: #18878 Reported-by: Yu Liang <luy70@psu.edu> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/18878-a26fa5ab6be2f2cf@postgresql.org Backpatch-through: 13 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5e7be43f4b8bfe77570e566b89f23fc73ea625dc Modified Files -------------- src/backend/parser/parse_cte.c | 152 ++++++++++++++++++++++++++----------- src/test/regress/expected/with.out | 8 ++ src/test/regress/sql/with.sql | 7 ++ 3 files changed, 124 insertions(+), 43 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements @ 2025-04-05 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2025-04-05 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH to INSERT/UPDATE/DELETE (and later MERGE). Moreover, since it was coded to deliberately block recursion to a WithClause, even updating raw_expression_tree_walker didn't save it. The upshot of this was that we didn't see references to outer CTE names appearing within an inner WITH, and would neither complain about disallowed recursion nor account for such references when sorting CTEs into a usable order. The lack of complaints about this is perhaps not so surprising, because typical usage of WITH wouldn't hit either case. Still, it's pretty broken; failing to detect recursion here leads to assert failures or worse later on. Fix by factoring out the processing of sub-WITHs into a new function WalkInnerWith, and invoking that for all the statement types that can have WITH. Bug: #18878 Reported-by: Yu Liang <luy70@psu.edu> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/18878-a26fa5ab6be2f2cf@postgresql.org Backpatch-through: 13 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ede29a1e400bc9d1488ec70ec5630b62ca071fd5 Modified Files -------------- src/backend/parser/parse_cte.c | 152 ++++++++++++++++++++++++++----------- src/test/regress/expected/with.out | 8 ++ src/test/regress/sql/with.sql | 7 ++ 3 files changed, 124 insertions(+), 43 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements @ 2025-04-05 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2025-04-05 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH to INSERT/UPDATE/DELETE (and later MERGE). Moreover, since it was coded to deliberately block recursion to a WithClause, even updating raw_expression_tree_walker didn't save it. The upshot of this was that we didn't see references to outer CTE names appearing within an inner WITH, and would neither complain about disallowed recursion nor account for such references when sorting CTEs into a usable order. The lack of complaints about this is perhaps not so surprising, because typical usage of WITH wouldn't hit either case. Still, it's pretty broken; failing to detect recursion here leads to assert failures or worse later on. Fix by factoring out the processing of sub-WITHs into a new function WalkInnerWith, and invoking that for all the statement types that can have WITH. Bug: #18878 Reported-by: Yu Liang <luy70@psu.edu> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/18878-a26fa5ab6be2f2cf@postgresql.org Backpatch-through: 13 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1980ec2bc99361bb6486bf1aaa836c95dd5d629e Modified Files -------------- src/backend/parser/parse_cte.c | 152 ++++++++++++++++++++++++++----------- src/test/regress/expected/with.out | 8 ++ src/test/regress/sql/with.sql | 7 ++ 3 files changed, 124 insertions(+), 43 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements @ 2025-04-05 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2025-04-05 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH to INSERT/UPDATE/DELETE (and later MERGE). Moreover, since it was coded to deliberately block recursion to a WithClause, even updating raw_expression_tree_walker didn't save it. The upshot of this was that we didn't see references to outer CTE names appearing within an inner WITH, and would neither complain about disallowed recursion nor account for such references when sorting CTEs into a usable order. The lack of complaints about this is perhaps not so surprising, because typical usage of WITH wouldn't hit either case. Still, it's pretty broken; failing to detect recursion here leads to assert failures or worse later on. Fix by factoring out the processing of sub-WITHs into a new function WalkInnerWith, and invoking that for all the statement types that can have WITH. Bug: #18878 Reported-by: Yu Liang <luy70@psu.edu> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/18878-a26fa5ab6be2f2cf@postgresql.org Backpatch-through: 13 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/754a3d82d79cc3d7040cfadaf9c8cd1579684ee6 Modified Files -------------- src/backend/parser/parse_cte.c | 139 +++++++++++++++++++++++++------------ src/test/regress/expected/with.out | 8 +++ src/test/regress/sql/with.sql | 7 ++ 3 files changed, 111 insertions(+), 43 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements @ 2025-04-05 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2025-04-05 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix parse_cte.c's failure to examine sub-WITHs in DML statements. makeDependencyGraphWalker thought that only SelectStmt nodes could contain a WithClause. Which was true in our original implementation of WITH, but astonishingly we missed updating this code when we added the ability to attach WITH to INSERT/UPDATE/DELETE (and later MERGE). Moreover, since it was coded to deliberately block recursion to a WithClause, even updating raw_expression_tree_walker didn't save it. The upshot of this was that we didn't see references to outer CTE names appearing within an inner WITH, and would neither complain about disallowed recursion nor account for such references when sorting CTEs into a usable order. The lack of complaints about this is perhaps not so surprising, because typical usage of WITH wouldn't hit either case. Still, it's pretty broken; failing to detect recursion here leads to assert failures or worse later on. Fix by factoring out the processing of sub-WITHs into a new function WalkInnerWith, and invoking that for all the statement types that can have WITH. Bug: #18878 Reported-by: Yu Liang <luy70@psu.edu> Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/18878-a26fa5ab6be2f2cf@postgresql.org Backpatch-through: 13 Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e276b58293d59f3c560e3322c1ac5b2c0e39af94 Modified Files -------------- src/backend/parser/parse_cte.c | 139 +++++++++++++++++++++++++------------ src/test/regress/expected/with.out | 8 +++ src/test/regress/sql/with.sql | 7 ++ 3 files changed, 111 insertions(+), 43 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2025-04-05 19:01 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2025-04-05 19:01 pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements Tom Lane <tgl@sss.pgh.pa.us> 2025-04-05 19:01 pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements Tom Lane <tgl@sss.pgh.pa.us> 2025-04-05 19:01 pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements Tom Lane <tgl@sss.pgh.pa.us> 2025-04-05 19:01 pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements Tom Lane <tgl@sss.pgh.pa.us> 2025-04-05 19:01 pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements Tom Lane <tgl@sss.pgh.pa.us> 2025-04-05 19:01 pgsql: Fix parse_cte.c's failure to examine sub-WITHs in DML statements Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox