Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

google app engine - How can a multi-property ndb query be successful without a composite index?

I have this entity model:

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)

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

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.

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

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

enter image description here

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

enter image description here

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

UPDATE:

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:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...