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

Query: Insert Select 1 ordering for rownumber paging when there is no… #19317

Merged
merged 1 commit into from
Dec 16, 2019
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 @@ -1299,9 +1299,12 @@ private void AddJoin(
{
var partitions = new List<SqlExpression>();
GetPartitions(joinPredicate, partitions);
var orderings = innerSelectExpression.Orderings.Any()
var orderings = innerSelectExpression.Orderings.Count > 0
? innerSelectExpression.Orderings
: innerSelectExpression._identifier.Select(e => new OrderingExpression(e, true));
: innerSelectExpression._identifier.Count > 0
? innerSelectExpression._identifier.Select(e => new OrderingExpression(e, true))
: new[] { new OrderingExpression(new SqlFragmentExpression("(SELECT 1)"), true) };

var rowNumberExpression = new RowNumberExpression(partitions, orderings.ToList(), limit.TypeMapping);
innerSelectExpression.ClearOrdering();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@ public override Task Project_uint_through_collection_FirstOrDefault(bool async)
return base.Project_uint_through_collection_FirstOrDefault(async);
}

[ConditionalTheory(Skip = "Issue#17246")]
public override Task Project_keyless_entity_FirstOrDefault_without_orderby(bool async)
{
return base.Project_keyless_entity_FirstOrDefault_without_orderby(async);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1635,5 +1635,14 @@ public virtual Task Project_uint_through_collection_FirstOrDefault(bool async)
ss => ss.Set<Customer>().Select(c => c.Orders.OrderBy(o => o.OrderID).FirstOrDefault())
.Select(e => MaybeScalar(e, () => e.EmployeeID)));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Project_keyless_entity_FirstOrDefault_without_orderby(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>().Select(c => ss.Set<CustomerView>().FirstOrDefault(cv => cv.CompanyName == c.CompanyName)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,25 @@ FROM [Orders] AS [o]
FROM [Customers] AS [c]");
}

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

AssertSql(
@"SELECT [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle]
FROM [Customers] AS [c]
LEFT JOIN (
SELECT [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle]
FROM (
SELECT [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], ROW_NUMBER() OVER(PARTITION BY [c0].[CompanyName] ORDER BY (SELECT 1)) AS [row]
FROM (
SELECT [c].[CustomerID] + N'' as [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]
) AS [c0]
) AS [t]
WHERE [t].[row] <= 1
) AS [t0] ON [c].[CompanyName] = [t0].[CompanyName]");
}

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

Expand Down