views:

60

answers:

2

I'm using GAE/Java with Objectify, and I'm trying to find the fastest way to check if a given object exists in the datastore, given the key. What I'm doing right now is .get(key) with @Cached on, but either way that still retrieves the entire object, which is unnecessary.

Any ideas on how to do this with an index only hit? I was also thinking of a keys only query, but I'm seeing (on the system status dashboard ) that the latency is much more than a get.

A: 

Any ideas on how to do this with an index only hit? I was also thinking of a keys only query

A keys-only query is the only way to get an index-only hit. Whether it's faster than a get depends on the size of your entity and the size of your index. In a trivial example, I'm getting around 8ms for a get and 13ms for a query. You can use AppStats to figure out which is cheaper for you with real data.

Drew Sears
+1  A: 

A keys only query with a filter on __key__ will be substantially faster than the queries benchmarked on the status dashboard. Whether or not it's faster than simply fetching the entity I'm not sure - try it and let us know!

Nick Johnson