views:

77

answers:

2

On outer join fetching, the Nhibernate documentation says:

If your database supports ANSI or Oracle style outer joins, outer join fetching might increase performance by limiting the number of round trips to and from the database (at the cost of possibly more work performed by the database itself). Outer join fetching allows a graph of objects connected by many-to-one, one-to-many or one-to-one associations to be retrieved in a single SQL SELECT.

I'm trying to decide if I should use outer join fetching in my current project (which uses NHibernate). To that end I'm going to be testing load times with and without outer join fetching. But I would like to know if it's a good or bad strategy on the whole when using Sql Server 2008.

Is it generally better to use outer join fetching than not with Sql Server 2008?

How does one determine whether to use it or not? (other than through performance testing and query profiling)

Thanks

+2  A: 

Weird question. Use outer join fetching if necessary; certain queries will require outer join fetching on some entities. Other queries won't. So, if you do not need it, don't fetch eagerly using outer joins. You can specify the type of fetching for each association when you use the ICriteria API.

It's all a matter of optimization, which can be done afterwards. I mean: suppose you have an object graph, where certain parts are retrieved via lazy loading, and after testing, if it seems that lazy loading affects performance in a negative way for that specific object graph, check if you could gain something by using eager loading (via outer join fetching f.i.).

Frederik Gheysels
A: 

OUTER JOINs should be used to optionally return data from the "outer joined" table. As required.

Frankly, if you cared about performance you would not use nHibernate. This will decrease performance more then using OUTER JOINs (round tripping, inefficient SQL etc).

gbn
If you make proper use of NHibernate, I wouldn't see why it would decrease performance.
Frederik Gheysels
@Frederik Gheysels: because it generates extra round trips. Inefficient SQL often too. Always varchar(255) which could mean datatype conversions. need I go on? I'm a developer DBA consulted by my nHibernate using colleagues for help...
gbn
Right, but your solution lies outside of the scope of the question. How does telling me to use straight sql instead of nhibernate, solve my nhibernate optimization problem? What you are suggesting is instead a redesign of particular pieces (or at the least a major reconfiguration) of an existing project. In this context your answer is more a rejection of nhibernate rather than an actual useful answer to my problem. Still, in order to avoid retribution I will not down vote your answer, though frankly you should delete your answer.
Mark Rogers
@Mark Rogers. I said "OUTER JOINs should be used to optionally return data from the "outer joined" table. As required." They are a valid SQL construct that have no performance impact compared to other techniques you'd use to get the same data, unless misused like any tool. Your question could be interpreted as not trusting nHibernate...
gbn