• Keine Ergebnisse gefunden

Homework 1

N/A
N/A
Protected

Academic year: 2022

Aktie "Homework 1"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Homework 1

Points: 1 (1/8 per Question)

Deadline: 20.10.2020 23:59 (System time in Blackboard)

Create a table accounts with two columns, aid and balance, both of type integer. Insert two tuples: (1, 1000) and (2, 2000). Isolation level: read committed (default).

Execute the following transactions (imitating two concurrent money withdrawals from the same account). Before updating the balance with the new value, the transactions verify if there is enough money on the account (Step 3 and 4). After withdrawal, the new amount is also verified (Step 7 and 9). These tasks are imitated by the SELECT statements in steps 3, 4, 7, and 9.

Step T1 (withdraw 200) T2 (withdraw 1000)

1 BEGIN;

2 BEGIN;

3 SELECT balance into X

FROM accounts WHERE aid = 1;

4 SELECT balance into Y

FROM accounts WHERE aid = 1;

5 UPDATE accounts

SET balance = X - 200 WHERE aid = 1;

6 UPDATE accounts

SET balance = Y - 1000 WHERE aid = 1;

7 SELECT balance into X

FROM accounts WHERE aid = 1;

8 COMMIT;

9 SELECT balance into Y

FROM accounts WHERE aid = 1;

10 COMMIT;

Questions

Answer the following 8 questions in the Test in Blackboard.

1) What are the values of variables X and Y in step 4?

2) After step 10, is the update made by T1 in step 5 reflected on the database or is it lost?

Shortly explain.

3) What happens after step 6?

4) What are the values seen by `T1` in step 7 and `T2` in step 9? Is the balance of the account correct with respect to intended withdrawal tasks?

(2)

5) What happens to `T1` and `T2` if `T1` rolls back in step 7?

6) After swapping steps 4 and 5, does `T2` see the value updated by `T1`? Why is that so?

7) What happens if we partially modify the UPDATE statements with `SET balance = balance - 200` for `T1` and `SET balance = balance - 1000` for `T2`? Is the balance correct after the transactions commit?

8) How to fix the scenario to disallow a negative balance?

Referenzen

ÄHNLICHE DOKUMENTE

1) Karten mit schwarzen Zahlen der Reihe nach auslegen. Jeder schwarzen Zahl eine passende rote Zahl zuordnen, so dass das Ergebnis immer 10 ist. 2) Karten an zwei

Die Plättchennummer (entspricht der Aufgabennummer) und wird mit der entsprechenden Lösung auf das Nummernfeld gelegt.. Bei richtiger Lösung ergeben alle Plättchen ein Muster auf

Weitere anspruchsvolle Proben für das Fach Mathematik in der zweiten Klasse findest Du auf unserer Partnerseite www.CATLUX.de.. Dort gibt es ausführliche Musterlösungen,

a) At first, listen to the sentences. Look at the pictures. Point to the right picture. b) Now listen to the story again.. Put the pictures into the

[r]

Fredi Bär besucht Berni Biber.. Hurra, die Tablette tut dem

To focus on the effects of tenure, we restricted our sample to workers who were in the displacing firm for the entire period up until the displacement event, left the firm at the

Zeile: (7+1–4)·6=24 Finde zu möglichst vielen Kombinationen mindestens eine Lösung und