-
Notifications
You must be signed in to change notification settings - Fork 433
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
High client usage when closing result set after huge query #877
Comments
This blog post has a good explanation of SQL Server's behavior:
|
An enhancement would need to be made on the server side to facilitate different processing of result sets via TDS. Other alternatives are to use a driver which supports Multiple Active Result Sets (MARS), like ODBC, or server-side cursors. |
This issue was brought up by a customer. I wanted to capture it in a GitHub issue in case others encounter it and need to know why the driver behaves the way it does.
Driver version
7.0.0
SQL Server version
SQL Server 2017
Client Operating System
Windows 10
JAVA/JVM version
JRE 10
Table schema
CREATE TABLE TestTable (TestColumn varchar(max));
create table testtable2 (testcolumn varchar(max))
declare @i int = 0
while @i < 10000
begin
insert into testtable2 (testcolumn) values
('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
select @i = @i + 1
end
set @i = 0
while @i < 500
begin
insert into testtable (testcolumn) select testcolumn from testtable2
select @i = @i + 1
end
Problem description
Execute a SQL query that returns a large result set, but only read a few rows before doing connection.rollback()
Rollback is executed, ResultSet is closed immediately (less than a second).
ResultSet.close() is causing all rows to be fetched from the server and taking a long time to close.
Reproduction code
Workaround
You can call statement.cancel() to abort processing of further results before calling rs.close(). This will have the effect of cancelling all result sets that might be following the first one being returned by the statement.
This behavior is by design and is not specific to the JDBC driver. All drivers that communicate with SQL Server must follow the TDS specification. A statement may return multiple result sets, whether it is multiple SELECT statements in a batch or a stored procedure which returns multiple result sets. Closing a result set tells the driver to move on to the next one and the only way to get to the next one is to fetch the stream of data until the next result set is encountered. There is no way to tell the server to skip ahead in the stream to the next result set. The server will not even begin producing/writing subsequent result sets to the stream until all previous rows are read.
The text was updated successfully, but these errors were encountered: