commit 3e696f7d830098c6c1b55116b8d136b48d61e79c Author: Maksymilian LĂșmenn Stachowiak Date: Mon Dec 11 23:43:31 2023 +0100 Created examples for deadlock on each isolation level diff --git a/read commited/session 1.sql b/read commited/session 1.sql new file mode 100644 index 0000000..b1e015c --- /dev/null +++ b/read commited/session 1.sql @@ -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 diff --git a/read commited/session 2.sql b/read commited/session 2.sql new file mode 100644 index 0000000..e90b931 --- /dev/null +++ b/read commited/session 2.sql @@ -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 diff --git a/read uncomitted/session 1.sql b/read uncomitted/session 1.sql new file mode 100644 index 0000000..acd70f8 --- /dev/null +++ b/read uncomitted/session 1.sql @@ -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 diff --git a/read uncomitted/session 2.sql b/read uncomitted/session 2.sql new file mode 100644 index 0000000..133efad --- /dev/null +++ b/read uncomitted/session 2.sql @@ -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 diff --git a/repeatable read/session 1.sql b/repeatable read/session 1.sql new file mode 100644 index 0000000..69e3319 --- /dev/null +++ b/repeatable read/session 1.sql @@ -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 diff --git a/repeatable read/session 2.sql b/repeatable read/session 2.sql new file mode 100644 index 0000000..1389300 --- /dev/null +++ b/repeatable read/session 2.sql @@ -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 diff --git a/serializable/session 1.sql b/serializable/session 1.sql new file mode 100644 index 0000000..1c9128d --- /dev/null +++ b/serializable/session 1.sql @@ -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 diff --git a/serializable/session 2.sql b/serializable/session 2.sql new file mode 100644 index 0000000..9a7fd52 --- /dev/null +++ b/serializable/session 2.sql @@ -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