Skip to content

Commit 4068cd5

Browse files
Akkermanhazzik
Akkerman
authored andcommitted
NH-3777: Fixed JoinWalker to expose additional constraints to the topological sort.
Before, the only constraints exposed to the topological sort where constraints that were found in the explicit "On"-SqlString of the underlying OuterJoinableAssociation and not the implicit dependency of the join itself (LHS depends on RHS)
1 parent 8a10579 commit 4068cd5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/NHibernate/Loader/JoinWalker.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void AddAssociationToJoinTree(IAssociationType type, string[] aliasedLhs
158158
OuterJoinableAssociation assoc =
159159
new OuterJoinableAssociation(type, alias, aliasedLhsColumns, subalias, joinType, GetWithClause(path), Factory, enabledFilters);
160160
assoc.ValidateJoin(path);
161-
AddAssociation(subalias, assoc);
161+
AddAssociation(alias, assoc);
162162

163163
int nextDepth = currentDepth + 1;
164164

@@ -197,6 +197,7 @@ private static int[] GetTopologicalSortOrder(List<DependentAlias> fields)
197197
{
198198
var dependentField = dependentAlias.DependsOn[j].ToLower();
199199
int end;
200+
200201
if (_indexes.TryGetValue(dependentField, out end))
201202
{
202203
g.AddEdge(i, end);
@@ -211,25 +212,30 @@ private static int[] GetTopologicalSortOrder(List<DependentAlias> fields)
211212
/// <summary>
212213
/// Adds an association and extracts the aliases the association's 'with clause' is dependent on
213214
/// </summary>
214-
private void AddAssociation(string subalias, OuterJoinableAssociation association)
215+
private void AddAssociation(string lhsAlias, OuterJoinableAssociation association)
215216
{
216-
subalias = subalias.ToLower();
217+
string rhsAlias = association.RHSAlias.ToLower();
217218

218219
var dependencies = new List<string>();
220+
221+
// the association always depends on the lhsAlias (note: the "On"-SqlString does not seem to include this part of the join SQL)
222+
dependencies.Add(lhsAlias.ToLower());
223+
224+
// analyze the "On"-SqlString to find other aliases the association depends on.
219225
var on = association.On.ToString();
220226
if (!String.IsNullOrEmpty(on))
221227
{
222228
foreach (Match match in aliasRegex.Matches(on))
223229
{
224230
string alias = match.Groups[1].Value;
225-
if (alias == subalias) continue;
231+
if (alias == rhsAlias) continue;
226232
dependencies.Add(alias.ToLower());
227233
}
228234
}
229235

230236
_dependentAliases.Add(new DependentAlias
231237
{
232-
Alias = subalias,
238+
Alias = rhsAlias,
233239
DependsOn = dependencies.ToArray()
234240
});
235241

@@ -908,4 +914,4 @@ public string SelectString(IList<OuterJoinableAssociation> associations)
908914
}
909915
}
910916
}
911-
}
917+
}

0 commit comments

Comments
 (0)