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

Make "between" query conditions use index data #1186

Open
eric-nextsense opened this issue Aug 23, 2024 · 4 comments
Open

Make "between" query conditions use index data #1186

eric-nextsense opened this issue Aug 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@eric-nextsense
Copy link

eric-nextsense commented Aug 23, 2024

Build info

  • ObjectBox version: 3.5.0
  • OS: Android 14
  • Device/ABI/architecture: Pixel 8 Pro

Steps to reproduce

I have a database that contains say 100,000 rows. I try to query 20,000 rows using an id + a between query on an indexed long. It takes ~1.5 seconds in average, sometime up to 5-10s.

Data is frequently written to the database, about 40 times per second. Is that an issue? About 2400 rows are added per second in total between these writes.

The relativeSamplingTimestamp that is used as index has 2 values for the same timestamp in all cases (2 different data streams with same time). Like:

1
1
2
2
3
3
...

Expected behavior

I would expect it to be under a 100ms?

Actual behavior

Takes 1-10 seconds. Average 1.5s.

Code

Code
Schema:

  @Id
  public long id
  public ToOne<LocalSession> localSession;
  @Convert(converter = Converters.SerializableConverter.class, dbType = byte[].class)
  private HashMap<Integer, Float> samples;
  @Convert(converter = Converters.InstantConverter.class, dbType = Long.class)
  private Instant receptionTimestamp;
  @Nullable
  @Index
  private Integer relativeSamplingTimestamp;
  @Convert(converter = Converters.InstantConverter.class, dbType = Long.class)
  @Index
  @Nullable
  private Instant absoluteSamplingTimestamp;

Query:
    samplesRelativeTimestampBetweenQuery = sampleBox.query().equal(Sample_.localSessionId, 0)
        .between(Sample_.relativeSamplingTimestamp, 0, 0).build();

Which i then call with parameters like:

samplesRelativeTimestampBetweenQuery.setParameter(
            Sample_.localSessionId, localSessionId)
            .setParameters(Sample_.relativeSamplingTimestamp, startTimestamp, endTimestamp)
            .find())
@eric-nextsense eric-nextsense added the bug Something isn't working label Aug 23, 2024
@greenrobot-team greenrobot-team removed the bug Something isn't working label Aug 26, 2024
@greenrobot
Copy link
Member

Seems like between doesn't use the index. In your case "time series" would make sense I guess. It's a special feature that's better than a secondary index and supports between.

@greenrobot-team greenrobot-team added the more info required Further information is requested label Aug 26, 2024
Copy link

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2024
@greenrobot greenrobot reopened this Sep 19, 2024
@greenrobot greenrobot changed the title Slow query of high number of objects in a range using index Make "between" query conditions use index data Sep 19, 2024
@greenrobot greenrobot added enhancement New feature or request and removed more info required Further information is requested labels Sep 19, 2024
@eric-nextsense
Copy link
Author

eric-nextsense commented Sep 19, 2024

You are planning to add this to standard ObjectBox? If so, do you have an approximate ETA?

@greenrobot
Copy link
Member

We have a lot of things that we want to do, so there's no ETA on specific features. We track feature requests so we can at least estimate the community interest. (And if you have some business agreement with us, it much more likely things are getting prioritized.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants