objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

Incorrent result when query using lessThan or lessOrEqual for a String field with @Index(type: IndexType.value)

Open lokingwei opened this issue 4 years ago • 4 comments

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));

lokingwei avatar Oct 01 '21 09:10 lokingwei

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-team avatar Oct 04 '21 09:10 greenrobot-team

@greenrobot OK, confirmed and more details:

  • only if VALUE index is used, works fine with hash-based index.
  • affects only less and less 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.

greenrobot-team avatar Oct 04 '21 11:10 greenrobot-team

affects only less, less or equal

You're saying that "greater than" and "greater or equal" work (with an index)?

greenrobot avatar Oct 04 '21 11:10 greenrobot

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.

greenrobot-team avatar May 24 '22 06:05 greenrobot-team

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!

greenrobot-team avatar Sep 19 '23 14:09 greenrobot-team