Practice
Solution
Step 1: Understand CAP priorities
The database prioritizes availability and partition tolerance, so it must remain operational during partitions.Step 2: Effect on writes and reads
Writes continue independently on partitioned nodes to maintain availability, which can cause data divergence.Step 3: Impact on consistency
Because nodes can't synchronize during partition, clients may read stale or divergent data temporarily.Final Answer:
Option A -> Option AQuick Check:
Availability + Partition tolerance -> possible stale reads during partition [OK]
- Assuming writes are blocked to maintain consistency
- Believing reads are rejected during partitions
- Thinking consistency is instantly restored during partition
Solution
Step 1: Understand hash index key distribution
Hash indexes distribute keys across buckets based on hash values, losing key order.Step 2: Range query implications
Because keys are unordered, range queries require scanning all buckets or the entire table.Step 3: Evaluate distractors
Hash indexes can efficiently support range queries by scanning only relevant buckets, resulting in O(log n) time. incorrectly claims efficient bucket scanning for ranges. Hash indexes perform better than B+ trees for range queries because hashing reduces disk I/O. wrongly states hash indexes outperform B+ trees for range queries. Hash indexes can be modified to support range queries by sorting keys within each bucket. suggests sorting within buckets, which is not standard and does not solve global ordering.Final Answer:
Option A -> Option AQuick Check:
Hash index + range query -> full scan needed [OK]
- Assuming hash buckets are ordered
- Believing hash indexes reduce I/O for range queries
- Thinking sorting within buckets enables global range queries
Solution
Step 1: Understand cost estimation limitations
Cost estimation relies on statistics that may be stale or incomplete, leading to inaccuracies.Step 2: Analyze each option
Cost estimation always accurately predicts query execution time because it uses precise statistics: Cost estimation is heuristic, not always precise.
Cost estimation can be inaccurate due to outdated statistics or assumptions about data distribution: Correct--statistics can be outdated or assumptions invalid.
Cost estimation ignores CPU costs and focuses only on I/O costs: Cost models consider CPU, I/O, and sometimes network.
Cost estimation is unnecessary if the query uses indexes: Index usage reduces cost but estimation is still needed.Final Answer:
Option D -> Option DQuick Check:
Cost estimation is an approximation influenced by statistics quality.
- Believing cost estimation is perfectly accurate
- Thinking cost models ignore CPU costs
- Assuming indexes remove the need for cost estimation
Solution
Step 1: Identify operations in the query
The query aggregates sales (O(n)) then applies window function with ORDER BY, which requires sorting.Step 2: Analyze sorting cost in window function
Sorting all rows by category and total_sales costs O(n log n), dominating the complexity.Final Answer:
Option B -> Option BQuick Check:
Sorting inside window function -> O(n log n) time [OK]
- Assuming linear time ignoring sorting
- Confusing n and m in 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
