Python GAE数据存储:使用多个等式查询同一StringListProperty的性能
假设我有一个模型Python GAE数据存储:使用多个等式查询同一StringListProperty的性能,python,google-app-engine,google-cloud-datastore,Python,Google App Engine,Google Cloud Datastore,假设我有一个模型 class MyModelList(db.Model): listed_props = db.StringListProperty(indexed=True) 我对它提出质疑 SELECT * from MyModelList where listed_props = 'a' and listed_props = 'b' 它的性能(延迟方面)会和我的模型一样吗 class MyModelProps(db.Model): property_1 = db.StringP
class MyModelList(db.Model):
listed_props = db.StringListProperty(indexed=True)
我对它提出质疑
SELECT * from MyModelList where listed_props = 'a' and listed_props = 'b'
它的性能(延迟方面)会和我的模型一样吗
class MyModelProps(db.Model):
property_1 = db.StringProperty(indexed=True)
property_2 = db.StringProperty(indexed=True)
我会质疑:
SELECT * from MyModelProps where property_1 = 'a' and property_2 = 'b'
以及
indexes:
- kind: MyModelProps
properties:
- name: property_1
- name: property_2
使用MyModelList对第一个示例的查询似乎更难回答,因为与第二个示例(我假设1个二进制搜索找到开始,然后读取)相比,数据存储必须将列出的索引与自身合并(我假设2个二进制搜索找到开始,然后合并索引)
如果MyModelList.listed_道具的索引需要在多个bigtable平板电脑上分片,这将特别复杂
我能期望这两个方面的性能(延迟方面)大致相同吗
PS:我问这个问题的原因是因为我喜欢使用MyModelList.listed_道具,因为更新现有实体要便宜得多,因为我可以去掉很多复合索引。从性能角度看,在没有复合索引的情况下进行查询是一个非常糟糕的主意,例如
SELECT * from MyModelList where listed_props = 'a' and listed_props = 'b'
如果你这样做,效果会更好
SELECT * from MyModelProps where property_1 = 'a' and property_2 = 'b'
使用复合索引,即使它不需要
我已经实现了这两个解决方案,并在一个有270万条记录的实时系统中运行。有综合指数的那个大约快100倍
有一篇精彩的文章解释了这一切: