-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
sql: add support for sorted GROUP BY results #3542
Comments
@petermattis At first glance, I appear to have two options for making
At present I think I'm leaning towards 2), after toying with 1), but wanted to solicit feedback before I got too invested in either approach. |
I was expecting we would have to do something like option 1. Option 2 seems a bit messier, though perhaps easier to get working. I think it would be nice if neither |
Fixes cockroachdb#3542. Unlike either approach (for nesting order of sortNode and groupNode) mentioned there, this PR just passes both sortBy and orderBy the original scanNode, letting them inspect and modify it directly, rather than having one delegate to the to the other and extracting some common interface for inspecting and modifying the render expressions. Note that sortBy, despite wrapping after groupBy, is given the first chance at the scanNode: this is important for two reasons: first, so that any aggregate expressions it adds will be properly transformed along with the rest of render by groupBy and second so that when looking for existing expressions that match, it does so before the their transformation into aggregatefuncs.
Fixes cockroachdb#3542. Unlike either approach (for nesting order of sortNode and groupNode) mentioned there, this PR just passes both sortBy and orderBy the original scanNode, letting them inspect and modify it directly, rather than having one delegate to the to the other and extracting some common interface for inspecting and modifying the render expressions. Note that sortBy, despite wrapping after groupBy, is given the first chance at the scanNode: this is important for two reasons: first, so that any aggregate expressions it adds will be properly transformed along with the rest of render by groupBy and second so that when looking for existing expressions that match, it does so before the their transformation into aggregatefuncs.
Currently, even once #3494 lands with initial
GROUP BY
support, we still error withunimplemented ORDER BY with GROUP BY/aggregation
if both aGROUP BY
andORDER BY
are used.As noted in the code, adding support will require some changes to how we do sorting (as it currently hooks into the scan node).
The text was updated successfully, but these errors were encountered: