Created examples for deadlock on each isolation level

This commit is contained in:
Maksymilian Lúmenn Stachowiak 2023-12-11 23:43:31 +01:00
commit 3e696f7d83
8 changed files with 132 additions and 0 deletions

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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