Improve Query editor Read performance + cancel timely for large data (#2161)

This commit is contained in:
Cheena Malhotra
2023-08-02 14:04:30 -07:00
committed by GitHub
parent 969ac0ed8c
commit 6099746922
3 changed files with 25 additions and 1 deletions

View File

@@ -429,6 +429,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
do
{
cancellationToken.ThrowIfCancellationRequested();
columnSchemas.Add(reader.GetColumnSchema().ToArray());
} while (reader.NextResult());
}

View File

@@ -88,11 +88,33 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
/// </summary>
/// <param name="cancellationToken">The cancellation token to use for cancelling a query</param>
/// <returns></returns>
[Obsolete("Deprecated due to performance issues, please use Read() instead.")]
public Task<bool> ReadAsync(CancellationToken cancellationToken)
{
return DbDataReader.ReadAsync(cancellationToken);
}
/// <summary>
/// Pass-through to DbDataReader.Read()
///
/// ************** IMPORTANT ****************
/// M.D.SqlClient's ReadAsync() implementation is not as
/// performant as Read() and doesn't respect Cancellation Token
/// due to long existing design issues like below:
///
/// https://github.com/dotnet/SqlClient/issues/593
/// https://github.com/dotnet/SqlClient/issues/44
///
/// Until these issues are resolved, prefer using Sync APIs.
/// *****************************************
///
/// </summary>
/// <returns></returns>
public bool Read()
{
return DbDataReader.Read();
}
/// <summary>
/// Retrieves a value
/// </summary>

View File

@@ -396,8 +396,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
//
availableTask = SendCurrentResults();
while (await dataReader.ReadAsync(cancellationToken))
while (dataReader.Read())
{
cancellationToken.ThrowIfCancellationRequested();
fileOffsets.Add(totalBytesWritten);
totalBytesWritten += fileWriter.WriteRow(dataReader);
}