Hi Oliver, On Sat, Jun 13, 2009 at 12:26 AM, Oliver Zheng <[email protected]>wrote:
> > I forgot to include this question: > > What is the overhead of querying like this for just the first result, > vs just getting with the key? What is the magnitude of difference in > time? A get operation takes about 20-40 ms, while a query takes 160-200ms. See the system status console: http://code.google.com/status/appengine/detail/datastore/2009/06/15#ae-trust-detail-datastore-get-latency > > On Jun 12, 4:22 pm, Oliver Zheng <[email protected]> wrote: > > Is it a hash function in that the resulting string is randomly > > distributed among its range? It seems like in a distributed hash table > > like BigTable, this would be how it's implemented. > Bigtable isn't actually a distributed hash table. For more details, check out the paper at http://labs.google.com/papers/bigtable.html . A key consists of an app ID and a series of (type, id_or_name) pairs, where type is the name of your datastore class, and id_or_name is an autogenerated integer ID, or a user-provided name (in the case where you provided a key_name at construction time). Root entities have exactly one of these pairs, while child entities have one for each parent, in addition to their own - that is, the key describes the chain of entities. In the case of 'stringified' keys, what you are seeing is the base64 encoding of the protocol buffer containing the key. You can verify this by going to shell.appspot.com and entering: --- from google.appengine.ext import db db.Key(mystr) --- Where mystr is the key string - it will output the full key. > > > > > The reason I'm asking is, I want to do a random query. I want to > > select a random entity from an entity group. I thought if the key is > > distributed like this, then I could generate a random string like it > > myself, and simply query for the first result bigger than this. Is > > this viable? > No, but you could do the same with key components, assuming you know your IDs or names are evenly distributed. A better approach, however, is to associate a random number between 0 and 1 with each entity, and query on that. -Nick Johnson > > > > Thanks. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
