Datastore 索引中属性的排序有何不同?
What are the differences in the ordering of properties in a Datastore index?
我正在试验数据存储索引,我注意到我可以通过多种方式对索引中的属性进行排序:
IsItemActive ▲ + Rating ▲
- or -
Rating ▲ + IsItemActive ▲
以上两个指标有什么区别?一个允许我查询 SELECT * FROM Items WHERE Rating > 3 AND IsItemActive = FALSE
但另一个不允许。
Datastore 非常依赖索引属性的排序,以强制执行其规则,即每个查询都必须根据结果集的大小进行缩放。
为了回答查询,该查询的所有结果必须按顺序出现在索引中。
所以,考虑两个索引:
索引(IsItemActive,评分)
Item(Rating=3, IsItemActive=False) <----
Item(Rating=4, IsItemActive=False) <----
Item(Rating=3, IsItemActive=True)
Item(Rating=4, IsItemActive=True)
Item(Rating=5, IsItemActive=True)
索引(评级,IsItemActive)
Item(Rating=3, IsItemActive=False) <----
Item(Rating=3, IsItemActive=True)
Item(Rating=4, IsItemActive=False) <----
Item(Rating=4, IsItemActive=True)
Item(Rating=5, IsItemActive=True)
为了使您的查询 SELECT * FROM Items WHERE Rating > 3 AND IsItemActive = FALSE
的所有结果彼此相邻,它必须使用 Index(IsItemActive, Rating)
索引。另一个索引没有您需要的所有结果。
Here is an article about how index selection works. Also, I would highly recommend the Google I/O talk (2008) 了解 Datastore 的幕后工作原理。
我正在试验数据存储索引,我注意到我可以通过多种方式对索引中的属性进行排序:
IsItemActive ▲ + Rating ▲
- or -
Rating ▲ + IsItemActive ▲
以上两个指标有什么区别?一个允许我查询 SELECT * FROM Items WHERE Rating > 3 AND IsItemActive = FALSE
但另一个不允许。
Datastore 非常依赖索引属性的排序,以强制执行其规则,即每个查询都必须根据结果集的大小进行缩放。
为了回答查询,该查询的所有结果必须按顺序出现在索引中。
所以,考虑两个索引:
索引(IsItemActive,评分)
Item(Rating=3, IsItemActive=False) <----
Item(Rating=4, IsItemActive=False) <----
Item(Rating=3, IsItemActive=True)
Item(Rating=4, IsItemActive=True)
Item(Rating=5, IsItemActive=True)
索引(评级,IsItemActive)
Item(Rating=3, IsItemActive=False) <----
Item(Rating=3, IsItemActive=True)
Item(Rating=4, IsItemActive=False) <----
Item(Rating=4, IsItemActive=True)
Item(Rating=5, IsItemActive=True)
为了使您的查询 SELECT * FROM Items WHERE Rating > 3 AND IsItemActive = FALSE
的所有结果彼此相邻,它必须使用 Index(IsItemActive, Rating)
索引。另一个索引没有您需要的所有结果。
Here is an article about how index selection works. Also, I would highly recommend the Google I/O talk (2008) 了解 Datastore 的幕后工作原理。