Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
SELECT ... FOR UPDATE)SELECT ... FOR UPDATE statement can place an exclusive lock on the queried data rows, preventing other transactions from modifying or locking these data rows.START TRANSACTION;SELECT * FROM orders WHERE id = 1 FOR UPDATE;-- Operate on the queried data.UPDATE orders SET status = 'shipped' WHERE id = 1;COMMIT;
SELECT ... FOR UPDATE, if other transactions attempt to execute SELECT ... FOR UPDATE or modify operations on the same data row, they will be blocked until transaction A commits or rolls back.SELECT ... LOCK IN SHARE MODE)SELECT ... LOCK IN SHARE MODE statement to place a shared lock on the queried data rows. Shared locks allow multiple transactions to read the same data row concurrently but will prevent any transaction from modifying the data row.START TRANSACTION;SELECT * FROM products WHERE id = 1 LOCK IN SHARE MODE;-- Other transactions can read but cannot modify this data.COMMIT;
WHERE clause has an index, TDSQL Boundless will use row-level locks; if there is no index, it may escalate to range locks.-- Create tableCREATE TABLE users (user_id INT PRIMARY KEY,username VARCHAR(20));SELECT * FROM users WHERE user_id = 101 FOR UPDATE; -- Row-level lockSELECT * FROM users WHERE username = 'john' FOR UPDATE; -- Range lock (username column has no index, locks the entire table's data)SELECT * FROM users WHERE user_id >= 100 AND user_id < 200 FOR UPDATE; -- Range lock (locks data only within the user_id range [100, 200))
Comparison Dimension | TDSQL Boundless | MySQL (Based on InnoDB) | Core Differences and Impacts |
Lock target (what to lock) | Logical key (such as Primary Key = 15) | Physical storage location of data (Space ID + Page Number + bitmap) | The fundamental difference: TDSQL Boundless does not concern itself with the physical location of data, locking directly on the unique logical identifier. MySQL (InnoDB) locks are intricately tied to the physical page layout of the data. |
Locking a single record (such as: WHERE number=15) | Behavior is consistent: whether the record exists or not, a row-level lock is applied to the logical key primary key = 15. | Behavior diverges: 1. Record exists: apply a row-level lock to the record where number=15. 2. Record does not exist: to prevent phantom reads, a gap lock is applied, locking the interval between two adjacent records (such as number=7 and number=20). | Lock granularity and semantics: TDSQL Boundless exhibits more consistent and predictable locking behavior. MySQL (InnoDB) escalates to a broader gap lock when records are absent, potentially impacting concurrent inserts. |
Range query locking (for example: WHERE row_id BETWEEN 1 AND 20) | Holistic or adaptive decomposition: 1. No conflict: directly lock the entire logical range [1, 20]. 2. Conflict detected: if a point within the range (such as row_id=15) is already locked by another transaction, the locking range will be decomposed into non-contiguous intervals, [1, 15) + [15, 20], and wait for the lock to be released. | Segmented locking: according to the physical storage order of pages, split the query range into multiple small intervals (such as (1,3], (3,5], (5,10], and so on) and apply locks. | Locking policy: TDSQL Boundless tends to logically maintain a large lock range, decomposing only upon encountering lock conflicts. MySQL (InnoDB)'s locking granularity is influenced by physical data page divisions, resulting in finer fragmentation. |
Characteristics Summary | Direct locking: the locking process is independent of physical locations, logically clear, and particularly suitable for distributed architectures. | Locking requires prior positioning: before locks are applied, it is necessary to locate the physical page where the data resides. Lock management is tightly coupled with the storage structure. | Architectural adaptability: TDSQL Boundless implementation offers better scalability in distributed environments. MySQL (InnoDB) implementation is highly mature and efficient in single-node centralized deployments. |
피드백