Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[release/9.0] Fix TPC equality check inside subquery predicate (#35120)#35201

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
roji merged 1 commit intodotnet:release/9.0-stagingfromroji:GetTable9
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
Fix TPC equality check inside subquery predicate (#35120)
Fixes#35118(cherry picked from commit3d0b86d)
  • Loading branch information
@roji
roji committedNov 25, 2024
commitb9fde6d141ea216b7c70c184bf4aea3dcc98e6f4
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
Expand DownExpand Up@@ -52,6 +53,9 @@ public sealed partial class SelectExpression : TableExpressionBase

private static ConstructorInfo? _quotingConstructor;

private static readonly bool UseOldBehavior35118 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue35118", out var enabled35118) && enabled35118;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand DownExpand Up@@ -1550,7 +1554,8 @@ public void ApplyPredicate(SqlExpression sqlExpression)
Left: ColumnExpression leftColumn,
Right: SqlConstantExpression { Value: string s1 }
}
when GetTable(leftColumn) is TpcTablesExpression
when (UseOldBehavior35118 ? GetTable(leftColumn) : TryGetTable(leftColumn, out var table, out _) ? table : null)
is TpcTablesExpression
{
DiscriminatorColumn: var discriminatorColumn,
DiscriminatorValues: var discriminatorValues
Expand All@@ -1573,7 +1578,8 @@ when GetTable(leftColumn) is TpcTablesExpression
Left: SqlConstantExpression { Value: string s2 },
Right: ColumnExpression rightColumn
}
when GetTable(rightColumn) is TpcTablesExpression
when (UseOldBehavior35118 ? GetTable(rightColumn) : TryGetTable(rightColumn, out var table, out _) ? table : null)
is TpcTablesExpression
{
DiscriminatorColumn: var discriminatorColumn,
DiscriminatorValues: var discriminatorValues
Expand All@@ -1597,7 +1603,8 @@ when GetTable(rightColumn) is TpcTablesExpression
Item: ColumnExpression itemColumn,
Values: IReadOnlyList<SqlExpression> valueExpressions
}
when GetTable(itemColumn) is TpcTablesExpression
when (UseOldBehavior35118 ? GetTable(itemColumn) : TryGetTable(itemColumn, out var table, out _) ? table : null)
is TpcTablesExpression
{
DiscriminatorColumn: var discriminatorColumn,
DiscriminatorValues: var discriminatorValues
Expand DownExpand Up@@ -2724,6 +2731,24 @@ private bool ContainsReferencedTable(ColumnExpression column)
return false;
}

private bool TryGetTable(ColumnExpression column, [NotNullWhen(true)] out TableExpressionBase? table, out int tableIndex)
{
for (var i = 0; i < _tables.Count; i++)
{
var t = _tables[i];
if (t.UnwrapJoin().Alias == column.TableAlias)
{
table = t;
tableIndex = i;
return true;
}
}

table = null;
tableIndex = 0;
return false;
}

private enum JoinType
{
InnerJoin,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5276,6 +5276,14 @@ public virtual async Task ToPageAsync_in_subquery_throws()

#endregion ToPageAsync

public override async Task Column_access_inside_subquery_predicate(bool async)
{
// Uncorrelated subquery, not supported by Cosmos
await AssertTranslationFailed(() => base.Column_access_inside_subquery_predicate(async));

AssertSql();
}

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

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5849,4 +5849,11 @@ public virtual Task Static_member_access_gets_parameterized_within_larger_evalua

private static string StaticProperty
=> "ALF";

[ConditionalTheory] // #35118
[MemberData(nameof(IsAsyncData))]
public virtual Task Column_access_inside_subquery_predicate(bool async)
=> AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => ss.Set<Order>().Where(o => c.CustomerID == "ALFKI").Any()));
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7461,6 +7461,21 @@ FROM [Orders] AS [o]
""");
}

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

AssertSql(
"""
SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE EXISTS (
SELECT 1
FROM [Orders] AS [o]
WHERE [c].[CustomerID] = N'ALFKI')
""");
}

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

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp