Browse Source

don't ignore key when executing CONTAINS (#2924)

Fixes #2912
pull/2983/head
Anton Kaliaev 6 years ago
committed by GitHub
parent
commit
c4a1cfc5c2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +6
    -6
      state/txindex/kv/kv.go
  3. +3
    -1
      state/txindex/kv/kv_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -21,3 +21,4 @@ Special thanks to external contributors on this release:
### IMPROVEMENTS: ### IMPROVEMENTS:
### BUG FIXES: ### BUG FIXES:
- [kv indexer] \#2912 don't ignore key when executing CONTAINS

+ 6
- 6
state/txindex/kv/kv.go View File

@ -332,18 +332,18 @@ func isRangeOperation(op query.Operator) bool {
} }
} }
func (txi *TxIndex) match(c query.Condition, startKey []byte) (hashes [][]byte) {
func (txi *TxIndex) match(c query.Condition, startKeyBz []byte) (hashes [][]byte) {
if c.Op == query.OpEqual { if c.Op == query.OpEqual {
it := dbm.IteratePrefix(txi.store, startKey)
it := dbm.IteratePrefix(txi.store, startKeyBz)
defer it.Close() defer it.Close()
for ; it.Valid(); it.Next() { for ; it.Valid(); it.Next() {
hashes = append(hashes, it.Value()) hashes = append(hashes, it.Value())
} }
} else if c.Op == query.OpContains { } else if c.Op == query.OpContains {
// XXX: doing full scan because startKey does not apply here
// For example, if startKey = "account.owner=an" and search query = "accoutn.owner CONSISTS an"
// we can't iterate with prefix "account.owner=an" because we might miss keys like "account.owner=Ulan"
it := txi.store.Iterator(nil, nil)
// XXX: startKey does not apply here.
// For example, if startKey = "account.owner/an/" and search query = "accoutn.owner CONTAINS an"
// we can't iterate with prefix "account.owner/an/" because we might miss keys like "account.owner/Ulan/"
it := dbm.IteratePrefix(txi.store, startKey(c.Tag))
defer it.Close() defer it.Close()
for ; it.Valid(); it.Next() { for ; it.Valid(); it.Next() {
if !isTagKey(it.Key()) { if !isTagKey(it.Key()) {


+ 3
- 1
state/txindex/kv/kv_test.go View File

@ -89,8 +89,10 @@ func TestTxSearch(t *testing.T) {
{"account.date >= TIME 2013-05-03T14:45:00Z", 0}, {"account.date >= TIME 2013-05-03T14:45:00Z", 0},
// search using CONTAINS // search using CONTAINS
{"account.owner CONTAINS 'an'", 1}, {"account.owner CONTAINS 'an'", 1},
// search using CONTAINS
// search for non existing value using CONTAINS
{"account.owner CONTAINS 'Vlad'", 0}, {"account.owner CONTAINS 'Vlad'", 0},
// search using the wrong tag (of numeric type) using CONTAINS
{"account.number CONTAINS 'Iv'", 0},
} }
for _, tc := range testCases { for _, tc := range testCases {


Loading…
Cancel
Save