-
Notifications
You must be signed in to change notification settings - Fork 934
Remove OrderByClause from query models with Contains, All and Any result operators #2510
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
Conversation
/cc @ngbrown |
You can't simply remove var ordersQuery = db.Orders
.Where(x => x.Employee.EmployeeId > 5)
.OrderBy(x => x.OrderId)
.Take(2);
var orderLinesFuture = db.OrderLines
.Where(x => ordersQuery.Any(o => o == x.Order))
.OrderBy(x => x.Id)
.ToFuture(); In case paging rewriter this OrdereBy and TOP goes to IN subquery so it's OK to remove it in outer query for select
*
from
OrderLines orderline0_
where
exists (
select
order1_.OrderId
from
Orders order1_
where
order1_.OrderId=orderline0_.OrderId
and (
order1_.OrderId in (
select
TOP (@p0) order2_.OrderId
from
Orders order2_
where
order2_.EmployeeId>@p1
order by
order2_.OrderId asc -- this order by CAN'T be removed
)
--order by order2_.OrderId asc -- this can be removed
)
)
order by
orderline0_.OrderLineId asc; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Yeah, it seems it runs a second time again. And removes after PagingRewriter.... |
@bahusoid ok. Seems to be fixed. |
Now it seems we are doing twice job that should be done only once by your code. How safe would it be to move
|
Not quite... |
This thing would not pick up the QueryModel which is processed by PagingRewriter. Or at least it should not. |
It' just got me thinking that #2480 doesn't fix subqueries with [Test(Description = "GH2479")]
public void OrdersWithSubquery9Count()
{
if (Dialect is MySQLDialect)
Assert.Ignore("MySQL does not support LIMIT in subqueries.");
var ordersQuery = db.Orders
.Where(x => x.Employee.EmployeeId > 5)
.OrderByDescending(x => x.OrderId)
.Take(2);
var orderLinesFuture = db.OrderLines
.Where(x => ordersQuery.Count(o => o == x.Order) == 2)
.OrderBy(x => x.Id)
.ToFuture();
var orderLines = orderLinesFuture.ToList();
} Though for some reasons I don't see |
Not sure what you meant but calling So in theory we can just call it right from |
It is rewrited to |
But RemoveUnnecessaryBodyOperators needs to be called earlier because some other rewriters could be dependent on the removed queries. |
I meant calling it second time only when query is converted to Contains subquery. But maybe not as it's anyway doesn't handle Count |
@bahusoid how about that implementation? Let's deal with |
I like it |
Improvement for an unwanted behavior found on #2480