Practice
Solution
Step 1: Understand MVCC version management
MVCC stores multiple versions of rows to provide snapshot isolation, which increases storage usage and requires vacuuming or cleanup.Step 2: Analyze locking overhead
MVCC reduces locking but does not eliminate all contention, especially for writes.Step 3: Analyze isolation guarantees
MVCC typically provides snapshot isolation, which can allow anomalies; serializability requires additional mechanisms.Step 4: Analyze write amplification
MVCC increases write amplification due to version creation, not reduces it.Final Answer:
Option A -> Option AQuick Check:
MVCC trades off storage and cleanup overhead for concurrency benefits [OK]
- Assuming MVCC removes all contention
- Confusing snapshot isolation with serializability
- Believing MVCC reduces write amplification
Solution
Step 1: Understand BCNF vs 3NF
BCNF is stricter than 3NF and removes all anomalies caused by functional dependencies. However, BCNF decomposition can sometimes break dependency preservation, requiring more complex joins.Step 2: Analyze trade-offs
3NF preserves dependencies and avoids most anomalies, making it a practical compromise. BCNF may require additional joins and complicate queries.Step 3: Evaluate incorrect options
BCNF always increases redundancy compared to 3NF is false because BCNF reduces redundancy. 3NF does not remove any transitive dependencies, making it simpler is false because 3NF removes transitive dependencies. BCNF allows partial dependencies which 3NF disallows is false because BCNF disallows partial dependencies.Final Answer:
Option D -> Option DQuick Check:
BCNF can sacrifice dependency preservation for stricter normalization.
- Assuming BCNF always reduces redundancy without cost
- Believing 3NF leaves transitive dependencies
- Confusing partial dependencies allowed in BCNF
Solution
Step 1: Analyze write throughput scaling
Sharding can improve write throughput, but it does not guarantee linear scaling because of coordination overhead and cross-shard operations.Step 2: Understand query complexity
Cross-shard joins increase query complexity and can degrade performance, so this is a true trade-off, not a misconception.Step 3: Recognize shard key importance
A poor shard key causes hotspots and uneven load, a well-known limitation.Step 4: Consider transactional complexity
Distributed transactions across shards require complex coordination, increasing system complexity.Step 5: Identify misconception
The misconception is that sharding always improves write throughput linearly, which is false due to overheads.Final Answer:
Option A -> Option AQuick Check:
Sharding improves throughput but not always linearly due to overheads.
- Assuming perfect linear scaling with shards
- Ignoring cross-shard query overhead
- Underestimating transaction complexity
Solution
Step 1: Analyze data structure used for order_customer_ids
Using a list causes O(m) lookup per customer, leading to O(n*m) time and duplicates.Step 2: Identify impact on performance and correctness
Using a set enables O(1) lookups and avoids duplicates, improving performance and correctness.Final Answer:
Option C -> Option CQuick Check:
Replacing list with set fixes performance and duplicate issues [OK]
- Using list instead of set for membership
- Confusing customer_id with order_id
- Assuming duplicates are handled automatically
Solution
Step 1: Understand requirement change
Ranking each sale instance means no aggregation; each row is ranked by sales_amount within category.Step 2: Adjust query accordingly
Remove GROUP BY and SUM; apply RANK() window function directly on sales table partitioned by category ordered by sales_amount DESC.Final Answer:
Option D -> Option DQuick Check:
Ranking individual sales requires no aggregation [OK]
- Trying to aggregate then rank individual rows
- Misusing HAVING to filter non-aggregated columns
