syncbase: SyncQL: Support key expression operators: <,<=,>,>=,<>.
Rather than approximating key ranges (and, therefore, sometimes
iterating over more keys than necessary), this change computes
precise key ranges. At the same time, operators in key
expressions can now include <, <=, >, >= and <> (in addition to =
and like that were already supported).
Change-Id: I1bb96400169988664ea934e6b746982b62bd0be7
diff --git a/services/syncbase/server/nosql/database.go b/services/syncbase/server/nosql/database.go
index dd661ef..c78761a 100644
--- a/services/syncbase/server/nosql/database.go
+++ b/services/syncbase/server/nosql/database.go
@@ -406,30 +406,21 @@
func (t *tableDb) Scan(keyRanges query_db.KeyRanges) (query_db.KeyValueStream, error) {
streams := []store.Stream{}
for _, keyRange := range keyRanges {
- start := keyRange.Start
- limit := keyRange.Limit
- // 0-255 means examine all rows
- if start == string([]byte{0}) && limit == string([]byte{255}) {
- start = ""
- limit = ""
- }
// TODO(jkline): For now, acquire all of the streams at once to minimize the race condition.
// Need a way to Scan multiple ranges at the same state of uncommitted changes.
- streams = append(streams, t.qdb.st.Scan(util.ScanRangeArgs(util.JoinKeyParts(util.RowPrefix, t.req.name), start, limit)))
+ streams = append(streams, t.qdb.st.Scan(util.ScanRangeArgs(util.JoinKeyParts(util.RowPrefix, t.req.name), keyRange.Start, keyRange.Limit)))
}
return &kvs{
- t: t,
- keyRanges: keyRanges,
- curr: 0,
- validRow: false,
- it: streams,
- err: nil,
+ t: t,
+ curr: 0,
+ validRow: false,
+ it: streams,
+ err: nil,
}, nil
}
type kvs struct {
t *tableDb
- keyRanges query_db.KeyRanges
curr int
validRow bool
currKey string
@@ -442,7 +433,7 @@
if s.err != nil {
return false
}
- for s.curr < len(s.keyRanges) {
+ for s.curr < len(s.it) {
if s.it[s.curr].Advance() {
// key
keyBytes := s.it[s.curr].Key(nil)
@@ -497,7 +488,7 @@
s.it = nil
}
// set curr to end of keyRanges so Advance will return false
- s.curr = len(s.keyRanges)
+ s.curr = len(s.it)
}
////////////////////////////////////////