Repository navigation
Fix table splitting for derived types in the update pipeline. - #8976
Conversation
| [Fact] | ||
| public void Can_query_shared() | ||
| { | ||
| using (var store = CreateTestStore(OnModelCreating)) |
There was a problem hiding this comment.
Is this yet another test initialization pattern? 😄
There was a problem hiding this comment.
😢
Do we need to create new store everytime? Have a fixture based testing
There was a problem hiding this comment.
The fixture is unnecessary as we don't share anything. The store needs to be created every time to get a clean database
| Property.Format(key.Properties), | ||
| otherKey.Relational().Name, | ||
| Property.Format(otherKey.Properties))); | ||
| var entityType = unvalidatedTypes.Dequeue(); |
There was a problem hiding this comment.
Consider adding a comment describing the algorithm here.
There was a problem hiding this comment.
I wish there was another way to right this code to make it self-explanatory. (or you can suggest something)
In brief the algorithm is
Input List of entity types
- Take first entity type and make it first node in graph.
- Find all ETs which are either derived type or connected via identifying relationship and add them to graph.
- Repeat step 2 till graph no longer expands.
There was a problem hiding this comment.
Maybe something recursive like in EagerLoadingExpressionVisitor.WalkNavigations?
There was a problem hiding this comment.
Similar.
One difference I see is, in WalkNavigations, we know all outbound edges, we do DFS and add the leaf nodes. So the graph is known we are just walking.
Here we have list of nodes in which need to find the edges, hence create the unknown graph.
There was a problem hiding this comment.
I refactored this to look like a BFS
|
@bricelam, @smitpatel Are we happy that table-splitting works well with Migrations? |
| dependentList = new List<IEntityType>(); | ||
| dependents[principalEntityType] = dependentList; | ||
| } | ||
| ((List<IEntityType>)dependentList).Add(entityType); |
There was a problem hiding this comment.
This seems unusual - why is dependents declared using IReadOnlyList?
There was a problem hiding this comment.
ModificationCommandIdentityMap constructor takes IReadOnlyDictionary<IEntityType, IReadOnlyList<IEntityType>> and one cannot cast Dictionary<IEntityType, List<IEntityType>> to it.
smitpatel
left a comment
There was a problem hiding this comment.
Migration should be fine.
This mainly changes how they are handled in model building & update pipeline.
Once perfectly built model migrations would just work that way.
Metadata changes look good with some comments.
| [Fact] | ||
| public void Can_query_shared() | ||
| { | ||
| using (var store = CreateTestStore(OnModelCreating)) |
There was a problem hiding this comment.
😢
Do we need to create new store everytime? Have a fixture based testing
| validatedTypes.Add(entityType); | ||
| foreach (var entityType in invalidTypes) | ||
| { | ||
| throw new InvalidOperationException( |
There was a problem hiding this comment.
how does foreach & throw Exception work together? 😕
There was a problem hiding this comment.
If we get here and invalidTypes.Count > 1, then why not just exit the loop above early. I.e. stop on the first invalid type.
There was a problem hiding this comment.
It is due to graph traversal.
For the graph of A->B->C and starting point as A. Till B is discovered C is invalid type. So we need to iterate over the graph till it expands (and stabilizes). Then only we can be certain of invalid type.
| Property.Format(key.Properties), | ||
| otherKey.Relational().Name, | ||
| Property.Format(otherKey.Properties))); | ||
| var entityType = unvalidatedTypes.Dequeue(); |
There was a problem hiding this comment.
I wish there was another way to right this code to make it self-explanatory. (or you can suggest something)
In brief the algorithm is
Input List of entity types
- Take first entity type and make it first node in graph.
- Find all ETs which are either derived type or connected via identifying relationship and add them to graph.
- Repeat step 2 till graph no longer expands.
| && entityTypeAnnotations.Schema == principalTypeAnnotations.Schema) | ||
| { | ||
| var index = -1; | ||
| for (var i = 0; i < pk.Properties.Count; i++) |
There was a problem hiding this comment.
Can we use LINQ for this?
There was a problem hiding this comment.
It would be uglier IMO
There was a problem hiding this comment.
Do we have that or are you proposing to extract it?
There was a problem hiding this comment.
FindIndex is on List. You can use First. Would do the same as above loop just smaller code.
Leave it as is.
| dependentList = new List<IEntityType>(); | ||
| dependents[principalEntityType] = dependentList; | ||
| } | ||
| ((List<IEntityType>)dependentList).Add(entityType); |
There was a problem hiding this comment.
There seems to some mismatch here. Dictionary.Value is readonly list but the value being assigned is List instead. Consider making it one type.
If Readonly list is needed for perf then consider making them explicitly.
| } | ||
|
|
||
| [Fact(Skip = "#8907")] | ||
| [Fact(Skip = "#8973")] |
There was a problem hiding this comment.
We moved from one bug to another 😅
I was mostly thinking about the fact that there can be multiple ETs pointing to same table and wanted to make sure this is handled somehow. Do we have a test for migrations with table splitting? |
|
@bricelam - For migration changes |
|
I added tests to |
| var relationshipFound = validatedTypes.Any(validatedType => | ||
| var entityType = typesToValidate.Dequeue(); | ||
| var typesToValidateLeft = typesToValidate.Count; | ||
| var nextTypeSet = unvalidatedTypes.Where(validatedType => |
There was a problem hiding this comment.
Can you change the name of parameter in lambda?
picking validatedType from unvalidatedTypes enumerator ![]()
|
|
||
| foreach (var typeToValidate in typesToValidate.Skip(typesToValidateLeft)) | ||
| { | ||
| unvalidatedTypes.Remove(typeToValidate); |
There was a problem hiding this comment.
This can be removed when Enqueueing if nextTypeSet is allocated using ToList().
Whichever is more performant 👍
There was a problem hiding this comment.
This was added specifically to avoid ToList() 😄
Make the columns nullable for dependent types involved in table splitting. When uniquifying column names use the declaring entity type name as prefix. Fixes #8907
Make the columns nullable for dependent types involved in table splitting.
When uniquifying column names use the declaring entity type name as prefix.
Fixes #8907