Skip to content
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

Meta data caching batch query issue #393

Merged
merged 6 commits into from
Jul 27, 2017

Conversation

AfsanehR-zz
Copy link
Contributor

Fixes issue #375 and issue #374

@AfsanehR-zz
Copy link
Contributor Author

AfsanehR-zz commented Jul 18, 2017

Using the test repro raised by @thomek,
The test is doing the following operation:

pstmt.setint(1,0);
pstmt.setNString(2,"a");
pstmt.addBatch();

pstmt.setint(1,1);
pstmt.setNString(2,"b");
pstmt.addBatch();

pstmt.setint(1,2);
pstmt.setNString(2,"cc...");
pstmt.addBatch();

pstmt.setint(1,3);
pstmt.setNString(2,"d");
pstmt.addBatch();

pstmt.setint(1,4);
pstmt.setNString(2,"e");
pstmt.addBatch();

this is what the profiler shows before this pr:

exec sp_executesql N'insert into TEST_TABLE values (@P0,@P1)                ',N'@P0 int,@P1 nvarchar(4000)',0,N'a'

declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@P0 int,@P1 nvarchar(4000)',N'insert into TEST_TABLE values (@P0,@P1)                ',1,N'b'
select @p1

declare @p1 int
set @p1=2
exec sp_prepexec @p1 output,N'@P0 int,@P1 nvarchar(max)',N'insert into TEST_TABLE values (@P0,@P1)                ',2,N'cccc.....'
select @p1

--->duplicate insert happens here
declare @p1 int
set @p1=3
exec sp_prepexec @p1 output,N'@P0 int,@P1 nvarchar(4000)',N'insert into TEST_TABLE values (@P0,@P1)                ',4,N'e'
select @p1

Result of profiler after the changes made:

exec sp_executesql N'insert into TEST_TABLE values (@P0,@P1)                ',N'@P0 int,@P1 nvarchar(4000)',0,N'a'
declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@P0 int,@P1 nvarchar(4000)',N'insert into TEST_TABLE values (@P0,@P1)                ',1,N'b'
select @p1

declare @p1 int
set @p1=2
exec sp_prepexec @p1 output,N'@P0 int,@P1 nvarchar(max)',N'insert into TEST_TABLE values (@P0,@P1)                ',2,N'ccc...'
select @p1

declare @p1 int
set @p1=3
exec sp_prepexec @p1 output,N'@P0 int,@P1 nvarchar(4000)',N'insert into TEST_TABLE values (@P0,@P1)                ',3,N'd'
select @p1

exec sp_execute 3,4,N'e'

The issue is when we hit the error message of "could not find prepared statement with handle x", we don't reset the batch parameters and reset the preparedTypeDefinitions

@TobiasSQL your thoughts are appreciated on this.

@codecov-io
Copy link

codecov-io commented Jul 18, 2017

Codecov Report

Merging #393 into dev will increase coverage by 4.8%.
The diff coverage is 60%.

Impacted file tree graph

@@             Coverage Diff             @@
##                dev     #393     +/-   ##
===========================================
+ Coverage     40.12%   44.92%   +4.8%     
- Complexity     1890     2132    +242     
===========================================
  Files           107      107             
  Lines         24482    24671    +189     
  Branches       4038     4102     +64     
===========================================
+ Hits           9823    11084   +1261     
+ Misses        12820    11723   -1097     
- Partials       1839     1864     +25
Flag Coverage Δ Complexity Δ
#JDBC41 44.78% <60%> (+4.78%) 2121 <0> (+239) ⬆️
#JDBC42 44.74% <60%> (+4.74%) 2126 <0> (+244) ⬆️
Impacted Files Coverage Δ Complexity Δ
...oft/sqlserver/jdbc/SQLServerPreparedStatement.java 49.83% <60%> (+7.39%) 162 <0> (+26) ⬆️
...oft/sqlserver/jdbc/SQLServerParameterMetaData.java 23.98% <0%> (-1.55%) 31% <0%> (+1%)
...QLServerColumnEncryptionAzureKeyVaultProvider.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...m/microsoft/sqlserver/jdbc/KeyVaultCredential.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...ncurrentlinkedhashmap/ConcurrentLinkedHashMap.java 42.42% <0%> (+0.21%) 46% <0%> (ø) ⬇️
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 49.71% <0%> (+0.42%) 214% <0%> (+4%) ⬆️
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 29.47% <0%> (+0.45%) 48% <0%> (+2%) ⬆️
...n/java/com/microsoft/sqlserver/jdbc/DataTypes.java 77.4% <0%> (+0.5%) 5% <0%> (ø) ⬇️
...m/microsoft/sqlserver/jdbc/SQLServerStatement.java 59.57% <0%> (+0.5%) 138% <0%> (+9%) ⬆️
...oft/sqlserver/jdbc/SQLServerResultSetMetaData.java 40.84% <0%> (+0.7%) 23% <0%> (+1%) ⬆️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5fe6ccc...e3b9415. Read the comment docs.

@AfsanehR-zz
Copy link
Contributor Author

Hi @rPraml , Thank you for submitting pr #374 for the valuable repro of this bug. Since that one was opened to our master branch, I went ahead and added your pr to this commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants