Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0-staging] Fix to #35208 - Query/Perf: don't compile liftable constant resolvers in interpretation mode #35211

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override ConstantExpression InlineConstant(LiftableConstantExpression
if (liftableConstant.ResolverExpression is Expression<Func<RelationalMaterializerLiftableConstantContext, object>>
resolverExpression)
{
var resolver = resolverExpression.Compile(preferInterpretation: true);
var resolver = resolverExpression.Compile(preferInterpretation: UseOldBehavior35208);
var value = resolver(_relationalMaterializerLiftableConstantContext);
return Expression.Constant(value, liftableConstant.Type);
}
Expand Down
5 changes: 4 additions & 1 deletion src/EFCore/Query/LiftableConstantProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ private sealed record LiftedConstant(
private readonly LiftedConstantOptimizer _liftedConstantOptimizer = new();
private ParameterExpression? _contextParameter;

protected static readonly bool UseOldBehavior35208 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35208", out var enabled35208) && enabled35208;

/// <summary>
/// Exposes all constants that have been lifted during the last invocation of <see cref="LiftedConstants" />.
/// </summary>
Expand Down Expand Up @@ -198,7 +201,7 @@ protected virtual ConstantExpression InlineConstant(LiftableConstantExpression l
// Make sure there aren't any problematic un-lifted constants within the resolver expression.
_unsupportedConstantChecker.Check(resolverExpression);

var resolver = resolverExpression.Compile(preferInterpretation: true);
var resolver = resolverExpression.Compile(preferInterpretation: UseOldBehavior35208);
var value = resolver(_materializerLiftableConstantContext);

return Expression.Constant(value, liftableConstant.Type);
Expand Down