diff --git a/db/iterator.go b/db/iterator.go index 4347c002..f594834f 100644 --- a/db/iterator.go +++ b/db/iterator.go @@ -579,13 +579,15 @@ func (i *iterator) processTable(ctx context.Context, key *keys.Table) { beg := &keys.Thing{KV: key.KV, NS: key.NS, DB: key.DB, TB: key.TB, ID: keys.Ignore} end := &keys.Thing{KV: key.KV, NS: key.NS, DB: key.DB, TB: key.TB, ID: keys.Suffix} + min, max := beg.Encode(), end.Encode() + for x := 0; ; x = 1 { if !i.checkState(ctx) { return } - vals, err := i.e.dbo.GetR(i.versn, beg.Encode(), end.Encode(), 1000) + vals, err := i.e.dbo.GetR(i.versn, min, max, 1000) if err != nil { i.fail <- err return @@ -616,6 +618,8 @@ func (i *iterator) processTable(ctx context.Context, key *keys.Table) { beg.Decode(vals[len(vals)-1].Key()) + min = append(beg.Encode(), byte(0)) + } } diff --git a/db/select_test.go b/db/select_test.go index 2301820c..0b6eadc6 100644 --- a/db/select_test.go +++ b/db/select_test.go @@ -1073,6 +1073,25 @@ func TestSelect(t *testing.T) { }) + Convey("Group and retrieve more than 1000 records to test incremental processing", t, func() { + + setupDB() + + txt := ` + USE NS test DB test; + CREATE |person:1..10000|; + SELECT meta.tb, count(*) AS test FROM person GROUP BY meta.tb; + ` + + res, err := Execute(setupKV(), txt, nil) + So(err, ShouldBeNil) + So(res, ShouldHaveLength, 3) + So(res[1].Result, ShouldHaveLength, 10000) + So(res[2].Result, ShouldHaveLength, 1) + So(data.Consume(res[2].Result[0]).Get("test").Data(), ShouldEqual, 10000) + + }) + Convey("Order records ascending", t, func() { setupDB()