Google App Engine: how to speed up database query on a short-string property?
I have a quite simple database query:
Query q = new Query("person");
q.addFilter("name", Query.FilterOperator.EQUAL, req.getParameter("n"));
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asList(FetchOptions.Builder.withDefaults())) {
// ...
}
So it's simple search all entries for the given name. The name isn't unique and contains maximal 16 characters. As far as I know the index for the short strings (<500 characters) is generat开发者_JAVA百科ed automatically.
In the table are about 100000 entries. The database request needs more than 8 seconds to fetch all (about 10) entities.
The question is now how to speed it up?
The dev appserver's performance is not indicative of production performance. In particular, the dev appserver does not use indexes. At all. Every query just scans every entity of that type.
So don't insert that much data into the dev appserver. Use it to test basic functionality, then deploy, and insert your 1000000 entities into the production app engine appserver instead, where indexes actually get generated and used.
精彩评论