-
Notifications
You must be signed in to change notification settings - Fork 934
Improve IQuery.Enumerable #2017
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
Conversation
MySQL fails because of bugs in the provider. |
But it exposed an issue in our
And opening readers for all translators doesn't look like a good idea to me: nhibernate-core/src/NHibernate/Engine/Query/HQLQueryPlan.cs Lines 169 to 174 in 109f085
So my latest commit fixes it and MySql I believe won't fail for |
@@ -5,6 +5,9 @@ | |||
applyChanges: true | |||
analyzation: | |||
methodConversion: | |||
- conversion: Ignore | |||
name: GetEnumerable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because proper async enumeration is not supported by Async Generator (and I guess won't be supported until C#8 with its IAsyncEnumerable
). Generated code yields all results to List
which kills the whole point of Enumerable call:
private async Task<IEnumerable<object>> GetEnumerableAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var yields = new List<object>();
foreach (var t in Translators)
{
foreach (object obj in await (t.GetEnumerableAsync(queryParameters, session, cancellationToken)).ConfigureAwait(false))
{
yields.Add(obj);
}
}
return yields;
}
Besides current EnumerableAsync
methods are not async at all - the only async part is opening reader in query loader but iteration is synchronous.
Just for reference, the MySql bug causing those This MySQL bug causes unexpected readers to get closed by MySQL with the current implementation of Its main purpose is to reduce the number of cases where multiple readers are opened simultaneously on the same connection. For databases not supporting it, avoids having them copied into memory by NHibernate. About the async generation change, I do not think it should be done as part of this PR. |
I would say It makes Enumerable method usable for such cases. As the main purpose for separate Enumerable method is to avoid full query loading at once.
This PR didn't change async generation. I've added rule for the newly added method.
Yeah. That might be true. But as I understand the main purpose of this method is to process huge result sets - it's unlikely it's called under strict isolation levels. But that's just my speculations... |
Closed in favor of #2274 |
Do not open multiple readers when query has multiple translators (see more details here)
It fixes MySql
Query
test under .NET Core (as there is a bug with handling multiple readers)Also added proper dispose logic to Query test (so this part better review with whitespace changes disabled)
Possible breaking changes:
IQuery.Enumerable
call no longer opens reader until is actually enumerated.