Skip to content

Commit 4384ecc

Browse files
committed
Propagate CTE property flags when copying a CTE list into a rule.
rewriteRuleAction() neglected this step, although it was careful to propagate 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 executor certainly looks at that. The proposed test case only fails back to v10, but since the executor examines hasModifyingCTE in 9.x as well, I suspect that a test case could be devised that fails in older branches. Given the nearness of the release deadline, though, I'm not going to spend time looking for a better test. Report and patch by Greg Nancarrow, cosmetic changes by me Discussion: https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com
1 parent 5ad0337 commit 4384ecc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/rewrite/rewriteHandler.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ rewriteRuleAction(Query *parsetree,
504504
*
505505
* This could possibly be fixed by using some sort of internally
506506
* generated ID, instead of names, to link CTE RTEs to their CTEs.
507+
* However, decompiling the results would be quite confusing; note the
508+
* merge of hasRecursive flags below, which could change the apparent
509+
* semantics of such redundantly-named CTEs.
507510
*/
508511
foreach(lc, parsetree->cteList)
509512
{
@@ -525,6 +528,9 @@ rewriteRuleAction(Query *parsetree,
525528
/* OK, it's safe to combine the CTE lists */
526529
sub_action->cteList = list_concat(sub_action->cteList,
527530
copyObject(parsetree->cteList));
531+
/* ... and don't forget about the associated flags */
532+
sub_action->hasRecursive |= parsetree->hasRecursive;
533+
sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
528534
}
529535

530536
/*

0 commit comments

Comments
 (0)