Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lokingwei opened this issue Oct 1, 2021 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@lokingwei
Copy link

lokingwei commented Oct 1, 2021

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 lokingwei added the bug Something isn't working label Oct 1, 2021
@greenrobot-team
Copy link
Member

greenrobot-team commented Oct 4, 2021

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
Copy link
Member

greenrobot-team commented Oct 4, 2021

@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
Copy link
Member

greenrobot commented Oct 4, 2021

affects only less, less or equal

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

@greenrobot greenrobot self-assigned this Oct 5, 2021
@greenrobot-team
Copy link
Member

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 greenrobot-team added this to the 2.3.0 milestone Sep 19, 2023
@greenrobot-team
Copy link
Member

greenrobot-team commented Sep 19, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants