Created examples for deadlock on each isolation level
This commit is contained in:
commit
3e696f7d83
18
read commited/session 1.sql
Normal file
18
read commited/session 1.sql
Normal file
@ -0,0 +1,18 @@
|
||||
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
|
||||
|
||||
BEGIN TRANSACTION
|
||||
UPDATE Wycieczki
|
||||
SET cena = cena*2
|
||||
WHERE
|
||||
kraj = 'Bangkok'
|
||||
-- STEP 1 RUN ABOVE
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
Bilety
|
||||
WHERE
|
||||
kraj = 'Ateny'
|
||||
-- STEP 3 RUN BETWEEN 1 AND 3
|
||||
|
||||
COMMIT TRANSACTION
|
18
read commited/session 2.sql
Normal file
18
read commited/session 2.sql
Normal file
@ -0,0 +1,18 @@
|
||||
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
|
||||
|
||||
BEGIN TRANSACTION
|
||||
UPDATE Bilety
|
||||
SET cena = cena * 2
|
||||
WHERE
|
||||
kraj = 'Ateny'
|
||||
-- STEP 2 - RUN ABOVE
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
Wycieczki
|
||||
WHERE
|
||||
kraj = 'Bangkok'
|
||||
-- STEP 4 RUN BETWEEN 2 AND 4
|
||||
|
||||
COMMIT TRANSACTION
|
16
read uncomitted/session 1.sql
Normal file
16
read uncomitted/session 1.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
|
||||
|
||||
BEGIN TRANSACTION
|
||||
UPDATE Wycieczki
|
||||
SET cena = 2
|
||||
WHERE
|
||||
kraj = 'Bangkok'
|
||||
-- STEP 1 RUN ABOVE
|
||||
|
||||
UPDATE Bilety
|
||||
SET cena = 2
|
||||
WHERE
|
||||
kraj = 'Ateny'
|
||||
-- STEP 3 RUN BETWEEN 1 AND 3
|
||||
|
||||
COMMIT TRANSACTION
|
16
read uncomitted/session 2.sql
Normal file
16
read uncomitted/session 2.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
|
||||
|
||||
BEGIN TRANSACTION
|
||||
UPDATE Bilety
|
||||
SET cena = 1
|
||||
WHERE
|
||||
kraj = 'Ateny'
|
||||
-- STEP 2 - RUN ABOVE
|
||||
|
||||
UPDATE Wycieczki
|
||||
SET cena = 1
|
||||
WHERE
|
||||
kraj = 'Bangkok'
|
||||
-- STEP 4 RUN BETWEEN 2 AND 4
|
||||
|
||||
COMMIT TRANSACTION
|
16
repeatable read/session 1.sql
Normal file
16
repeatable read/session 1.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
|
||||
|
||||
BEGIN TRANSACTION T1
|
||||
SELECT
|
||||
SUM(Cena)
|
||||
FROM
|
||||
Wycieczki
|
||||
-- STEP 1 RUN ABOVE
|
||||
|
||||
UPDATE Bilety
|
||||
SET cena = cena * 2
|
||||
WHERE
|
||||
kraj = 'Ateny'
|
||||
-- STEP 3 RUN BETWEEN 1 AND 3
|
||||
|
||||
COMMIT TRANSACTION T1
|
16
repeatable read/session 2.sql
Normal file
16
repeatable read/session 2.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
|
||||
|
||||
BEGIN TRANSACTION T2
|
||||
SELECT
|
||||
SUM(Cena)
|
||||
FROM
|
||||
Bilety
|
||||
-- STEP 2 RUN ABOVE
|
||||
|
||||
UPDATE Wycieczki
|
||||
SET cena = cena * 2
|
||||
WHERE
|
||||
kraj = 'Bangkok'
|
||||
-- STEP 4 RUN BETWEEN 2 AND 4
|
||||
|
||||
COMMIT TRANSACTION T2
|
16
serializable/session 1.sql
Normal file
16
serializable/session 1.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
|
||||
|
||||
BEGIN TRANSACTION
|
||||
SELECT
|
||||
SUM(Cena)
|
||||
FROM
|
||||
Wycieczki
|
||||
-- STEP 1 RUN ABOVE
|
||||
|
||||
INSERT INTO
|
||||
Bilety
|
||||
VALUES
|
||||
(2, 'Honolulu', 1, 2000);
|
||||
-- STEP 3 RUN BETWEEN 1 AND 3
|
||||
|
||||
COMMIT TRANSACTION
|
16
serializable/session 2.sql
Normal file
16
serializable/session 2.sql
Normal file
@ -0,0 +1,16 @@
|
||||
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
|
||||
|
||||
BEGIN TRANSACTION
|
||||
SELECT
|
||||
SUM(Cena)
|
||||
FROM
|
||||
Bilety
|
||||
-- STEP 2 RUN ABOVE
|
||||
|
||||
INSERT INTO
|
||||
Wycieczki
|
||||
VALUES
|
||||
('Honolulu', 2000)
|
||||
-- STEP 4 RUN BETWEEN 2 AND 4
|
||||
|
||||
COMMIT TRANSACTION
|
Loading…
Reference in New Issue
Block a user