Practice
Solution
Step 1: Understand the 1:N relationship
Each employee belongs to one department; department is the 'one' side.Step 2: Referential integrity requires foreign key
Employee table must have a foreign key referencing Department's primary key.Step 3: Insert employee with valid department reference
Before inserting employee, ensure the department exists to avoid foreign key violation.Step 4: Evaluate other options
Insert the employee record first, then create the department record if missing inserts employee before department, risking integrity violation. Insert the department record with a foreign key referencing the employee's primary key reverses foreign key direction, which is incorrect. Insert the employee record without any reference to the department omits foreign key, breaking relationship.Final Answer:
Option B -> Option BQuick Check:
Foreign keys must reference existing primary keys to maintain integrity.
- Inserting dependent records before referenced records
- Misplacing foreign keys on the 'one' side instead of 'many' side
Solution
Step 1: Initial cardinality estimation
The optimizer starts by estimating the total number of rows in the table.Step 2: Apply filter selectivity
It adjusts cardinality by applying the estimated selectivity of the filter predicate, reducing the row count.Step 3: Use adjusted cardinality for access path selection
The reduced cardinality informs the choice of index scans or full scans.Step 4: Why other options are incorrect
The optimizer ignores filter predicates during cardinality estimation and applies them only at execution time: Ignoring filters during estimation leads to poor plans.
The optimizer assumes filter predicates reduce cardinality to zero if any predicate exists: Assuming zero cardinality is unrealistic and would discard valid plans.
The optimizer estimates cardinality after choosing the access path, not before: Cardinality estimation precedes access path selection to guide it.Final Answer:
Option A -> Option AQuick Check:
Filter predicates reduce estimated rows before access path decisions.
- Thinking filters are ignored until execution
- Assuming filters eliminate all rows
- Believing cardinality is estimated after access path choice
Solution
Step 1: Analyze insert performance claim
Clustered indexes may slow inserts if rows must be inserted in the middle, causing page splits.Step 2: Evaluate storage space claim
Clustered indexes do not eliminate index structures; non-clustered indexes still exist and clustered index is part of data storage.Step 3: Understand update impact
Updating clustered index key causes physical row movement, which can degrade performance.Step 4: Assess suitability for high cardinality random access
Clustered indexes are less beneficial for random access on high cardinality columns; non-clustered indexes often better.Final Answer:
Option B -> Option BQuick Check:
Frequent updates on clustered key -> performance hit due to physical row moves [OK]
- Assuming clustered indexes always speed inserts
- Believing clustered indexes save storage by removing indexes
- Thinking clustered indexes are best for random access on high cardinality columns
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: Understand deadlock conditions
Deadlocks happen when transactions cyclically wait for locks held by each other, which can occur under 2PL.Step 2: Analyze deadlock prevention
Strict 2PL does not guarantee deadlock prevention; it only ensures serializability.Step 3: Evaluate options
A, B, and D are correct statements. C is incorrect because strict 2PL does not prevent deadlocks by ordering lock acquisition.Final Answer:
Option A -> Option AQuick Check:
Deadlocks require detection and resolution even under strict 2PL.
- Assuming strict 2PL prevents deadlocks
- Confusing deadlock detection with prevention
- Believing 2PL eliminates all concurrency issues
