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

[TINY] Fix to #23121 - Query: improve optimization of "false==(expr)" #23239

Merged
merged 1 commit into from
Nov 12, 2020
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
3 changes: 1 addition & 2 deletions src/EFCore.Relational/Query/SqlNullabilityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using JetBrains.Annotations;
Expand Down Expand Up @@ -1195,7 +1194,7 @@ private SqlExpression OptimizeComparison(
// true != a -> !a
// false != a -> a
return sqlBinaryExpression.OperatorType == ExpressionType.Equal ^ leftBoolValue
? _sqlExpressionFactory.Not(right)
? OptimizeNonNullableNotExpression(_sqlExpressionFactory.Not(right))
: right;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public virtual void Where_contains_on_parameter_empty_array_with_relational_null
.Where(e => names.Contains(e.NullableStringA))
.Select(e => e.NullableStringA).ToList();

Assert.Equal(0, result.Count);
Assert.Empty(result);
}

[ConditionalFact]
Expand All @@ -737,7 +737,7 @@ public virtual void Where_contains_on_parameter_array_with_just_null_with_relati
.Where(e => names.Contains(e.NullableStringA))
.Select(e => e.NullableStringA).ToList();

Assert.Equal(0, result.Count);
Assert.Empty(result);
}

[ConditionalTheory]
Expand Down Expand Up @@ -1528,6 +1528,15 @@ await AssertQuery(
ss => ss.Set<NullSemanticsEntity1>().Where(e => e.NullableStringA != e.NullableStringB));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task False_compared_to_negated_is_null(bool async)
{
await AssertQuery(
async,
ss => ss.Set<NullSemanticsEntity1>().Where(e => false == (!(e.NullableStringA == null))));
}

private string NormalizeDelimitersInRawString(string sql)
=> Fixture.TestStore.NormalizeDelimitersInRawString(sql);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,16 @@ FROM [Entities1] AS [e]
WHERE (([e].[NullableStringA] <> [e].[NullableStringB]) OR ([e].[NullableStringA] IS NULL OR [e].[NullableStringB] IS NULL)) AND ([e].[NullableStringA] IS NOT NULL OR [e].[NullableStringB] IS NOT NULL)");
}

public override async Task False_compared_to_negated_is_null(bool async)
{
await base.False_compared_to_negated_is_null(async);

AssertSql(
@"SELECT [e].[Id], [e].[BoolA], [e].[BoolB], [e].[BoolC], [e].[IntA], [e].[IntB], [e].[IntC], [e].[NullableBoolA], [e].[NullableBoolB], [e].[NullableBoolC], [e].[NullableIntA], [e].[NullableIntB], [e].[NullableIntC], [e].[NullableStringA], [e].[NullableStringB], [e].[NullableStringC], [e].[StringA], [e].[StringB], [e].[StringC]
FROM [Entities1] AS [e]
WHERE [e].[NullableStringA] IS NULL");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down