vault backup: 2024-04-15 19:20:46

This commit is contained in:
2024-04-15 19:20:46 +01:00
parent 30bfa6f243
commit 9d548c7912
22 changed files with 23784 additions and 26 deletions

View File

@@ -0,0 +1,136 @@
# 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)
![](Pasted%20image%2020240415135455.png)
#### ii)
Root Node: $\pi$ ( factory.name )
Leaf Nodes: factory, order
#### iii)
Line-by-line:
1. 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.
2. 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.
3. 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.
4. 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)**
*Consistency: Database should be in a consistent state, prior to a transaction and after. e.g. Following constraints, relationships, etc.
Isolation: All transactions should by fully independent from concurrently executing transactions.
Durability: When a transaction is committed, it's effect should be permanent in the database, withstanding system failures or restarts.*
*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: A DBMS would enforce constraints on a transaction, assuring the defined rules / relationships are followed.
Isolation: 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.*
### b)
To guarantee consistency, a DBMS handles the enforcement of atomicity, consistency, isolation and durability, along with concurrency control to prevent conflicts.
Transfer of crates:
```sql
UPDATE warehouses
SET crates = crates - 3
WHERE wname = 'warehouse1'
UPDATE warehouses
SET crates = crates + 3
WHERE wname = 'warehouse2';
```
### 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)
![](Pasted%20image%2020240415190010.png)
#### 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)
![](Pasted%20image%2020240415190127.png)
#### ii)
Deadlock does not occur, since there are no cycles in the graph
### d)
#### i)
The recovery manager would first identify in-progress transactions at the time of failure
# Q4
### a)
#### i)
```sql
SELECT partName
FROM part
WHERE partPrice > 100;
```
#### ii)
```sql
SELECT
```