-
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
Add COUNT(DISTINCT ...), SUM(DISTINCT ...), AVG(DISTINCT ...) #2568
Conversation
@@ -125,6 +130,19 @@ func (n *groupNode) Next() bool { | |||
for n.plan.Next() { | |||
values := n.plan.Values() | |||
for i, f := range n.funcs { | |||
if f.val.Distinct { | |||
encoded := make([]byte, 0, 100) |
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.
pretty sure in this case, you're just as well passing nil
typo in commit message: s/ADD/SUM/ |
@@ -99,6 +103,7 @@ type groupNode struct { | |||
render []parser.Expr | |||
funcs []*aggregateFunc | |||
needGroup bool | |||
seen []map[string]struct{} |
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.
Rather than a separate seen
slice that parallels the funcs
slice, could you place this map inside aggregateFunc
?
LGTM Seems like there are some opportunities to optimize distinct processing given the ordering, similar to what is done for |
524a15b
to
bbe2713
Compare
I've incorporated most of your feedback and added another commit that encodes tuples for SELECT DISTINCT. Thanks. |
@@ -196,11 +196,17 @@ func (v *extractAggregatesVisitor) Visit(expr parser.Expr, pre bool) (parser.Vis | |||
break | |||
} | |||
if impl, ok := aggregates[strings.ToLower(string(t.Name.Base))]; ok { | |||
seen := make(map[string]struct{}) |
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 unnecessarily allocates a map even when it's unused. How about:
f := &aggregateFunc{
val: aggregateValue{
FuncExpr: t,
},
impl: impl.New(),
}
if t.Distinct {
f.seen = make(map[string]struct{})
}
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.
sounds good
On Mon, Sep 21, 2015 at 3:12 PM Tamir Duberstein notifications@github.com
wrote:
In sql/group.go
#2568 (comment):@@ -196,11 +196,17 @@ func (v *extractAggregatesVisitor) Visit(expr parser.Expr, pre bool) (parser.Vis
break
}
if impl, ok := aggregates[strings.ToLower(string(t.Name.Base))]; ok {
seen := make(map[string]struct{})
This unnecessarily allocates a map even when it's unused. How about:
f := &aggregateFunc{
val: aggregateValue{
FuncExpr: t,
},
impl: impl.New(),
}if t.Distinct {
f.seen = make(map[string]struct{})
}—
Reply to this email directly or view it on GitHub
https://github.com/cockroachdb/cockroach/pull/2568/files#r40012456.
Whoops, no there isn't! LGTM modulo the extra map allocation. |
LGTM |
I was struggling to find a query that will return a tuple and not return an error. The test I have used to return a different error before the change. SELECT (2, 3) IN (SELECT DISTINCT (y, z) FROM xyz) doesn't work If we don't have a query available, I'll create a bug report and fix it in a different PR. |
0e0a484
to
f2ce174
Compare
Hmm, |
Looks like I messed up the commits. Let me put the right changes in the right commits |
f2ce174
to
1b39414
Compare
1b39414
to
9443b74
Compare
I think you can just squash these to one. |
Add COUNT(DISTINCT ...), SUM(DISTINCT ...), AVG(DISTINCT ...)
closes #2248