mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Add FieldNotNull for more efficient BETWEEN queries
This commit is contained in:
parent
881a9f1351
commit
07ae881967
3 changed files with 32 additions and 0 deletions
10
executor.go
10
executor.go
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue