3
votes

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

1

1 Answers

2
votes

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

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

  • Queries using only ancestor and equality filters

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