Skip to content

Group By and Outer Apply and Query Optimizations and, and... - #7543

Closed
tuespetre wants to merge 1 commit into
dotnet:devfrom
tuespetre:group-by-and-optimizations
Closed

tuespetre wants to merge 1 commit into
dotnet:devfrom
tuespetre:group-by-and-optimizations

Conversation

@tuespetre

@tuespetre tuespetre commented Feb 3, 2017 •

Copy link
Copy Markdown
Contributor

Okay, please don't be mad at me -- I'm feeling kind 👨‍🍳 of scrambled after my deep dive into this. It's a pretty big PR and touches a lot of things. I didn't plan on it being this way but as I was working on my initial goal (getting GROUP BY to work) I ended up breaking some things, and in order to fix them, other things broke, and I had to fix them, ad nauseum.

Now I've finally got the tests all passing (save for one SQLite oddity, but I will cover that in a sec) and successfully rebased onto the last month's worth of commits.

The gist of what I've done:

  • Added GROUP BY support
  • Added LEFT JOIN LATERAL/OUTER APPLY support
  • Optimized generated queries to avoid materialization whenever possible, resulting in much smaller SQL statements, less data over the wire, etc.

Now, there are several points I know still need to be covered:

  • Complex GroupBy keys
  • I'm suspicious of some of the test SQL output changes surrounding discriminator columns and would like to double-check
  • I think the whole QueryFlattener class and its factory could disappear, it's only used for one call now
  • Plenty more tests for GROUP BY

...I just thought that for as long as this has already taken, and for as large of a changeset as this is, I would get some kind of ball rolling here.

@dnfclas

dnfclas commented Feb 3, 2017

Copy link
Copy Markdown

Hi @tuespetre, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@tuespetre

Copy link
Copy Markdown
Contributor Author

There you go @langdonx, multi-part/complex/nested key support

@smitpatel

Copy link
Copy Markdown
Contributor

@tuespetre - If fix for certain issues are isolated and not required/related to group by translation then please create different PR. Multiple unrelated changes in same PR makes it harder to review.

@tuespetre

Copy link
Copy Markdown
Contributor Author

@smitpatel sorry, I know it's a large PR. Everything ended up being extremely intertwined, a total domino effect.

@tuespetre
tuespetre force-pushed the group-by-and-optimizations branch 2 times, most recently from 7bd42cd to a3b2caa Compare February 6, 2017 14:43
@tuespetre

Copy link
Copy Markdown
Contributor Author

@smitpatel I squashed the commits again and amended the notes. I've also just rebased onto upstream/dev with @maumar's changes from the weekend and am running tests before pushing up again.

@tuespetre
tuespetre force-pushed the group-by-and-optimizations branch from a3b2caa to a3e5efc Compare February 6, 2017 19:00
@tuespetre

Copy link
Copy Markdown
Contributor Author

Okay, I've finished rebasing and pushed.

@tuespetre
tuespetre force-pushed the group-by-and-optimizations branch 3 times, most recently from c5e0555 to 5652a69 Compare February 7, 2017 14:36
@tuespetre

Copy link
Copy Markdown
Contributor Author

I've just pushed again, this time to add and uncomment some GroupBy tests. At this point I'm going to wait for feedback (except to rebase periodically if I don't hear anything.)

@tuespetre
tuespetre force-pushed the group-by-and-optimizations branch from 5652a69 to 52561bd Compare February 9, 2017 15:48
@tuespetre

Copy link
Copy Markdown
Contributor Author

I've rebased to account for the changes merged into dev for commit b8fb258.

@maumar

maumar commented Feb 9, 2017

Copy link
Copy Markdown
Contributor

@tuespetre please try to break this PR into smaller components. In it's current form this PR is simply too big and too risky for us to take. (e.g. if one part of the fix regresses some behavior, we don't want to be looking for the culprit among the 100 changed files).

I would suggest trying to separate the small bug fixes first (e.g. fix to #7523) as well as the small refactorings you made (e.g. properly implementing VisitChildren on some of the Expressions).

It should also be possible to separate GroupJoin optimization (i.e. avoid unnecessary materialization) from the rest - we have a prototype of similar change which is fairly isolated (although 15 tests or so are still broken in it, so I might be wrong :) )

Moreover, breaking the PR to components would make it easier for you to perform the rebase - there are some decent size PRs coming from our end.

@tuespetre
tuespetre force-pushed the group-by-and-optimizations branch 3 times, most recently from 37e0558 to fcba9de Compare February 14, 2017 17:25
@tuespetre
tuespetre force-pushed the group-by-and-optimizations branch from d8b10a1 to afc00fc Compare February 16, 2017 16:32
@tuespetre

Copy link
Copy Markdown
Contributor Author

@smitpatel @maumar rebased again; also nitpicked through for any noisy pointless changes (added line breaks, methods shifted around, variable names, etc.) that I could find to clean them up. From ~100 files changed down to 70 now. It's getting down to the parts that are truly interdependent and cannot be easily split up (if at all.)

The main components remaining:

  • Changes to InExpression and ExistsExpression
  • The changes to what requires materialization, including group joins, which brings about the introduction of OUTER APPLY
  • The support for GROUP BY

I will look for any remaining opportunities I can find to split out other things, but I have tried tackling it a few different ways already and it gets to be impossible (apart from shaving off all of the GROUP BY work to leave the materialization and group join changes by themselves.) I have one idea for something that can be split out -- that is, getting rid of QueryFlattener -- but I'm not too sure that is really worth it outside of the bigger picture of the rest of the changes.

