0% found this document useful (0 votes)
11 views4 pages

DB2 20240717 Solutions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

DB2 20240717 Solutions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Databases 2 - exam - July 17, 2024 - Dur.

2h
S. Comai, P. Fraternali, D. Martinenghi
A. Concurrency control (12 points, up to 2 points per class)
Consider the schedule S = r4 (x) w3 (x) r4 (z) w4 (y) r2 (x) r1 (x) w2 (z) w3 (y) r2 (y) w1 (x) w1 (y). First,
classify S with respect to 2PL and TS Multi (with the conventions adopted for TS Multi under Snapshot
Isolation, used for the exercises). Then, also classify S with respect to VSR, CSR, Strict 2PL, and TS Mono,
but use
use class
class inclusion
inclusion to
to determine
determine membership
membership wherever
wherever possible
possible.
possible
Solution.
Overview
S is 2PL, and thus also CSR, and VSR. S is not Strict 2PL. S is not TS Multi and thus also not TS Mono.
Detailed analysis for the 2PL class
1 2 3 4 5 6 7 8 9 10 11

x ↑ 4 r4 ↓ 4 ↑ 3 w3 ↓ 3 ↑ 2 r2 ↑ 1 r1 ↓ 2 ↑ 1 w1 ↓ 1

y ↑4 w4 ↓ 4 ↑ 3 w3 ↓ 3 ↑ 2 r2 ↓ 2 ↑ 1 w1 ↓ 1 Legend
↑ : read lock request
z ↑4 r4 ↓ 4 ↑ 2 w2 ↓2 ↑ : write lock request
↑ : lock upgrade
4 3 2 1
↓ : unlock request

Detailed analysis for the TS Multi class


Operation RTM(x) WTM(x) RTM(y) WTM(y) RTM(z) WTM(z) Killed transactions
r4 (x) 4 (0) 0 0 (0) 0 0 (0) 0
w3 (x) 3 as 3 < RTM(x) = 4
r4 (z) 4 (0)
w4 (y) 0, 4
r2 (x) 4 (0)
r1 (x) 4 (0)
w2 (z) 2 as 2 < RTM(z) = 4
w3 (y) 3 (already killed)
r2 (y) 2 (already killed)
w1 (x) 1 as 1 < RTM(x) = 4
w1 (y) 1 (already killed)
Detailed analysis for the Strict 2PL class
1 2 3 4 56 7 8 9 10 11

x r4 ↓ 4 w3 ↓ 3 r2 r1 w1
4 3
y w4 ●∣ w3 ●∣ r2 w1 Legend
↓ : mandatory unlock request
z r4 w2 ∣●: commit time
B. Ranking (12 points, up to 4 points per sub-question)

Consider a dataset with attributes x, y, and z, where high values are better than low values.
x y z x y z x y z
D: 10 2 4 C: 1 0 5 D: 10 0 5
E: 6 1 5 E: 6 1 5 E: 5 0 5
A: 4 1 2 I: 2 0 5 A: 5 0 0
F: 2 2 3 D: 10 2 4 H: 0 5 5
T1 = H: 2 7 4 T2 = G: 0 0 4 T3 = J: 0 5 0
I: 2 0 5 H: 2 7 4 B: 0 5 0
J: 2 3 1 F: 2 2 3 F: 0 0 5
C: 1 0 5 A: 4 1 2 I: 0 0 5
B: 0 6 0 J: 2 3 1 C: 0 0 5
G: 0 0 4 B: 0 6 0 G: 0 0 5
1. The table on the left, T1 , shows the dataset already sorted with respect to x. Use SFS to compute the
skyline of T1 . Make sure to indicate all dominance tests made by the algorithm.
2. Consider now table T2 , shown in the center, which is the same as T1 but sorted with respect to z.
Compute the skyline of T2 with SFS (no need to show all steps) and comment on the results you
obtained.
3. Table T3 , on the right, has the same data as the other ones, but with values approximated to the
closest multiple of 5. Compute its skyline (no need to show all steps) and clarify whether, in general
(not just with this specific dataset), after the approximation step: a) a non-skyline point can become
skyline; b) a skyline point can become non-skyline.
Solution.

1. The dataset is already sorted, so we do not need to pre-sort it (but see the answer to the following
point). There are 16 dominance tests: D ≺/ E, D ≺ A, D ≺ F , D ≺/ H, E ≺/ H, D ≺/ I, E ≺ I, D ≺/ J,
E ≺/ J, H ≺ J, D ≺/ C, E ≺ C, D ≺/ B, E ≺/ B, H ≺ B, D ≺ G. The skyline is {D, E, H}.
2. If we proceed as in the previous point, we obtain the skyline {C, E, D, H}, which unlike the previous
one, also contains C. After a closer inspection, we observe that the sorting criterion based solely on z
cannot distinguish between C and E (and I) even though C is dominated by E, so placing C before
E constitutes a violation of the topological sort principle used by SFS according to which a preceding
item cannot be dominated by a subsequent item. We note that the principle is violated in T1 , too
(since F precedes but is dominated by H), but the final result remains correct (F is also dominated
by D and thus removed).

