Practice
Solution
Step 1: Identify the query type
The query performs exact-match lookups, which hash indexes optimize efficiently.Step 2: Understand hash index strengths
Hash indexes provide average O(1) time for equality lookups but do not support ordered traversal.Step 3: Understand B+ tree strengths
B+ trees support ordered traversal and range queries but equality lookups are O(log n), slower than hash indexes.Step 4: Evaluate distractors
B+ tree index, because it supports efficient range queries. is incorrect because range queries are not the focus here. B+ tree index, because it provides faster equality lookups than hash indexes. wrongly claims B+ trees are faster for equality lookups. Hash index, because it supports ordered traversal for range queries. incorrectly states hash indexes support ordered traversal.Final Answer:
Option B -> Option BQuick Check:
Exact-match queries -> hash index [OK]
- Confusing hash indexes as supporting range queries
- Assuming B+ trees are always faster for equality lookups
- Believing hash indexes maintain order
Solution
Step 1: Both transactions request shared locks
Shared locks are compatible, so T1 and T2 both acquire shared locks simultaneously.Step 2: T1 requests exclusive lock (lock upgrade)
Exclusive lock is incompatible with shared locks held by others, so T1 must wait until T2 releases its shared lock.Step 3: T1 waits; T2 continues holding shared lock
T1 cannot upgrade immediately; it must wait for T2 to release.Final Answer:
Option D -> Option DQuick Check:
Lock compatibility rules prevent immediate exclusive lock upgrade when others hold shared locks.
- Assuming lock upgrade is immediate despite other shared locks
- Believing shared locks are exclusive
- Ignoring lock compatibility rules
Solution
Step 1: Understand N:M relationship representation
Direct N:M relationships are not supported as foreign keys in relational tables.Step 2: Identify issues with direct implementation
Trying to store multiple foreign keys in one table leads to redundancy and integrity problems.Step 3: Use associative table to resolve
Associative (junction) tables break N:M into two 1:N relationships, maintaining normalization and integrity.Step 4: Evaluate other options
Because relational databases do not support multiple foreign keys in a single table is false; tables can have multiple foreign keys. Because N:M relationships require storing duplicate primary keys in both tables is incorrect; primary keys are not duplicated but referenced. Because N:M relationships can only be represented using triggers is false; triggers are not required for N:M representation.Final Answer:
Option A -> Option AQuick Check:
Associative tables prevent redundancy and maintain referential integrity in N:M relationships.
- Believing multiple foreign keys in one table can represent N:M directly
- Confusing primary key duplication with foreign key referencing
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
LIMIT is applied without an ORDER BY clause. Which of the following statements about the behavior of LIMIT in this case is correct, and what adjustment should be made to the simulation to reflect real SQL behavior?Solution
Step 1: Understand LIMIT behavior without ORDER BY
Without ORDER BY, LIMIT returns an arbitrary subset of rows, not sorted, so results may be inconsistent.Step 2: Adjust simulation to reflect logical execution
Simulation should keep LIMIT as the last clause executed but clarify it does not guarantee sorted output without ORDER BY.Final Answer:
Option D -> Option DQuick Check:
LIMIT applies last but unordered without ORDER BY [OK]
- Assuming LIMIT sorts rows by default
