-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap Multiple Eager Loaded Queries that leverage Include in Repeatable Read transactions #9014
Comments
@caleblloyd Can you post a specific example of how the wrong data is loaded? i.e. The SQL that gets generated and what inserts happen between the SQL statements that cause the data to be wrong? |
Sure. Consider the following query that fetches a blog and it's associated posts. Assume that LINQ Query:
Generated SQL:
Race Condition Now say between the 1st query that retrieves the Blogs and the 2nd query that retrieves the Posts, a new Blog is created that lands in the middle of the LIMIT(10). It will cause the Solution Wrap both queries in a |
@ajcvickers can the EF team get this on the schedule for 2.1? I believe that providing a method to fix this race condition in DBMS's that support Repeatable Read transactions is important for consistency. |
@caleblloyd It's something we plan to do some thinking around, but we're not even sure what approach to take at this time. We're not sure yet whether always using repeatable read is the best approach for the default behavior, whether it should be opt-in, whether it should remain an application concern, or whether to do something different. @anpete and @divega will do some investigation and thinking, but it may not happen for 2.1 |
Clearing milestone for this since it is similar to #14062 |
Closing this as a duplicate of #12098 with a reference here to consider this discussion. |
I am opening this issue against the behavior observed in EF Core 1.0. I have not had time to investigate changes in EF Core 2.0 so if by chance this has been added already please let me know.
Eager Loading with
.Include
generates multiple SQL queries. They are not inside of a transaction, however. This means that between the queries, new records could be inserted affecting ranges in theWHERE
clause and causing incorrect data to get loaded.Pomelo.EntityFrameworkCore.MySql solves this in 1.0 by wrapping queries that have in
Include
clause in a RepeatableRead transaction. I think that this logic should be moved into EFCore.Relational. It's pretty important for consistency's sake.Here's an example of how we do it in 1.0:
HasInclude
flag in MySqlQueryContextThe transaction isolation level should be
RepeatableRead
The text was updated successfully, but these errors were encountered: