objectbox / objectbox/objectbox-java

Make "between" query conditions use index data

未关闭
#1,186 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement
主要语言
Java
星标
4.6k
派生
311
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

Issue 中没有指定 repository 文件或测试。首先,在 Android 上使用 100,000 行数据和并发写入复现已建立索引的 Java between 查询,然后确定该查询是否使用索引数据;当原因以及相对于所报告的低于 100 ms 预期值的实测结果都已确定时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, java
领域
databases, performance
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。