Skip to content

Commit

Permalink
Fold multiple Filter nodes into one
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Sep 6, 2022
1 parent a49ff58 commit 2992b0c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/FilterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public override IDataExecutionPlanNodeInternal FoldQuery(IDictionary<string, Dat

var foldedFilters = false;

foldedFilters |= FoldConsecutiveFilters();
foldedFilters |= FoldNestedLoopFiltersToJoins(dataSources, options, parameterTypes, hints);
foldedFilters |= FoldInExistsToFetchXml(dataSources, options, parameterTypes, hints, out var addedLinks);
foldedFilters |= FoldTableSpoolToIndexSpool(dataSources, options, parameterTypes, hints);
Expand All @@ -155,6 +156,23 @@ public override IDataExecutionPlanNodeInternal FoldQuery(IDictionary<string, Dat
return this;
}

private bool FoldConsecutiveFilters()
{
if (Source is FilterNode filter)
{
filter.Filter = new BooleanBinaryExpression
{
FirstExpression = filter.Filter,
BinaryExpressionType = BooleanBinaryExpressionType.And,
SecondExpression = Filter
};
Filter = null;
return true;
}

return false;
}

private bool FoldNestedLoopFiltersToJoins(IDictionary<string, DataSource> dataSources, IQueryExecutionOptions options, IDictionary<string, DataTypeReference> parameterTypes, IList<OptimizerHint> hints)
{
// Queries like "FROM table1, table2 WHERE table1.col = table2.col" are created as:
Expand Down

0 comments on commit 2992b0c

Please sign in to comment.