Google api resolves the IN operator by using multiple queries: http://code.google.com/appengine/docs/python/datastore/gqlreference.html
"The IN operator compares value of a property to each item in a list. The IN operator is equivalent to many = queries, one for each value, that are ORed together. An entity whose value for the given property equals any of the values in the list can be returned for the query. 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." In SQL IN would be O(1) in GQL it is O(N) so it should be used carefully. Robin On Dec 14, 12:04 am, mdipierro <[email protected]> wrote: > Unless I misunderstand. web2py is not breaking this in 3 GAE queries. > It maps the belongs in the GAE IN operator. Since the IN is executed > at the entity level, before data is aggregated, ordered and filtered, > I do not think there is any significant overhead. Or at least there > should not be. Yet I do not know how GAE is implemented and I have not > benchmarked it. > > Massimo > > On Dec 13, 11:17 pm, Robin B <[email protected]> wrote: > > > IN is not magic, and evaluates1 db query for each member, and should > > be used carefully. > > > q3=(db.table.field.belongs(('value1','value2','value3'))) > > > evaluates 3 db queries to get the result, > > > Robin > > > On Dec 13, 5:33 am, Richard <[email protected]> wrote: > > > > neat! I need to keep closer track of GAE developments ... > > > > On Dec 13, 2:17 pm, mdipierro <[email protected]> wrote: > > > > > At some point GAE added support for the IN operator. I do not know > > > > when but when I found out I added it (belongs maps to IN). Notice that > > > > this is not the same as LIKE. > > > > > Massimo > > > > > On Dec 12, 6:19 pm, Richard <[email protected]> wrote: > > > > > > how did you add belongs support for GAE? I remember in a previous > > > > > discussion this was considered not > > > > > possible/practical:http://code.google.com/p/web2py/issues/detail?id=56&can=1 > > > > > > On Dec 12, 4:42 pm, mdipierro <[email protected]> wrote: > > > > > > > I have re-factored a lot of code in gluon/contrib/gql.py in order to > > > > > > make it leaner, more readable and add new syntax. Now you can do mix > > > > > > and match queries like: > > > > > > > q1=(db.table.id==1) > > > > > > q2=(db.table.id>0) > > > > > > q3=(db.table.field.belongs(('value1','value2','value3'))) > > > > > > > in expressions like > > > > > > > db(q1)(q2)q3).select() > > > > > > db(q1&q&q3).select() > > > > > > db(...).update(...) > > > > > > db(...).delete() > > > > > > > Before this patch, belongs was not supported by web2py on GAE, q1 > > > > > > and > > > > > > q2 could not be mixed with other conditions. > > > > > > > Now you can do for example: > > > > > > > d=datetime.date.today() > > > > > > db.define_table('person',Field('name'),Field('birthday','date')) > > > > > > db.person.insert(name='John',birthday=d) > > > > > > > > > > > > rows=db(db.person.id>0)(db.person.name.belongs(('John',))).count() > > > > > > rows=db(db.person.id==1)(db.person.name.belongs(('John',)))\ > > > > > > (birthday==d).update(name='Jim') > > > > > > > Moreover the db['_lastsql'] now contains a complete representation > > > > > > of > > > > > > the last query on GAE and it can be used for debugging, and both > > > > > > db, db > > > > > > (...) and can serialized as a string. > > > > > > > Please check it and report any problem. > > > > > > > Also please let me know if you find places in the online > > > > > > documentation > > > > > > that have just become obsolete. > > > > > > > Massimo -- You received this message because you are subscribed to the Google Groups "web2py-users" 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/web2py?hl=en.

