-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dml function in for loops in with blocks. (#8306)
Given the schema: ``` type Bar { required property a -> int64; }; function foo(x: int64) -> Bar { using ((insert Bar{ a := x })) }; ``` The query `with temp := (for x in {1,2,3} union(foo(x))) select temp.a` would produce: ``` {1, 1, 1, 2, 2, 2, 3, 3, 3} ``` A similar result would appear if the dml function contained `update` or `delete`. This was caused by two related bugs: 1. Sets can be compiled twice if they are DML and contained within a for loop within a with block. For normal DML statements, `CompilerContextLevel.dml_stmts` is used to track such CTEs and ensure that they are not duplicated. However, for inlined function arguments, this CTE was not tracked and was therefore duplicated and joined multiple times. The fix was to track the inlined argument CTEs using a newly added `CompilerContextLevel.inline_dml_ctes`. Unlike the iterator CTEs, these need to be tracked by `PathId` instead of the `Set` directly. If the CTE is used in a view, then it may create a copy of the `Set` with the same path. 2. Update and Delete did not apply iterator path bond to the statement body. This was not an issue with explicit DML, as the dml range could be relied on to merge in any iterators. However, this did not join in the new inlined argument CTE.
- Loading branch information
Showing
4 changed files
with
581 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.