-
-
Notifications
You must be signed in to change notification settings - Fork 238
fix group by over empty result sets #1704
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
| // add to plan.GroupBy.SelectedExprs iff expression has an expression.GetField | ||
| hasGetField := false | ||
| transform.InspectExpr(e, func(expr sql.Expression) bool { | ||
| if _, ok := expr.(*expression.GetField); ok { | ||
| hasGetField = true | ||
| return true | ||
| } | ||
| return false | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // add to plan.GroupBy.SelectedExprs iff expression has an expression.GetField | |
| hasGetField := false | |
| transform.InspectExpr(e, func(expr sql.Expression) bool { | |
| if _, ok := expr.(*expression.GetField); ok { | |
| hasGetField = true | |
| return true | |
| } | |
| return false | |
| }) | |
| // add to plan.GroupBy.SelectedExprs iff expression has an expression.GetField | |
| hasGetField = transform.InspectExpr(e, func(expr sql.Expression) bool { | |
| _, ok := expr.(*expression.GetField) | |
| return ok | |
| }) |
| " └─ columns: [a]\n" + | ||
| "", | ||
| }, | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add some tests 1) with this transform preformed inside subqueries, making sure they stay cached afterwards (select * from xy join (select count(*) as u, 1 as v from ...) uv on x = u, and 2)) this transform performed inside subquery expressions, with semi/anti joins still being generated afterwards ( select ... where x in/not in (select y from (select count(*) as u, 1 as v from ...) uv), select ... where x =/!= (...), select * from xy where exists (select y from (select count(*) as u, 1 as v from ...) uv) where x = y))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and idk if this is valid, but can the projection be a subquery expression? select count(*), (select * from uv where u = x) from xy group by x
sql/analyzer/resolve_columns.go
Outdated
| return n, transform.SameTree, nil | ||
| } | ||
| if !ok || len(g.GroupByExprs) == 0 { | ||
| if !ok || len(g.GroupByExprs) == 0 { // TODO: this never happens because of above if??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the TODO action here?
If the "never happens" situation actually happens, how bad is it? Should we return an error or panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just a note for myself while I was looking through the code.
If we somehow make it to this condition and it evaluates to true, we would just do what we did in the previous block.
I'm pretty sure this block can be safely removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
fix for: dolthub/dolt#5683