Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

sql/plan: more efficient implementation of GroupBy #332

Merged
merged 1 commit into from
Aug 16, 2018

Conversation

erizocosmico
Copy link
Contributor

Fixes #331

Before:

go test -benchmem -run=^$ gopkg.in/src-d/go-mysql-server.v0/sql/plan -bench ^BenchmarkGroupBy$

goos: darwin
goarch: amd64
pkg: gopkg.in/src-d/go-mysql-server.v0/sql/plan
BenchmarkGroupBy/no_grouping-4         	     500	   3735067 ns/op	 2468276 B/op	   10075 allocs/op
BenchmarkGroupBy/grouping-4            	     200	   6032010 ns/op	 2386503 B/op	   41453 allocs/op
PASS
ok  	gopkg.in/src-d/go-mysql-server.v0/sql/plan	4.124s

Now:

go test -benchmem -run=^$ gopkg.in/src-d/go-mysql-server.v0/sql/plan -bench ^BenchmarkGroupBy$

goos: darwin
goarch: amd64
pkg: gopkg.in/src-d/go-mysql-server.v0/sql/plan
BenchmarkGroupBy/no_grouping-4         	    1000	   1641740 ns/op	  321972 B/op	   10033 allocs/op
BenchmarkGroupBy/grouping-4            	     300	   4580011 ns/op	  677216 B/op	   40300 allocs/op
PASS
ok  	gopkg.in/src-d/go-mysql-server.v0/sql/plan	3.706s

Aggregations without a grouping clause are now more than 2x faster, 25-30% faster with grouping. Memory usage is an order of magnitude lower than before.

Even if having the code branching into grouping/no grouping and end up with some repeated code, I preferred that path because, as the benchmarks say, it's way faster and it's a pretty common use case to aggregate without grouping.

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
@erizocosmico erizocosmico requested a review from a team August 16, 2018 10:03
@ajnavarro ajnavarro merged commit 77f6b9b into src-d:master Aug 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants