【发布时间】:2018-01-22 18:34:23
【问题描述】:
我使用谷歌应用引擎作为我的后端和数据存储作为数据库。链接https://cloud.google.com/datastore/docs/concepts/limits表示一个项目的最大复合索引数不能超过200。 我的项目中有大约 130 个复合索引,将来某个时候会达到限制。
200 的限制对我来说似乎非常少。 假设我的项目中有 5 个模块,每个模块都有 10 个“种类”。在每种类型中,我都有 4 个要索引的属性(我们称它们为 prop1、prop2、prop3 和 prop4)。此外,每个“种类”都有一个名为 creationTime 的字段,它存储实体在数据存储中创建的时间。无论我应用 0、1、2、3 还是全部 4 个过滤器,我总是希望我的实体列表按creationTime 排序,最新的在前。
在我看来,这是一个完全合理的场景。在这种情况下,对于每个“种类”,我必须定义以下复合索引
<datastore-index kind="kind1" ancestor="false">
<property name="prop1" direction="asc" />
<property name="creationTime" direction="desc" />
</datastore-index>
<datastore-index kind="kind1" ancestor="false">
<property name="prop2" direction="asc" />
<property name="creationTime" direction="desc" />
</datastore-index>
<datastore-index kind="kind1" ancestor="false">
<property name="prop3" direction="asc" />
<property name="creationTime" direction="desc" />
</datastore-index>
<datastore-index kind="kind1" ancestor="false">
<property name="prop4" direction="asc" />
<property name="creationTime" direction="desc" />
</datastore-index>
既然有 50 个这样的种类,那么就有 200 个这样的索引。现在我知道,如果我不按创建时间对实体列表进行排序,我可以避免这些索引,但我认为从用户的角度来看这将是非常糟糕的。
那么有没有办法增加/克服限制? 我在这里错过了什么吗? 我需要限制我的查询吗?如果是,那么我怎样才能获得相同的用户体验? 数据存储不是用于此类查询吗?我有什么选择?
【问题讨论】:
标签: google-app-engine google-cloud-platform google-cloud-datastore