views:

17

answers:

1

Hi,

Does anyone have an idea how the use of multiple ORs impacts performance in app engine (cpu time use maybe?). Something like:

select from users where username = 'bob' or
    username = 'jane' or
    username = 'greg' or
    username = 'Nth user';

I think we can only layer 30 of these in at once. I'm curious if this operation would be done in parallel (all the ors go out at once) or each is done serially.

Thanks

+2  A: 

You can do:

SELECT FROM users WHERE username IN ('bob', 'jane', 'greg', 'Nth user')

For cleanliness. Here's what Google says about its impact on performance:

Note: The IN and != operators use multiple queries behind the scenes. For example, the IN operator executes a separate underlying datastore query for every item in the list. The entities returned are a result of the cross-product of all the underlying datastore queries and are de-duplicated. A maximum of 30 datastore queries are allowed for any single GQL query.

http://code.google.com/appengine/docs/python/datastore/gqlreference.html

NullUserException
Oops - the manual is incorrect. The entities returned are the result of the _union_ of the underlying database queries, not the cross-product. The same is true for ORs.
Nick Johnson