Hi,

You're right about 2): more efficient because only key is accessed: i/
o limited to index rather than index + table when you fetch the entire
entity. So more disk i/o and more bytes to transfer between the
datastore server and the server of your jvm.

About 3): 2 important points come to mind: (a) using ancestor key
means that you know how your entities are grouped in the datastore for
transactional purposes: i.e you need to know the parent for each
entity key you want to check  and (b) according to this grouping, get
on 1 ancestor key may return more than 1 child entity and then you may
lose the performance optimization that you are looking for.

regards

didier

On Jan 2, 11:16 am, "ss.require" <ss.requ...@gmail.com> wrote:
> Let's suppose I need to check by a key if the specified entity exists
> in the datastore. What is the most proper way to achieve that?I have
> the next ways:
>
> 1) datastoreservice.get(key).
> 2) execute keys-only query with the __key__ property: new
> Query("Kind").addFilter(Entity.KEY_RESERVED_PROPERTY,
> FilterOperator.EQUAL, key).setKeysOnly()
> 3) execute keys-only query with the ancestor key: new
> Query("Kind").setAncestor(key).setKeysOnly()
>
> I think that 2) or 3) is more efficient than 1) because we don't need
> to deserialize the whole entity from the datastore, just get only
> keys. But I don't have any suggestions about: 2) or 3) is more
> efficient?

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to