Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Jun 21, 2024
1 parent 539083d commit 9d81921
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
3 changes: 3 additions & 0 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/FilterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,9 @@ private bool FoldTableSpoolToIndexSpool(NodeCompilationContext context, IList<Op

private bool FoldFiltersToDataSources(NodeCompilationContext context, IList<OptimizerHint> hints, Dictionary<BooleanExpression, ConvertedSubquery> subqueryExpressions)
{
if (Filter == null)
return false;

var foldedFilters = false;

// Find all the data source nodes we could fold this into. Include direct data sources, those from either side of an inner join, or the main side of an outer join
Expand Down
8 changes: 4 additions & 4 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/FoldableJoinNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public override IDataExecutionPlanNodeInternal FoldQuery(NodeCompilationContext
// Left outer join - right key must be non-null
// Right outer join - left key must be non-null
if (JoinType == QualifiedJoinType.Inner || JoinType == QualifiedJoinType.RightOuter)
LeftSource = AddNotNullFilter(LeftSource, LeftAttribute, context, hints);
LeftSource = AddNotNullFilter(LeftSource, LeftAttribute, context, hints, false);

if (JoinType == QualifiedJoinType.Inner || JoinType == QualifiedJoinType.LeftOuter)
RightSource = AddNotNullFilter(RightSource, RightAttribute, context, hints);
RightSource = AddNotNullFilter(RightSource, RightAttribute, context, hints, false);

if (FoldSingleRowJoinToNestedLoop(context, hints, leftSchema, rightSchema, out folded))
return folded;
Expand All @@ -142,7 +142,7 @@ private IDataExecutionPlanNodeInternal PrependFilters(IDataExecutionPlanNodeInte
return folded;
}

private IDataExecutionPlanNodeInternal AddNotNullFilter(IDataExecutionPlanNodeInternal source, ColumnReferenceExpression attribute, NodeCompilationContext context, IList<OptimizerHint> hints)
protected IDataExecutionPlanNodeInternal AddNotNullFilter(IDataExecutionPlanNodeInternal source, ColumnReferenceExpression attribute, NodeCompilationContext context, IList<OptimizerHint> hints, bool required)
{
var schema = source.GetSchema(context);
if (!schema.ContainsColumn(attribute.GetColumnName(), out var colName))
Expand All @@ -163,7 +163,7 @@ private IDataExecutionPlanNodeInternal AddNotNullFilter(IDataExecutionPlanNodeIn

var folded = filter.FoldQuery(context, hints);

if (folded != filter)
if (required || folded != filter)
{
folded.Parent = this;
return folded;
Expand Down
23 changes: 2 additions & 21 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/HashJoinNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,8 @@ public override IDataExecutionPlanNodeInternal FoldQuery(NodeCompilationContext

// Make sure the join keys are not null - the SqlType classes override == to prevent NULL = NULL
// but .Equals used by the hash table allows them to match
LeftSource = new FilterNode
{
Source = LeftSource,
Filter = new BooleanIsNullExpression
{
Expression = LeftAttribute,
IsNot = true
}
}.FoldQuery(context, hints);
LeftSource.Parent = this;

RightSource = new FilterNode
{
Source = RightSource,
Filter = new BooleanIsNullExpression
{
Expression = RightAttribute,
IsNot = true
}
}.FoldQuery(context, hints);
RightSource.Parent = this;
LeftSource = AddNotNullFilter(LeftSource, LeftAttribute, context, hints, true);
RightSource = AddNotNullFilter(RightSource, RightAttribute, context, hints, true);

return this;
}
Expand Down

0 comments on commit 9d81921

Please sign in to comment.