You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MARS requirement gives issues for DB's that don't support this #1665
Working on my provider for MySQL i'm running into troubles with the MARS requirement. As MySql doesn't support this all the outer queries fail with the already open DataReader exception. I managed to workaround this by catching the exception in my DB Command wrapper object and opening a new connection to the database and creating a reader on this new connection. Luckily the MySql connector has connection pooling by default so not too many connections are opened, but still all the "cloned" connections are untracked and undisposed.
Is there a possibility this MARS requirement is reconsidered, or some kind of option is introduced to turn this of ?
@bartdevriendt This is really just a limitation of our default query compiler in our core provider framework - one we will probably address at some point. A couple of things to consider:
When compiling a query, you have complete control over the expression tree produced and you can opt out of our default behavior by overriding the appropriate VisitX method (or expression tree visitor) in your query model visitor.
Have you considered completely buffering the results from the outer reader so that you can close that reader?
Since non-MARS is a pretty common case (maybe even the normal case?), doesn't it make sense for the EF core to contain a compatible query compiler and/or necessary services? This way driver writers would simply choose the non-MARS one rather than reimplementing their own?
On a related note, I'm (still) very unfamiliar with the actual mechanics going on, but it seems odd for something as simple as an Include() to depend on MARS, even in the default query compiler. Wasn't this handled without MARS in EF6? Was there a big architecture change that made it impossible to continue doing so? And handling that by buffering up the entire outer reader seems very problematic from a performance/memory-usage perspective.
Thanks for any help/pointers on how to proceed with this...
Npgsql is nearing the end of a pretty huge rewrite (3.0.0-beta.1 has just been released). The option of implementing MARS via SQL cursors does exist, but doing it in a correct and efficient way would be a pretty big task that I really want to avoid for the immediate future. I'd also like to avoid implementing a performance-problematic solution such as buffering an entire reader (a sort of poor man's MARS, I guess).
So if EF7 is compatible with an efficient, non-MARS way of doing things, that would be ideal - and it would be great to have the necessary services available for use in EF7 itself. Otherwise we really need to think we to do on our side...
Hi @roji, we actually did adress this issue in PRs #2177 and #2198. Unfortunately the latter appears in GitHub as if it had been force-pushed so there aren't any changes associated with it, but in summary, providers override 'RelationalConnection.IsMultipleActiveResultSetsEnabled' to control the EF runtime behavior. If a provider returns 'false' EF will automatically buffer the remaining results of any pending query before starting a new one.
@divega, thanks for the quick answer. Great, I'll go and implement that and will write back if there are any issues.
Do I understand correctly that this non-MARS simply buffers the data from the open reader in memory? Do you guys view this as an adequate solution from a performance perspective? At least for stuff like simple Includes, I was expecting simple SQL joins rather than any reliance on MARS or buffering...
(apologies in advance if I'm misunderstanding things, am not very familiar with EF internals)
@roji It depends 😄 but we believe that in many cases this will be better than the alternative. @anpete implemented it so he may want to correct me or provide more details, but here are a couple of points that should help explain it:
The implementation of Include() still uses JOINs in cases in which they would preserve the cardinality of the results. It only switches to multiple queries when it needs to traverse a collection navigation property, a case in which JOINs would cause an explosion of the number of rows and data redundancy in the results.
Independently of the implementation of Include() an application can attempt to execute a query while iterating over the results of another query which would require MARS or buffering to work correctly. The design addresses (or at least has the potential to address) that scenario as well.
Well that's strange. I'm running a single request from a properly injected context and if it uses Include it throws this error. So it's only related to having include or not. Also with having include it does two queries indeed.
I'm using EF6, last stable. With .NET Core 1.1. Driver is MySQL (Pomelo.EntityFrameworkCore.MySql 1.1). Am I missing something?
Does this mean that the below async scenario will only work with MsSqlServer with MARS enabled?
I am attempting to port an application from MsSqlServer to Postgres/NPgSql using EF Core 2 and would be surprised if this was not possible because of the use of the multiple concurrent async queries. Is that the case?
@PeterKneale In general WaitAll should not be used with EF Core because EF cannot execute multiple queries in parallel. If this is working on SQL Server (or for any provider) then it is because EF is serializing the two queries to run consecutively. While this will likely work for cases only involving queries because of the way the internal query state machine works, it will likely not work if the async calls are doing anything that is strictly not just a query. It's pretty hard to know when that's the case, and since there is no concurrency advantage to doing this, it means it's best to just not use WaitAll at all.
Activity
rowanmiller commentedon Feb 20, 2015
@anpete - can you drive some discussion around this
anpete commentedon Feb 20, 2015
@bartdevriendt This is really just a limitation of our default query compiler in our core provider framework - one we will probably address at some point. A couple of things to consider:
Cheers,
Andrew.
bartdevriendt commentedon Feb 27, 2015
By replacing all necessary services and overriding the default behaviour it would indeed be possible to overcome the limitation. Closing this issue.
roji commentedon May 25, 2015
@bartdevriendt, @anpete, @rowanmiller, Npgsql has the same issue with the lack of MARS support.
Since non-MARS is a pretty common case (maybe even the normal case?), doesn't it make sense for the EF core to contain a compatible query compiler and/or necessary services? This way driver writers would simply choose the non-MARS one rather than reimplementing their own?
On a related note, I'm (still) very unfamiliar with the actual mechanics going on, but it seems odd for something as simple as an
Include()to depend on MARS, even in the default query compiler. Wasn't this handled without MARS in EF6? Was there a big architecture change that made it impossible to continue doing so? And handling that by buffering up the entire outer reader seems very problematic from a performance/memory-usage perspective.Thanks for any help/pointers on how to proceed with this...
roji commentedon May 25, 2015
Just to add a little on my last note...
Npgsql is nearing the end of a pretty huge rewrite (3.0.0-beta.1 has just been released). The option of implementing MARS via SQL cursors does exist, but doing it in a correct and efficient way would be a pretty big task that I really want to avoid for the immediate future. I'd also like to avoid implementing a performance-problematic solution such as buffering an entire reader (a sort of poor man's MARS, I guess).
So if EF7 is compatible with an efficient, non-MARS way of doing things, that would be ideal - and it would be great to have the necessary services available for use in EF7 itself. Otherwise we really need to think we to do on our side...
divega commentedon May 25, 2015
Hi @roji, we actually did adress this issue in PRs #2177 and #2198. Unfortunately the latter appears in GitHub as if it had been force-pushed so there aren't any changes associated with it, but in summary, providers override 'RelationalConnection.IsMultipleActiveResultSetsEnabled' to control the EF runtime behavior. If a provider returns 'false' EF will automatically buffer the remaining results of any pending query before starting a new one.
Hope this helps.
roji commentedon May 25, 2015
@divega, thanks for the quick answer. Great, I'll go and implement that and will write back if there are any issues.
Do I understand correctly that this non-MARS simply buffers the data from the open reader in memory? Do you guys view this as an adequate solution from a performance perspective? At least for stuff like simple
Includes, I was expecting simple SQL joins rather than any reliance on MARS or buffering...(apologies in advance if I'm misunderstanding things, am not very familiar with EF internals)
divega commentedon May 25, 2015
@roji It depends 😄 but we believe that in many cases this will be better than the alternative.
@anpete implemented it so he may want to correct me or provide more details, but here are a couple of points that should help explain it:
Include()still uses JOINs in cases in which they would preserve the cardinality of the results. It only switches to multiple queries when it needs to traverse a collection navigation property, a case in which JOINs would cause an explosion of the number of rows and data redundancy in the results.Include()an application can attempt to execute a query while iterating over the results of another query which would require MARS or buffering to work correctly. The design addresses (or at least has the potential to address) that scenario as well.13 remaining items
inossidabile commentedon Mar 7, 2017
Well that's strange. I'm running a single request from a properly injected context and if it uses
Includeit throws this error. So it's only related to having include or not. Also with having include it does two queries indeed.I'm using EF6, last stable. With .NET Core 1.1. Driver is MySQL (Pomelo.EntityFrameworkCore.MySql 1.1). Am I missing something?
roji commentedon Mar 7, 2017
This repository is for Entity Framework Core, not EF6. You're better off opening an issue with a code sample at your provider's repo (Pomelo).
inossidabile commentedon Mar 7, 2017
Yeah, I use that really. Miswritten. I didn't realise that could be a provider issue. Thanks!
divega commentedon Mar 8, 2017
@inossidabile filing an issue on the Pomelo provider repo sounds like a good idea.
But in case it : that provider is for EF Core and not EF6. And EF6 never used MARS for Include queries.
inossidabile commentedon Mar 8, 2017
Yeah, like I said, I mistakenly wrote that. I'm using EF Core.
PeterKneale commentedon Feb 13, 2018
Does this mean that the below
asyncscenario will only work withMsSqlServerwithMARSenabled?I am attempting to port an application from
MsSqlServertoPostgres/NPgSqlusing EF Core 2 and would be surprised if this was not possible because of the use of the multiple concurrent async queries. Is that the case?ajcvickers commentedon Feb 13, 2018
@PeterKneale In general WaitAll should not be used with EF Core because EF cannot execute multiple queries in parallel. If this is working on SQL Server (or for any provider) then it is because EF is serializing the two queries to run consecutively. While this will likely work for cases only involving queries because of the way the internal query state machine works, it will likely not work if the async calls are doing anything that is strictly not just a query. It's pretty hard to know when that's the case, and since there is no concurrency advantage to doing this, it means it's best to just not use WaitAll at all.