Fix dml function in for loops in with blocks. #8306
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Given the schema:
The query
with temp := (for x in {1,2,3} union(foo(x))) select temp.a
would produce:A similar result would appear if the dml function contained
update
ordelete
.This was caused by two related bugs:
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 byPathId
instead of theSet
directly. If the CTE is used in a view, then it may create a copy of theSet
with the same path.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.