What is the absolute cheapest way (CPU cost) theoretically to run an
SQL EXISTS query with the Datastore API?

I imagine FetchOptions would be
FetchOptions.Builder.withChunkSize(1).limit(1).prefetchSize(1) and
probably option 1 below.

                Query query = new Query("KIND");
                //add filters and sorts here, if querying by key use
query.setKeysOnly()
                DatastoreService datastoreService =
DatastoreServiceFactory.getDatastoreService();
                PreparedQuery pq = datastoreService.prepare(query);

                //Option 1
                long count =
pq.countEntities(FetchOptions.Builder.withChunkSize(1).limit(1).prefetchSize(1));

                if (count == 0) {
                        //does not exist
                }
                else {
                        //exists
                }

                // or maybe
                //Option 2
                if (pq.asIterator().hasNext()) {
                        //exists
                }
                else {
                        //does not exist
                }

Is there anything cheaper?

Best wishes,
Dan

-- 
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