AppEngine - ndb - 未编入索引的属性不起作用?

时间:2015-02-25 05:33:15

标签: google-app-engine python-2.7

我试图了解内置索引在AppEngine中的工作原理。文档说,将“indexed = False”传递给构造函数会停止索引属性,但似乎并非如此。

我有以下代码:

import webapp2
from google.appengine.ext import ndb

class IndexedClass(ndb.Model):
    prop1 = ndb.IntegerProperty(indexed=True)
    prop2 = ndb.StringProperty(indexed=True)

class UnindexedClass(ndb.Model):
    prop1 = ndb.IntegerProperty(indexed=False)
    prop2 = ndb.StringProperty(indexed=False)

class MainHandler(webapp2.RequestHandler):
    def get(self):
        for i in range(10):
            IndexedClass(
                prop1=i,
                prop2="Item %s" % i
            ).put()
            UnindexedClass(
                prop1=i,
                prop2="Item %s" % i
            ).put()

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

如果您在GAEL中执行并创建统计信息,则可以获得:enter image description here

它为索引和未索引的类报告相同的内置索引。

如果有人能指出我做错了什么,我将非常感激。

在AppEngine上部署的类似应用在模型中有更多未编入索引的属性,here are the stats声明如下: -

aProperty = ndb.KeyProperty(kind='Geography', indexed=False)

正如您所看到的,我们有超过2M实体使用947Mb。我们有使用5Gb数据的40M索引。这些不需要的内置索引占用的空间比实体本身多5倍。因此,我们支付的存储空间增加了5倍,写入操作数量增加了10倍,而不是文档说明。

提前致谢, 马克

1 个答案:

答案 0 :(得分:1)

未经索引的属性肯定会在实践中发挥作用:它们不会在索引表中注册,因此您将无法在投影查询和过滤器中使用它们。

但是,你对统计数据是正确的。你在那里展示的图片让我非常感兴趣。进入SDK的内容的是DatastoreStatsProcessor类,它似乎是负责聚合您在触发a stats update时看到的结果的人。在方法__AgreggateTotal中,它似乎没有区分索引和未索引的属性:在__GetPropertyIndexStat方法中,它总是为每个属性返回2,这解释了生成统计数据后得到的结果

在部署项目后,值得检查一下Google Dev Console的内容。存储 - > Datastore->信息中心。可耻的是,我没有任何已部署的项目使用无索引(或Blob或Text属性)。 你呢?