0
0
MySQLquery~20 mins

Lock types (shared, exclusive) in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Lock Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Shared Locks

Which statement best describes a shared lock in MySQL?

AIt allows multiple transactions to write to the data simultaneously but prevents reading.
BIt allows only one transaction to read or write the data at a time.
CIt prevents all transactions from reading or writing the data until the lock is released.
DIt allows multiple transactions to read the same data simultaneously but prevents any transaction from writing to it.
Attempts:
2 left
💡 Hint

Think about what happens when many people want to read a book but no one should change it while reading.

🧠 Conceptual
intermediate
2:00remaining
Exclusive Lock Behavior

What is the main effect of an exclusive lock on a database row in MySQL?

AIt prevents other transactions from reading or writing the locked row until the lock is released.
BIt allows other transactions to read but not write the locked row.
CIt allows multiple transactions to write to the row simultaneously.
DIt only prevents other transactions from writing but allows reading.
Attempts:
2 left
💡 Hint

Imagine locking a diary so no one else can even peek or write until you finish.

query_result
advanced
2:00remaining
Result of Concurrent Shared Locks

Consider two transactions that both request a shared lock on the same row simultaneously. What will be the result?

ABoth transactions are blocked and cannot proceed until an exclusive lock is released.
BOnly the first transaction acquires the shared lock; the second waits until the first releases it.
CBoth transactions acquire the shared lock and can read the row simultaneously.
DBoth transactions acquire exclusive locks, causing a deadlock.
Attempts:
2 left
💡 Hint

Think about multiple people reading the same book at the same time.

query_result
advanced
2:00remaining
Effect of Exclusive Lock on Concurrent Shared Lock Request

Transaction A holds an exclusive lock on a row. Transaction B requests a shared lock on the same row. What happens to Transaction B?

ATransaction B waits until Transaction A releases the exclusive lock before acquiring the shared lock.
BTransaction B immediately acquires the shared lock and reads the row.
CTransaction B causes Transaction A to release the exclusive lock automatically.
DTransaction B acquires an exclusive lock instead of a shared lock.
Attempts:
2 left
💡 Hint

Think about waiting your turn when someone else is writing in a book.

schema
expert
3:00remaining
Designing Locking Strategy for High Concurrency

You have a table orders where many transactions read order details, but only a few update them. Which locking strategy optimizes concurrency while ensuring data integrity?

AUse exclusive locks for all operations to ensure maximum data safety.
BUse shared locks for reads and exclusive locks only for updates to minimize blocking.
CUse no locks and rely on application-level checks to handle conflicts.
DUse shared locks for updates and exclusive locks for reads.
Attempts:
2 left
💡 Hint

Consider how to let many people read without waiting but still protect updates.