开发者

Google App Engine: how to speed up database query on a short-string property?

开发者 https://www.devze.com 2023-04-09 21:56 出处:网络
I have a quite simple database query: Query q = new Query(\"person\"); q.addFilter(\"name\", Query.FilterOperator.EQUAL, req.getParameter(\"n\"));

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号