Incorrent result when query using lessThan or lessOrEqual for a String field with @Index(type: IndexType.value)
When create a IndexType.value for a string field, and query using lessOrEqual and lessThan with the value larger than then last record, eg \uffff, the query return zero record instead of all record
reproduce repo: https://github.com/lokingwei/objectbox_string_lessthan
@Entity()
class Doc {
int? id;
@Index(type: IndexType.value)
String key;
Doc({
required this.key,
});
}
box.put(Doc(key: 'b'));
box.put(Doc(key: 'c'));
box.put(Doc(key: 'd'));
// this line is corrent
expect(box.query(Doc_.key.lessOrEqual('d')).build().find(), hasLength(3));
// expected result to be 3 but return 0
expect(box.query(Doc_.key.lessOrEqual('e')).build().find(), hasLength(3));
Thanks for the detailed report and example repo!
~I think less and greater is only properly defined for integers, not sure if this is even supposed to work with strings.~ It's supposed to work as explicitly added for strings.
Anyhow, I guess a query should return the same results regardless if an index is used or not.
@greenrobot OK, confirmed and more details:
- only if
VALUEindex is used, works fine with hash-based index. - affects only
lessandless or equal,greater (or equal)are fine. - if explicitly making the condition case insensitive (which should prevent using the index) test succeeds.
- can reproduce in Java, so appears to be a core database issue.
Edit: added internal integration test for Java to repro.
affects only less, less or equal
You're saying that "greater than" and "greater or equal" work (with an index)?
You're saying that "greater than" and "greater or equal" work (with an index)?
To also update here (there is an internal issue for this): yes.
We have released version 2.3.0 which resolves this issue. Please update using flutter pub upgrade (or dart pub upgrade for Dart Native projects).
Thanks again!