没有复合索引的多属性ndb查询如何成功? [英] How can a multi-property ndb query be successful without a composite index?

查看:21
本文介绍了没有复合索引的多属性ndb查询如何成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个实体模型:

class ApartCILabel(ndb.Model):
    project_id = ndb.IntegerProperty(indexed=True)
    changeset_ids = ndb.IntegerProperty(repeated=True, indexed=True)   # ApartCIChangeset IDs
    # other properties

我最近为这些实体添加了一种新的查询类型:

I recently added a new type of query for these entities:

            keys = ApartCILabel.query(ApartCILabel.project_id == self.db_data.project_id,
                                      ApartCILabel.changeset_ids == self.key_id).fetch(keys_only=True)
            if keys:
                label = Label(db_key=keys[0], handler=self.handler)
                logging.debug('label found: %s' % label.name)
            else:
                logging.error('label for %s not found' % self.lid)

我知道我需要一个复合索引,所以我在 dev_appserver.py 中运行了该应用程序,它用于自动更新我的 index.yaml 文件.我在日志中看到调试信息,说明查询成功:

I knew I needed a composite index for it, so I ran the app in dev_appserver.py, which used to automatically update my index.yaml file. I see the debug message in the log, indicating that the query was successful:

DEBUG    2018-02-20 23:56:11,720 ci_changeset.py:70] label found: ACI_COPY_OF_SMALL_180221_1

令我惊讶的是,我的 index.yaml 文件中没有任何更新.好的,自从我上次需要更新索引(现在运行 1.9.65)以来,我确实更新了我的 GAE SDK,也许是我用于在所有用户之间共享我的索引定义文件的基于符号链接的方案我的服务以某种方式干扰.没问题,我将在 GAE 上部署更改,我会在那里看到缺少的复合索引错误.

To my surprise, I see no update in my index.yaml file. OK, I did update my GAE SDK since the last time I needed an index update (running 1.9.65 now), maybe the symlink-based scheme I'm using for sharing my index definition file across all my services interferes somehow. No problem, I'm gonna deploy the change on GAE and I'll see the missing composite index error there.

再次惊喜:查询成功,没有错误.

Again surprise: the query is successful, no error.

我检查了我的 index.yaml 文件,这种唯一的复合索引是这个:

I checked my index.yaml file, the only composite index for this kind is this one:

- kind: ApartCILabel
  properties:
  - name: project_id
  - name: created
    direction: desc

我在开发者控制台中仔细检查了数据存储索引,正如我预期的那样,与 index.yaml 文件同步:

I double-checked the datastore indexes in the developer console, which is, as I expected, in sync with the index.yaml file:

我什至在开发者控制台中执行了手动查询,这也应该需要复合索引.也成功了:

I even performed a manual query in the developer console, which should also require a composite index. Also successful:

这样的查询如何在没有复合索引的情况下运行?我错过了什么?

How is it possible for such query to function without a composite index? What am I missing?

更新:

几个小时后,我执行了另一个类似的手动查询,结果再次正确,但是这次 您的数据存储没有此查询所需的复合索引(开发人员提供). 错误(或者我应该称之为警告?)出现了:

After a few hours I performed another similar manual query, again the result is correct, but this time the Your Datastore does not have the composite index (developer-supplied) required for this query. error (or should I rather call it warning?) showed up:

推荐答案

仅使用相等过滤器的查询不需要创建复合索引.来自文档:

Queries using only equality filters do not require a composite index to be created. From the documentation:

Cloud Datastore 为以下形式的查询提供内置或自动索引:

Cloud Datastore provides built-in, or automatic, indexes for queries of the following forms:

  • 仅使用祖先和相等过滤器的查询

https://cloud.google.com/datastore/docs/concepts/indexes#index_configuration

这篇关于没有复合索引的多属性ndb查询如何成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