DannyA
DannyA

Reputation: 1541

Query with filter on a Key field and another (string) field very slow on App Engine Datastore

I have an entity Kind A with around 1.3 million entities. It has several fields, two of which I use as filters in a Datastore query - K (which is a Key) and S (which is a string).

I perform the following query, and it takes it almost 8 seconds to complete:

SELECT * FROM A WHERE K=KEY('...') AND S='...' LIMIT 1

(I do this by constructing a query with filters in java, but it works just as slow in GQL.)

Is this reasonable? Can this be improved in any way?

Replacing the key query with other fields (or removing completely), speeds things up. Does it make sense to save the key field as a string, and query on that instead of on the original Key type field?

Upvotes: 0

Views: 131

Answers (1)

Bardia D.
Bardia D.

Reputation: 693

Can you please send your index.yaml file, or at least paste all the indexes for Kind A? My initial feeling is that you don't have a proper index for K and S, so it's doing a full table scan or using another index to project the results. Check out https://developers.google.com/appengine/docs/python/datastore/indexes for an explanation.

If you're still banging your head, I would suggest turning appstats on and determining the slowness from the visuals on your local dev server (https://developers.google.com/appengine/docs/python/tools/appstats).

Finally, I wanted to point out that single property lookups are fast in App Engine, so either K= or S= lookups would be fast. Together, they require special attention (indexing, memcache, etc.).

Upvotes: 2

Related Questions