Add FieldNotNull for more efficient BETWEEN queries

This commit is contained in:
Travis 2017-10-05 11:52:14 -05:00
parent 881a9f1351
commit 07ae881967
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
3 changed files with 32 additions and 0 deletions

View file

@ -727,6 +727,10 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *
return nil, errors.New("Range(): BETWEEN condition requires exactly two integer values")
}
// The reason we don't just call:
// return f.FieldRangeBetween(fieldName, predicates[0], predicates[1])
// here is because we need the call to be slice-specific.
// Find field.
field := f.Field(fieldName)
if field == nil {
@ -744,6 +748,12 @@ func (e *Executor) executeFieldRangeSlice(ctx context.Context, index string, c *
return NewBitmap(), nil
}
// If the query is asking for the entire valid range, just return
// the not-null bitmap for the field.
if predicates[0] <= field.Min && predicates[1] >= field.Max {
return frag.FieldNotNull(field.BitDepth())
}
return frag.FieldRangeBetween(field.BitDepth(), baseValueMin, baseValueMax)
} else {

View file

@ -796,6 +796,23 @@ func TestExecutor_Execute_FieldRange(t *testing.T) {
}
})
t.Run("BETWEEN", func(t *testing.T) {
if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo >< [1, 1000])`), nil, nil); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) {
t.Fatalf("unexpected result: %s", spew.Sdump(result))
}
})
// Ensure that the FieldNotNull code path gets run.
t.Run("FieldNotNull", func(t *testing.T) {
if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=other, foo >< [0, 1000])`), nil, nil); err != nil {
t.Fatal(err)
} else if !reflect.DeepEqual([]uint64{0}, result[0].(*pilosa.Bitmap).Bits()) {
t.Fatalf("unexpected result: %s", spew.Sdump(result))
}
})
t.Run("BelowMin", func(t *testing.T) {
if result, err := e.Execute(context.Background(), "i", test.MustParse(`Range(frame=f, foo == 0)`), nil, nil); err != nil {
t.Fatal(err)

View file

@ -730,6 +730,11 @@ func (f *Fragment) fieldRangeGT(bitDepth uint, predicate uint64, allowEquality b
return b, nil
}
// FieldNotNull returns the not-null row (stored at bitDepth).
func (f *Fragment) FieldNotNull(bitDepth uint) (*Bitmap, error) {
return f.Row(uint64(bitDepth)), nil
}
func (f *Fragment) FieldRangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Bitmap, error) {
b := f.Row(uint64(bitDepth))
keep1 := NewBitmap() // GTE