Martin wrote:

> a) 2 separate select-queries? One query going like:
> "SELECT * from blog_posts WHERE post_id = my_post_id"
> and the other sth. like
> "SELECT * from comments WHERE parent_id = my_post_id".
> 
> b) one join-query? Joining the two tables over my_post_id, so I only
> need 1 sql-query?

Two queries would take more time as the bottleneck will usually be the 
network. Communicating back and forth takes a while compared to CPU cycles.

Usually, for performance, you should try to retrieve a maximum amount of 
data in one shot.

I'm no database expert, anyone correct me if I'm wrong.

Using the ORM part of SA, you would want to set your "post" mapper with 
a non-lazy relation: relation('comments', ..., lazy=False). When you'll 
query for a post, it will generate some SQL that will retrieve your 
"post" *and* it's "comments" all in one query. Set echo=True on your 
engine and you'll see the actual query. Anyway, all this is nicely 
documented... :)

Regards,
-- 
Alexandre CONRAD


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