Hi,
We're using LLBL v2.6 using Adapter and Sql Server 2005. I wanted to know if anyone has some suggestions on increasing prefetch performance. But first I wanted to explain where I'm at...
I have an object graph that is moderately complex. All tables have indexes. What I noticed is that LLBL will do something like this when prefetching:
select <columns>
from <child>
where <foreignkey> in (select <primarykey> from <parent> where <parentpredicate>)
and you may see:
select <columns>
from <grandchild>
where <foreignkey> in
(
select <primarykey> from <child> where <foreignkey> in
(
select <primarykey> from <parent> where <parentpredicate>
)
)
This will continue as deep as your prefetch goes. Most of the time this works fine, but I noticed if it goes deep enough (I think somewhere around 5 nestings in my case), performance takes a huge dive. Has anyone seen this?
My workaround is to process the prefetches myself and build the graph manually. I fetch the parent entities, then use them to find all the IDs used in my query for the child entities. The child entities are returned by doing an IN clause. Something like this:
select <columns> from <child> where <foreignkey> in (pk1, pk2, pk3...)
This resulted in a massive performance increase when dealing with larger entity collections.
I'm somewhat happy with what I have, but I would still like to tweak it a bit. My bottleneck now seems to be rebuilding the graph. For instance, I have the following kind of situation:
foreach (var child in childEntities)
parent.ChildEntityCollection.Add(child)
Is there any faster way to do something like this?
Maybe there's not much I can do other than throw hardware at it. I can live with that I suppose. Although I am curious, is there a reason LLBL nests the subqueries to do the prefetch versus doing what I did?