Michael Bayer wrote:
> but what happens if i say:
> 
> q.select(or_(User.c.orders.items.item_name == 'item#4',  
> User.c.orders.items.item_name == 'item #5'))
> 
> if we naively convert c.orders.items.item_name=='item #4' into  
> "user.user_id=orders.user_id and orders.order_id=items.order_id and  
> items.item_name='item #4", then the other clause for item #5  
> generates into the same thing and you get an inefficient query.  i  
> wonder also if some expressions above dont work correctly if the join  
> conditions are repeated like that.

Can you give an example of the SQL (including the joins) that would be 
generated by your statement above?

> 
> its still better to say:
> 
>       q.select(or_(Item.c.item_name == 'item#4', Item.c.item_name == 'item  
> #5'), from_obj=[c.orders.items])
> 
> isnt it ?  (User.c.orders.items would be a synonym for query.join_via 
> ('orders', 'items'))
> 

Right. It should be possible (although I'm not sure how simple) to combine 
conditions using the rules for combining logical expressions (i.e. commutative, 
transitive, etc.). For example:

(A == B AND C == D) OR (A == B AND C == E)

can be reduced to

(A == B) AND (C == D OR C == E)

So what we need is a way to take a group of expressions and reduce them to 
their simplest form before generating the SQL. However, don't most main-stream 
databases do this kind of optimization anyway? MySQL does 
(http://dev.mysql.com/doc/refman/5.0/en/where-optimizations.html).

Having said all that, it may be simpler to use join_to/join_via in some cases 
and maybe that's a good reason to keep those functions around. However, I think 
this new syntax would still be very valuable in many cases.

FWIW, an equivalent but slightly more concise version of your query above would 
be this:

q.select(user.c.orders.items.item_name.in_("item#4", "item #5"))


~ Daniel

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to