@smitpatel

Copy link
Copy Markdown
Contributor

@tuespetre - What are the issues addressed in this PR?
How groupjoin materialization optimization are related to group by translation?

@tuespetre

tuespetre commented Feb 17, 2017 •

Copy link
Copy Markdown
Contributor Author

@smitpatel

How groupjoin materialization optimization are related to group by translation?

Implementing GROUP BY translation required a lot of changes that broke some things, and fixing those things broke other things, and so on. After a month or so of painstaking work I finally had the tests passing and submitted this PR in its original form.

I can't explain exactly and concisely how it is related other than saying that I've tried to separate the changes and I'm just about at the point where there's nothing left to separate, other than submitting a new PR that has all of the materialization optimizations and leaving this PR to contain only the GROUP BY optimizations that depend on those materialization optimizations.

@tuespetre

tuespetre commented Feb 17, 2017 •

Copy link
Copy Markdown
Contributor Author

EDIT: son of a 🐩 I did not mean to do that

@tuespetre tuespetre closed this Feb 17, 2017
@tuespetre tuespetre reopened this Feb 17, 2017
@dnfclas

dnfclas commented Feb 17, 2017

Copy link
Copy Markdown

Hi @tuespetre, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@maumar

maumar commented Feb 17, 2017

Copy link
Copy Markdown
Contributor

@tuespetre I think separating GroupJoin materialization optimization is the right call here. Those are both really big features and I think that their combined complexity is still too risky for us to consider.
Moreover I think the GroupJoin materialization improvement, when separated from the GroupBy stuff could potentially be split into few different smaller PRs.
As long as there is incremental progress (and ideally a test of group of tests that show it) we will be MUCH more likely to consider the fix, rather than fixing it all at once.

Good examples of such small incremental improvements would be #7647 and #7648.

@tuespetre

Copy link
Copy Markdown
Contributor Author

I wish it were simpler to make incremental changes for this but once the 'query sources requiring materialization' is changed, there is a LOT of stuff that has to change. I've split off a branch for just the materialization changes (the tests are finishing up locally right now, I will push it soon) and it still has 66 affected files.

@maumar

maumar commented Feb 17, 2017

Copy link
Copy Markdown
Contributor

The way I was thinking about it was to start with only fixing cases where we don't produce client side GroupJoin. This makes it so that you don't need to tinker with with implementation of client _GroupJoin method and still provides significant value

@tuespetre

Copy link
Copy Markdown
Contributor Author

It's not going so well on #7663 (trying to remove the caching and still getting everything to pass.)

I don't think I'm going to be able to invest much more of my time into all of these optimizations I've worked on 😞

I know the initial changes were big and 'risky' and stuff. I started out targeting GROUP BY and just in getting that to work I made all of the other improvements. That's why splitting it apart is hard, I took a problem by the horns and really went to town on it, I didn't go the other way around and solve little problem by little problem and wait for some day to come when all of the other stuff was out of the way so that it would be 'easy' to implement GROUP BY.

But hey, all the tests passed and I think I added a lot of value (if performance is a feature.) But this is going on 3 weeks of trying to split out small components not to mention the month of work I put into it before that. Too many other things that need to get done, I'm afraid.

Sorry @smitpatel, @maumar, @anpete, @divega

@tuespetre tuespetre closed this Feb 23, 2017
@langdonx

Copy link
Copy Markdown

Oh, no! This is really sad news. :(

As it stands, EF Core is a no go for me because doing any sort of aggregate querying performs terribly on datasets with more than a few hundred records. This feature is the only thing standing in the way of me being able to go serverless on AWS.

Assuming there is good test coverage to begin with, if all existing tests pass, is it really that risky? If the tests aren't extensive, the sooner a PR like this gets merged, the more likely issues will be found and corrected before the next major release.

@maumar

maumar commented Feb 23, 2017

Copy link
Copy Markdown
Contributor

@tuespetre I'm sorry that the things didn't work out better with this PR. There are a lot of good ideas here and it should be very useful once we begin to tackle this issue (will make sure to give you credit where credit is due).

There will always be a problem with big PRs like this, as it's so much harder for us to understand all the ramifications if we haven't done the legwork ourselves. That's why we were pushing so hard to break this apart (I can imagine how frustrating it must have felt on your end). Breaking it apart really was critical to us as it makes it much easier for us to grok and make the risk acceptable. Also easier to revert and/or fix a more isolated change if we find a bug in it in the future.

I wish we were bit more responsive and also that the timing was better (i.e. we would not have had a couple of big PRs in the works at the same time). However, I'm glad that you managed to get some of those smaller PRs in, so hopefully the whole experience doesn't feel like a complete waste of time from your perspective (it certainly doesn't feel like that to us).

@maumar

maumar commented Feb 23, 2017

Copy link
Copy Markdown
Contributor

@langdonx We are afraid what impact such a big change could have on our long-term maintainability. We have a few sizable PRs in similar area (one of them is a rework of our eager loading, for instance). Some of those big changes would have to go on top of this PR. If we find some small bugs in it we could easily fix it for sure, but if there is a fundamental problem somewhere, it could be a real nightmare for us going forward.

@tuespetre

Copy link
Copy Markdown
Contributor Author

@MauMaur thank you, I do have one last idea of something I may be able to offer up out of this pile of code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants