Google数据存储索引优化

问题描述 投票:0回答:1

虽然设计了仅关键字查询来过滤Google数据存储区实体,但我正在生成许多复合索引,它们是另一个索引的子集。是否可以将相同的复合索引用于对已建立索引的属性的子集进行筛选的查询?例如,如果我有以下仅键查询,是否可能少于三个索引?

Query 1: Entities where a = 1, b = 1, c = 1;
Query 2: Entities where a = 1, b = 1;
Query 3: Entities where a = 1;

这里是我正在使用的实际查询的示例:

Query<Key> query = Query.newKeyQueryBuilder()
              .setKind("track")
              .setFilter(CompositeFilter.and(PropertyFilter.eq("status", 1), PropertyFilter.eq("bpm", 138), PropertyFilter.eq("artist", "AVB"), PropertyFilter.eq("label", "Armada")))
              .setOrderBy(OrderBy.asc("date"))
              .build();
google-cloud-datastore
1个回答
0
投票

数据存储区可以将较小的索引合并在一起以支持较大的相等性查询,请参见index merging。使用此功能,查询集的最小索引集应类似于:

index.yaml

indexes:

- kind: Albums
  properties:
  - name: artist
  - name: date

- kind: Albums
  properties:
  - name: bpm
  - name: date

- kind: Albums
  properties:
  - name: label
  - name: date

- kind: Albums
  properties:
  - name: status
  - name: date

这支持对任意数量的这些属性进行相等性查询,并按日期排序。但是请注意,index merging has a performance trade-off in some cases

© www.soinside.com 2019 - 2024. All rights reserved.