-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle IN optimizer transformation of ordering to constant
Our InExpressionValuesExpanding visitor can turn an an IN expression to a constant (i.e. when the values list is empty), which is unsupported in orderings in SqlServer. Detect this and turn these expressions to a simple constant expression detectable by the SQL generator, which will generate (SELECT 1). Fixes #16375
- Loading branch information
Showing
8 changed files
with
114 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query.Pipeline | ||
{ | ||
/// <summary> | ||
/// Searches an expression tree for the first occurrence of a node meeting the given criteria, and returns that node. | ||
/// </summary> | ||
public class SearchingExpressionVisitor : ExpressionVisitor | ||
{ | ||
private Func<Expression, bool> _predicate; | ||
|
||
public Expression FoundExpression { get; private set; } | ||
|
||
public SearchingExpressionVisitor(Func<Expression, bool> predicate) | ||
{ | ||
_predicate = predicate; | ||
} | ||
|
||
public SearchingExpressionVisitor(Type searchForType) | ||
: this(searchForType.IsInstanceOfType) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Resets the visitor, making it ready to run again. | ||
/// </summary> | ||
public void Reset() | ||
{ | ||
FoundExpression = null; | ||
} | ||
|
||
public override Expression Visit(Expression node) | ||
{ | ||
// TODO: can be optimized by immediately returning null when a matching node is found (but must be handled everywhere...) | ||
|
||
if (FoundExpression == null && _predicate(node)) | ||
{ | ||
FoundExpression = node; | ||
} | ||
|
||
return base.Visit(node); | ||
} | ||
|
||
/// <summary>Visits the children of the <see cref="T:System.Linq.Expressions.BinaryExpression"></see>.</summary> | ||
/// <param name="node">The expression to visit.</param> | ||
/// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns> | ||
protected override Expression VisitBinary(BinaryExpression node) | ||
{ | ||
return base.VisitBinary(node); | ||
} | ||
} | ||
} |
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
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