Skip to content

Commit

Permalink
Fixed test for filter on outer join nested loop
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Sep 14, 2024
1 parent fd94f86 commit 3aa9eec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8497,9 +8497,11 @@ SELECT IIF(q1.name = 'Test1', 1, 0) AS [flag1],
Assert.AreEqual(1, plans.Length);

var select = AssertNode<SelectNode>(plans[0]);
var apply = AssertNode<NestedLoopNode>(select.Source);
var filter = AssertNode<FilterNode>(select.Source);
Assert.AreEqual("q2.flag1 = 1 OR q2.flag2 = 1", filter.Filter.ToSql());
var apply = AssertNode<NestedLoopNode>(filter.Source);
Assert.AreEqual(QualifiedJoinType.LeftOuter, apply.JoinType);
Assert.AreEqual("q2.flag1 = 1 OR q2.flag2 = 1", apply.JoinCondition.ToSql());
Assert.IsNull(apply.JoinCondition);
var fetch = AssertNode<FetchXmlScan>(apply.LeftSource);
var alias = AssertNode<AliasNode>(apply.RightSource);
var compute = AssertNode<ComputeScalarNode>(alias.Source);
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine/ExecutionPlan/FilterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private bool FoldFiltersToNestedLoopCondition(NodeCompilationContext context, IL
if (Filter == null)
return false;

if (!(Source is NestedLoopNode loop))
if (!(Source is NestedLoopNode loop) || loop.JoinType != QualifiedJoinType.Inner)
return false;

// Can't move the filter to the loop condition if we're using any of the defined values created by the loop
Expand Down

0 comments on commit 3aa9eec

Please sign in to comment.