-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add support for sys.sp_reset_connection stored procedure #2758
Changes from all commits
c561179
7b7a8ea
4ea70d8
b68575c
1d4a9fb
d92fcd8
3acb08d
f8a0f79
0690b94
fa16724
0f3c8ea
dec89b0
f41dec1
711a197
5bd9f96
19fe321
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
-- 1. Test resets GUC variables | ||
SET lock_timeout 0; | ||
GO | ||
SELECT @@lock_timeout; | ||
GO | ||
~~START~~ | ||
int | ||
0 | ||
~~END~~ | ||
|
||
EXEC sys.sp_reset_connection | ||
-- TODO: GUC is not resetting | ||
SELECT @@lock_timeout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming the default value was 0. How are we really testing the reset in this case? |
||
GO | ||
~~START~~ | ||
int | ||
0 | ||
~~END~~ | ||
|
||
|
||
-- 2. Test open transactions are aborted on reset | ||
DROP TABLE IF EXISTS sp_reset_connection_test_table; | ||
CREATE TABLE sp_reset_connection_test_table(id int); | ||
BEGIN TRANSACTION | ||
INSERT INTO sp_reset_connection_test_table VALUES(1) | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
EXEC sys.sp_reset_connection | ||
GO | ||
COMMIT TRANSACTION | ||
GO | ||
~~ERROR (Code: 3902)~~ | ||
|
||
~~ERROR (Message: COMMIT can only be used in transaction blocks)~~ | ||
|
||
SELECT * FROM sp_reset_connection_test_table | ||
GO | ||
~~START~~ | ||
int | ||
~~END~~ | ||
|
||
|
||
-- 3. Test temp tables are deleted on reset | ||
CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) | ||
INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) | ||
GO | ||
~~ROW COUNT: 3~~ | ||
|
||
SELECT * from #babel_temp_table | ||
GO | ||
~~START~~ | ||
int#!#int | ||
1#!#100 | ||
2#!#200 | ||
3#!#300 | ||
~~END~~ | ||
|
||
EXEC sys.sp_reset_connection | ||
GO | ||
SELECT * from #babel_temp_table | ||
GO | ||
~~ERROR (Code: 33557097)~~ | ||
|
||
~~ERROR (Message: relation "#babel_temp_table" does not exist)~~ | ||
|
||
|
||
-- 4. Test isolation level is reset | ||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
~~START~~ | ||
smallint | ||
1 | ||
~~END~~ | ||
|
||
EXEC sys.sp_reset_connection | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
~~START~~ | ||
smallint | ||
2 | ||
~~END~~ | ||
|
||
|
||
-- 5. Test sp_reset_connection called with sp_prepexec | ||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
~~START~~ | ||
smallint | ||
1 | ||
~~END~~ | ||
|
||
DECLARE @handle int; | ||
EXEC SP_PREPARE @handle output, NULL, N'exec sys.sp_reset_connection' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my previous comments, we have still not added RPC tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my previous comments, we have still not added RPC tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I see the these are added in .net |
||
EXEC SP_EXECUTE @handle | ||
GO | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
~~START~~ | ||
smallint | ||
2 | ||
~~END~~ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
-- 1. Test resets GUC variables | ||
SET lock_timeout 0; | ||
GO | ||
SELECT @@lock_timeout; | ||
GO | ||
EXEC sys.sp_reset_connection | ||
-- TODO: GUC is not resetting | ||
SELECT @@lock_timeout; | ||
GO | ||
|
||
-- 2. Test open transactions are aborted on reset | ||
DROP TABLE IF EXISTS sp_reset_connection_test_table; | ||
CREATE TABLE sp_reset_connection_test_table(id int); | ||
BEGIN TRANSACTION | ||
INSERT INTO sp_reset_connection_test_table VALUES(1) | ||
GO | ||
EXEC sys.sp_reset_connection | ||
GO | ||
COMMIT TRANSACTION | ||
GO | ||
SELECT * FROM sp_reset_connection_test_table | ||
GO | ||
|
||
-- 3. Test temp tables are deleted on reset | ||
CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) | ||
INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) | ||
GO | ||
SELECT * from #babel_temp_table | ||
GO | ||
EXEC sys.sp_reset_connection | ||
GO | ||
SELECT * from #babel_temp_table | ||
GO | ||
|
||
-- 4. Test isolation level is reset | ||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
EXEC sys.sp_reset_connection | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
|
||
-- 5. Test sp_reset_connection called with sp_prepexec | ||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO | ||
DECLARE @handle int; | ||
EXEC SP_PREPARE @handle output, NULL, N'exec sys.sp_reset_connection' | ||
EXEC SP_EXECUTE @handle | ||
GO | ||
GO | ||
select transaction_isolation_level from sys.dm_exec_sessions where session_id=@@SPID | ||
GO |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#Q#DROP TABLE IF EXISTS sp_reset_connection_test_table; | ||
#Q#CREATE TABLE sp_reset_connection_test_table(id int); | ||
#Q#INSERT INTO sp_reset_connection_test_table VALUES(1) | ||
#Q#INSERT INTO sp_reset_connection_test_table VALUES(2) | ||
#Q#sys.sp_reset_connection | ||
#Q#SELECT * FROM sp_reset_connection_test_table | ||
#D#int | ||
1 | ||
#Q#CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) | ||
#Q#INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) | ||
#Q#SELECT * from #babel_temp_table | ||
#D#int#!#int | ||
1#!#100 | ||
2#!#200 | ||
3#!#300 | ||
#Q#sys.sp_reset_connection | ||
#Q#SELECT * from #babel_temp_table | ||
#E#relation "#babel_temp_table" does not exist | ||
#Q#select current_setting('transaction_isolation') | ||
#D#text | ||
repeatable read | ||
#Q#sys.sp_reset_connection | ||
#Q#select current_setting('transaction_isolation') | ||
#D#text | ||
read committed | ||
#Q#CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) | ||
#Q#INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) | ||
#Q#SELECT * from #babel_temp_table | ||
#D#int#!#int | ||
1#!#100 | ||
2#!#200 | ||
3#!#300 | ||
#Q#sys.sp_reset_connection | ||
#Q#sys.sp_reset_connection | ||
#Q#SELECT * from #babel_temp_table | ||
#E#relation "#babel_temp_table" does not exist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Test (1): Test abort open transaction | ||
DROP TABLE IF EXISTS sp_reset_connection_test_table; | ||
CREATE TABLE sp_reset_connection_test_table(id int); | ||
INSERT INTO sp_reset_connection_test_table VALUES(1) | ||
txn#!#begin | ||
INSERT INTO sp_reset_connection_test_table VALUES(2) | ||
storedproc#!#prep#!#sys.sp_reset_connection#!# | ||
txn#!#commit | ||
SELECT * FROM sp_reset_connection_test_table | ||
# Test (1): End | ||
|
||
# Test (2): Test temp table deletion | ||
CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) | ||
INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) | ||
SELECT * from #babel_temp_table | ||
storedproc#!#prep#!#sys.sp_reset_connection#!# | ||
SELECT * from #babel_temp_table | ||
# Test (2): End | ||
|
||
# Test (3): Test reset of isolation level | ||
txn#!#begin#!#isolation#!#ss | ||
select current_setting('transaction_isolation') | ||
storedproc#!#prep#!#sys.sp_reset_connection#!# | ||
select current_setting('transaction_isolation') | ||
txn#!#commit | ||
# Test (3): End | ||
|
||
# Test (4): Test prepexec sp_reset_connection | ||
CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) | ||
INSERT INTO #babel_temp_table (Data) VALUES (100), (200), (300) | ||
SELECT * from #babel_temp_table | ||
prepst#!#sys.sp_reset_connection#!# | ||
prepst#!#exec#!# | ||
SELECT * from #babel_temp_table | ||
# Test (4): End |
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.
On diving deep, Found 2 behaviour differences:
We have not fixed this for sp_reset_connection and this is paramount for feature complete. Lets focus on testing and aligning TSQL Behaviour and using wireshark