Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7393751

Browse files
committed
Propagate CTE property flags when copying a CTE list into a rule.
rewriteRuleAction() neglected this step, although it was careful topropagate other similar flags such as hasSubLinks or hasRowSecurity.Omitting to transfer hasRecursive is just cosmetic at the moment,but omitting hasModifyingCTE is a live bug, since the executorcertainly looks at that.The proposed test case only fails back to v10, but since the executorexamines hasModifyingCTE in 9.x as well, I suspect that a test casecould be devised that fails in older branches. Given the nearnessof the release deadline, though, I'm not going to spend time lookingfor a better test.Report and patch by Greg Nancarrow, cosmetic changes by meDiscussion:https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com
1 parent4353bc8 commit7393751

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ rewriteRuleAction(Query *parsetree,
530530
*
531531
* This could possibly be fixed by using some sort of internally
532532
* generated ID, instead of names, to link CTE RTEs to their CTEs.
533+
* However, decompiling the results would be quite confusing; note the
534+
* merge of hasRecursive flags below, which could change the apparent
535+
* semantics of such redundantly-named CTEs.
533536
*/
534537
foreach(lc,parsetree->cteList)
535538
{
@@ -551,6 +554,9 @@ rewriteRuleAction(Query *parsetree,
551554
/* OK, it's safe to combine the CTE lists */
552555
sub_action->cteList=list_concat(sub_action->cteList,
553556
copyObject(parsetree->cteList));
557+
/* ... and don't forget about the associated flags */
558+
sub_action->hasRecursive |=parsetree->hasRecursive;
559+
sub_action->hasModifyingCTE |=parsetree->hasModifyingCTE;
554560
}
555561

556562
/*

‎src/test/regress/expected/with.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,33 @@ SELECT * FROM bug6051_2;
16721672
3
16731673
(3 rows)
16741674

1675+
-- silly example to verify that hasModifyingCTE flag is propagated
1676+
CREATE TEMP TABLE bug6051_3 AS
1677+
select a from generate_series(11,13) as a;
1678+
CREATE RULE bug6051_3_ins AS ON INSERT TO bug6051_3 DO INSTEAD
1679+
SELECT i FROM bug6051_2;
1680+
BEGIN; SET LOCAL force_parallel_mode = on;
1681+
WITH t1 AS ( DELETE FROM bug6051_3 RETURNING * )
1682+
INSERT INTO bug6051_3 SELECT * FROM t1;
1683+
i
1684+
---
1685+
1
1686+
2
1687+
3
1688+
1
1689+
2
1690+
3
1691+
1
1692+
2
1693+
3
1694+
(9 rows)
1695+
1696+
COMMIT;
1697+
SELECT * FROM bug6051_3;
1698+
a
1699+
---
1700+
(0 rows)
1701+
16751702
-- a truly recursive CTE in the same list
16761703
WITH RECURSIVE t(a) AS (
16771704
SELECT 0

‎src/test/regress/sql/with.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,22 @@ INSERT INTO bug6051 SELECT * FROM t1;
773773
SELECT*FROM bug6051;
774774
SELECT*FROM bug6051_2;
775775

776+
-- silly example to verify that hasModifyingCTE flag is propagated
777+
CREATE TEMP TABLE bug6051_3AS
778+
select afrom generate_series(11,13)as a;
779+
780+
CREATERULEbug6051_3_insASON INSERT TO bug6051_3 DO INSTEAD
781+
SELECT iFROM bug6051_2;
782+
783+
BEGIN;SET LOCAL force_parallel_mode=on;
784+
785+
WITH t1AS (DELETEFROM bug6051_3 RETURNING* )
786+
INSERT INTO bug6051_3SELECT*FROM t1;
787+
788+
COMMIT;
789+
790+
SELECT*FROM bug6051_3;
791+
776792
-- a truly recursive CTE in the same list
777793
WITH RECURSIVE t(a)AS (
778794
SELECT0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp