5.3 KiB
Q1
a)
i)
1 tuple = 24 + 5 + 10 + 20 + 6 = 65b 1 block = 1024 - 24 = 1000b 1000 / 65 = 15.38, 15 tuples can be stored in 1 block 800 / 15 = 53.33, 54 blocks are needed to store all tuples in this relation.
ii)
65 - 20 = 45b 1000 / 45 = 22.22, 22 tuples per block 800 / 22 = 36.36, 37 blocks for this projection.
iii)
If the "street" attribute is unneeded, less IO operations are needed to retrieve the relevant data from disk, making the query more efficient. As a result, this also uses less disk space, and optimises memory usage for processing.
b)
i)
Add Projections
ii)
Root Node: \pi
( factory.name )
Leaf Nodes: factory, order
iii)
Line-by-line:
- This is the final attribute we want to obtain. Placing this here ensures only the necessary data is output; reduces IO operations and memory usage, as only the required data is given.
- Exists to join the 2 tables together based on the condition that the order's factory ID = factory's ID, allowing the projection root node to have the necessary data from the factory table to obtain the factory's name.
- There is an argument for this being above or below the theta join, however I have placed this here due to the heuristic principles of query optimisation, moving selection operations down the tree. This exists to "filter" the result on the condition that the order is urgent. By placing this selection after the theta join, we can "filter" more selectively and reduce the dataset size to optimise memory usage, similar to the adjacent selection operation.
- This exists to "filter" the dataset on the condition that the quantity is larger than 20 units. By placing this at the start, we ensure filtering is executed earlier, as to not waste compute resources. This reduces the dataset size, allowing the following operations to be more optimised, as there is less data to be processed.
Q2
a)
Atomicity: A transaction must be completed, or aborted. If a transaction fails, a DBMS ensures the rollback of data to allow the database to remain consistent. Consistency: Database should be in a consistent state, prior to a transaction and after. A DBMS would enforce constraints on a transaction, assuring the defined rules / relationships are followed. Isolation: All transactions should by fully independent from concurrently executing transactions. Reduces concurrency issues by restricting access to shared data until a transaction is committed. Durability: Guarantees data is permanent once committed, preventing inconsistency after failures. Should withstand system failures or restarts.
b)
To guarantee consistency, a DBMS handles the enforcement of atomicity, consistency, isolation and durability, along with concurrency control to prevent conflicts.
Ideal SQL Transfer of crates:
UPDATE warehouse
SET crates = crates - 3
WHERE wname = 'warehouse1'
UPDATE warehouse
SET crates = crates + 3
WHERE wname = 'warehouse2';
If the second query is not run, it is not the fault of the DBMS. A DBMS can only enforce ACID rules and ensure consistency, not transaction logic.
c)
By allowing concurrent execution of transactions, system resources are allocated more efficiently due to multiple operations occurring simultaneously. This has an effect of being more performant, since more transactions can be processed per second.
d)
i)
Transaction 1 updates multiple values while Transaction 2 is reading, as can be seen in t4, as 10 units are added to W1, so the sum would be 10 units too low.
ii)
Inconsistent Analysis
e)
i)
ii)
The graph is not serialisable, since there is a directed cycle in the precedence graph - the graph is cyclic.
Q3
a)
An exclusive lock is used when a transaction must update / write to an item to avoid conflicts.
b)
2-phase locking consists of a growing phase and a shrinking phase. A transaction must acquire a read or write lock on an item before operation (growing phase), after which it must release all locks and acquire no more (shrinking phase). Transactions do not have to simultaneously acquire locks, but must adhere to these rules.
c)
i)
ii)
Deadlock does not occur, since there are no cycles in the graph
d)
i)
TO DO
The recovery manager would first identify in-progress transactions at the time of failure
Q4
a)
i)
SELECT partName
FROM part
WHERE partPrice > 100;
ii)
SELECT carModel
FROM car
JOIN carPart ON car.carId = carPart.carId
GROUP BY car.carModel
HAVING COUNT(carPart.partID) > 4;
b)
If the DBA revoked auth from U2 -> U1, U4, and U5 would also have auth revoked due to cascading revokes. There is no path from U1, U4 or U5 to the DBA if U2's authorisation is revoked. U3 and U6 still have a path to the DBA, as they do not depend on U2 for authorisation, authorisation is still valid.
c)
i)
GRANT ALL PRIVILEGES ON * TO Isavella
CREATE VIEW employeeView AS
SELECT *
FROM employee
GRANT SELECT, UPDATE ON employeeView TO Laura, Naser;
ii)
CREATE VIEW projectsView AS
SELECT *
FROM project
WHERE level = 'advanced'
GRANT SELECT ON projectsView TO Jane;
iii)
REVOKE ALL PRIVILEGES ON * FROM Naser;