a quicker empty check for group by

This commit is contained in:
Todd Gruben 2018-12-22 06:12:06 -06:00 committed by Matt Jaffee
parent aa0d64047d
commit 216fd0964a
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
3 changed files with 30 additions and 1 deletions

View file

@ -2854,7 +2854,7 @@ TOP:
}
gbi.rows[i].id = rowID
if gbi.rows[i].row.Count() == 0 {
if gbi.rows[i].row.IsEmpty() {
goto TOP // I wanted to just call nextAtIdx again, but if a bunch of
// rows in a row were 0, I was worried we'd get into a stack
// overflow situation

15
row.go
View file

@ -16,6 +16,7 @@ package pilosa
import (
"encoding/json"
"fmt"
"sort"
"github.com/pilosa/pilosa/roaring"
@ -42,6 +43,20 @@ func NewRow(columns ...uint64) *Row {
return r
}
func (r *Row) IsEmpty() bool {
fmt.Println("what", len(r.segments))
if len(r.segments) == 0 {
return true
}
for i := range r.segments {
if r.segments[i].n > 0 {
return false
}
}
return true
}
// Merge merges data from other into r.
func (r *Row) Merge(other *Row) {
var segments []rowSegment

View file

@ -111,3 +111,17 @@ func TestRow_Difference_Segment(t *testing.T) {
t.Fatalf("Test 2 Difference Results %v != expected %v\n", res.Columns(), exp)
}
}
func TestRow_IsEmpty(t *testing.T) {
r1 := pilosa.NewRow(1, ShardWidth)
r2 := pilosa.NewRow(0, 2*ShardWidth)
res := r2.Intersect(r1)
if r1.IsEmpty() {
t.Fatal("r1 Should Not Be Empty\n")
}
if !res.IsEmpty() {
t.Fatal("Result Should Be Empty\n")
}
}