3. a) In this specific case, the skyline becomes {D, H}, so a skyline point (like E) can become non-
skyline. Indeed, E becomes dominated by D, because its advantage in the z attribute is lost due to
the approximation. b) No non-skyline point becomes skyline in this example, but this may very well
happen: consider a dataset with just two points α = ⟨2, 2⟩ and β = ⟨1, 1⟩; clearly α ≺ β, but after the
approximation they coincide and thus are both skyline points.
C. Triggers
An urban pollution monitoring system monitors the concentration of various pollutants through ground
stations. Each ground station monitors the concentration of all the pollutants and inserts in the central
database a record only when a change of value is detected. A set of triggers reacts to the insertion of a
record by updating the pollution statistics and emitting an alert when threshold values are exceeded at a
station. The central database has the following relational schema (primary keys are uppercase):

STATION(SID, name, status)


POLLUTANT(PID, name, threshold)
RECORD(SID, PID, TIMESTAMP, value)
STATS(SID, PID, average, peak)
ALERT(SID, TIMESTAMP)

Define a set of triggers that react when a ground station inserts a record, as follows:
• The average value at that station of the pollutant mentioned in the record is updated.
• If the recorded value exceeds the maximum value sensed in the station for the pollutant, the peak of
the pollutant at the station is updated to the recorded value.

• If the peak value of ANY pollutant exceeds the threshold, the status of the station where the value is
sensed is set to critical, and an alert tuple is created (or updated, if already existing) to register the
last timestamp at which the alert is raised at that station.
• If 10 subsequent below-threshold values are recorded in a critical station after the last alert, the
station’s status is reset to normal and that alert is deleted.
Assumptions:
• Assume that the monitoring is weekly and the data are cleaned up every Monday at 00:00 so that it is
not necessary to consider the date and time in the record’s timestamp when computing the (weekly)
average and peak.

• Timestamps are distinct integer numbers in progressive order of time.


• At the beginning of each week the average and peak values of each pollutant in each station are set to
0 and the status of each station is set to normal.
Solution.

CREATE TRIGGER T1
AFTER INSERT ON RECORD

BEGIN
UPDATE STATS
SET AVERAGE = (SELECT AVG(value) FROM RECORD
WHERE PID = NEW.PID AND SID = NEW.SID)
WHERE SID = NEW.SID AND PID = NEW.PID;
END;

CREATE TRIGGER T2
AFTER INSERT ON RECORD

BEGIN
IF NEW.value >= (SELECT peak FROM STATS WHERE SID = NEW.SID AND PID = NEW.PID) THEN
UPDATE STATS
SET peak = NEW.value
WHERE SID = NEW.SID AND PID = NEW.PID;
END IF;
END;
CREATE TRIGGER T3
AFTER UPDATE OF peak ON STATS

DECLARE MAX_TS INT;

BEGIN
SELECT max(timestamp) INTO MAX_TS from record WHERE SID = new.SID;
IF NEW.peak > (SELECT threshold FROM POLLUTANT WHERE PID = NEW.PID) THEN
UPDATE STATION
SET status = ’critical’
WHERE SID = NEW.SID;

IF EXISTS (SELECT * FROM ALERT WHERE SID = NEW.SID) THEN


UPDATE ALERT
SET timestamp = MAX_TS
WHERE SID = NEW.SID;
ELSE
INSERT INTO ALERT (SID, timestamp)
VALUES (NEW.SID, MAX_TS);
END IF;
END IF;
END;

CREATE TRIGGER T4
AFTER INSERT ON RECORD

WHEN (SELECT STATUS FROM STATION WHERE SID = NEW.SID) = ’critical’

DECLARE
ALERT_TS INT;

BEGIN
SELECT timestamp INTO ALERT_TS
FROM ALERT
WHERE ALERT.SID = NEW.SID;

IF (SELECT COUNT(*)
FROM RECORD
JOIN POLLUTANT ON RECORD.SID = NEW.SID AND RECORD.PID = POLLUTANT.PID
WHERE timestamp >= ALERT_TS AND value <= threshold) > 10 THEN
DELETE FROM ALERT WHERE SID = NEW.SID;

UPDATE STATION
SET STATUS = ’normal’
WHERE SID = NEW.SID;
END IF;
END;

You might also like