Practice
Solution
Step 1: Understand pessimistic locking behavior
Pessimistic locking blocks conflicting operations to prevent concurrency issues.Step 2: Analyze lock acquisition
When the first transaction holds an exclusive row-level lock, the second transaction must wait to acquire the same exclusive lock.Step 3: Outcome of concurrent update attempts
The second transaction is blocked until the first commits or rolls back, releasing the lock.Final Answer:
Option D -> Option DQuick Check:
Waiting prevents dirty writes and ensures serializability under pessimistic concurrency control.
- Thinking the second transaction aborts immediately
- Assuming the second transaction can overwrite without waiting
- Confusing shared and exclusive locks in updates
Solution
Step 1: Identify the entities involved
Students and Courses are entities.Step 2: Analyze the relationship cardinality
Students can enroll in multiple courses, and courses can have multiple students, indicating a many-to-many relationship.Step 3: Evaluate other options
Each student has exactly one student ID describes a 1:1 attribute, not a relationship. Each professor teaches only one course is a 1:1 or 1:N but not N:M. Each classroom is assigned to only one course at a time is a 1:1 or 1:N scenario.Final Answer:
Option D -> Option DQuick Check:
Many-to-many relationships occur when multiple instances of one entity relate to multiple instances of another.
- Confusing unique attributes with relationships
- Assuming 1:N when both sides can have multiple connections
Solution
Step 1: Understand lossless join vs dependency preservation
Lossless join ensures no spurious tuples after decomposition, while dependency preservation ensures all FDs are enforceable without joins.Step 2: Analyze the trade-off
Sometimes, to achieve lossless join, some dependencies may not be preserved in decomposed relations.Step 3: Scenario matching
When avoiding data anomalies is critical, lossless join is prioritized even if some dependencies are lost.Final Answer:
Option C -> Option CQuick Check:
When all functional dependencies must be preserved at the cost of possible data loss during joins reverses the priorities, C and D are irrelevant to the scenario.
- Confusing dependency preservation as more important than lossless join always
- Assuming BCNF always guarantees dependency preservation
- Believing relations without FDs need normalization
Solution
Step 1: Understand MVCC's strength in concurrency
MVCC allows readers to access snapshot versions without blocking writers, making it ideal for workloads with many reads and fewer writes.Step 2: Analyze write-heavy workloads
Write-heavy workloads with minimal reads benefit less from MVCC since version maintenance overhead can be costly.Step 3: Analyze batch updates without concurrent reads
Batch updates without concurrent reads do not leverage MVCC's snapshot isolation benefits.Step 4: Analyze strict serializability requirements
MVCC provides snapshot isolation, which may allow some anomalies; strict serializability requires stronger mechanisms.Final Answer:
Option C -> Option CQuick Check:
MVCC shines in read-heavy concurrent environments [OK]
- Assuming MVCC is best for write-heavy workloads
- Confusing snapshot isolation with strict serializability
- Believing MVCC is unnecessary without concurrent reads
SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT. To correctly process the query and produce the expected result, which approach best models the order in which these clauses are logically executed by the database engine?Solution
Step 1: Understand SQL logical execution order
SQL does not execute clauses in the written order. Instead, it first identifies data sources (FROM), then filters rows (WHERE), groups rows (GROUP BY), filters groups (HAVING), selects columns (SELECT), orders results (ORDER BY), and finally limits output rows (LIMIT).Step 2: Match problem description to logical execution order
The logical order ensures correct filtering and grouping before selection and ordering, which matches Execute clauses in the logical order: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY -> LIMIT exactly.Final Answer:
Option B -> Option BQuick Check:
Logical execution order matches database engine processing [OK]
- Assuming SQL executes clauses top-to-bottom as written
