Skip to content

Commit

Permalink
don't ignore key when executing CONTAINS
Browse files Browse the repository at this point in the history
Fixes #2912
  • Loading branch information
melekes committed Dec 5, 2018
1 parent 5413c11 commit 299ccce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Special thanks to external contributors on this release:
### IMPROVEMENTS:

### BUG FIXES:
- [rpc] \#2408 `/broadcast_tx_commit`: Fix "interface conversion: interface {} in nil, not EventDataTx" panic (could happen if somebody sent a tx using /broadcast_tx_commit while Tendermint was being stopped)
- [rpc] \#2408 `/broadcast_tx_commit`: Fix "interface conversion: interface {} in nil, not EventDataTx" panic (could happen if somebody sent a tx using /broadcast_tx_commit while Tendermint was being stopped)
- [kv indexer] \#2912 don't ignore key when executing CONTAINS
8 changes: 4 additions & 4 deletions state/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ func (txi *TxIndex) match(c query.Condition, startKey []byte) (hashes [][]byte)
hashes = append(hashes, it.Value())
}
} 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, []byte(fmt.Sprintf("%s/", c.Tag)))
defer it.Close()
for ; it.Valid(); it.Next() {
if !isTagKey(it.Key()) {
Expand Down
4 changes: 3 additions & 1 deletion state/txindex/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ func TestTxSearch(t *testing.T) {
{"account.date >= TIME 2013-05-03T14:45:00Z", 0},
// search using CONTAINS
{"account.owner CONTAINS 'an'", 1},
// search using CONTAINS
// search for non existing value using CONTAINS
{"account.owner CONTAINS 'Vlad'", 0},
// search using the wrong tag (of numeric type) using CONTAINS
{"account.number CONTAINS 'Iv'", 0},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 299ccce

Please sign in to comment.