sql - O/R mapping: Single complex query vs. multiple simple queries -


i'm qurious on how result set of sql query transported server client.

most o/r mappers support both eager , lazy load, both have pros , cons. e.g. entity framework4 (.net) has wonderful eager load support.

however, lets assume have model this:

blogpost {     public string body {get;set;}     icollection<comment> comments {get;set;} } 

...

and query this:

var posts = context           .posts           .include(post => post.comments)           .where(post => post.id == 1)           .first(); 

this result in single sql query, data "post" repeated on each row every "comment"

lets have 100 comments on specific post , post.body massive peice of text. can't good? or data somehow compressed when sent client, minimizing overhead of repeating data on each row?

what best way determine if 1 such query more efficient 2 simple queries (one getting post , 1 getting comments)?

benchmarking on dev environment pretty pointless, there multiple factors here: cpu load on sql server network load cpu load on app server (materializing objects)

ideas on this?

[edit] clarification:

two queries this:

sql

select * post postid = 123 

result

id , topic, body , etc... 

sql

select * comment postid = 123 

result

id,postid, commenttext , etc... 

the first query yield 1 row , 2nd query yield many rows there comments.

with single query there many rows there comments specific post , post data repeated on each row.

result

p.id , p.topic, __p.body__, c.id, c.postid, c.commenttext 

p.body repeated on each row, making result set extremely large. (assuming p.body contains alot of data ;-)

i think comes down following:

  • how many posts there?
  • how complex comments of post?

if have several million posts, better use single query, if have several comments each post, because aggregated roundtrip time worse time transfer of additional data.
so, think need have sharp eye ;-)
, also, think benchmarking in dev environment not pointless, because can give @ least relations between 2 ways of doing it.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -