首页 > 解决方案 > 基于父子索引点燃 CacheQuery

问题描述

使用点燃 2.9.x

我有两个 BinaryObject 缓存,一个用作父级,另一个用作子级,具有与父级的关联键,这样我可以将所有相关记录放在同一个节点上。

然后我想根据父键选择所有子记录。目前基于 3 节点集群,搜索时间随着我添加新的父子记录而线性增长(每个父子记录是固定的(1000))。

我想知道是否有办法在子缓存父属性(资产)上添加索引,以便扫描更有效地扩展。

生产..>资产(资产)

    IgniteCache<Integer, BinaryObject> productions = ignite.cache("productions").withKeepBinary();

    Map<LocalDate, Double> totals = new HashMap<>();

    try (QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> cursor =
        productions.query(
            new ScanQuery<BinaryObject, BinaryObject>().setLocal(true).setFilter(this::apply))) {
      for (Cache.Entry<BinaryObject, BinaryObject> entry : cursor) {
        OffsetDateTime timestamp = entry.getValue().field("timestamp");
        double productionMwh = entry.getValue().field("productionMwh");

        totals.computeIfPresent(
            timestamp.toLocalDate().withDayOfMonth(1),
            (localDate, aDouble) -> aDouble + productionMwh);
        totals.computeIfAbsent(
            timestamp.toLocalDate().withDayOfMonth(1), localDate -> productionMwh);
      }
    }

  private boolean apply(BinaryObject id, BinaryObject production) {
    return key == ((Integer) production.field("asset"));
  }

标签: indexingignite

解决方案


实现有效的父->子链接的唯一方法是为您的数据定义SQL 表和 SQL 索引。您仍然可以在亲和列上搭配此类数据。


推荐阅读