don't return false positives when searching for a prefix of a tag value (#2919)

Fixes #2908
This commit is contained in:
Anton Kaliaev
2018-11-27 17:12:28 +04:00
committed by Ethan Buchman
parent bef39f3346
commit 92dc5fc77a
3 changed files with 5 additions and 2 deletions

View File

@@ -412,9 +412,9 @@ LOOP:
func startKey(c query.Condition, height int64) []byte {
var key string
if height > 0 {
key = fmt.Sprintf("%s/%v/%d", c.Tag, c.Operand, height)
key = fmt.Sprintf("%s/%v/%d/", c.Tag, c.Operand, height)
} else {
key = fmt.Sprintf("%s/%v", c.Tag, c.Operand)
key = fmt.Sprintf("%s/%v/", c.Tag, c.Operand)
}
return []byte(key)
}

View File

@@ -73,6 +73,8 @@ func TestTxSearch(t *testing.T) {
{"account.number = 1 AND account.owner = 'Ivan'", 1},
// search by exact match (two tags)
{"account.number = 1 AND account.owner = 'Vlad'", 0},
// search using a prefix of the stored value
{"account.owner = 'Iv'", 0},
// search by range
{"account.number >= 1 AND account.number <= 5", 1},
// search by range (lower bound)