Hint Name | Scope | Purpose |
TXSQL_FORCE_LOCK | transaction-level | Update multiple different hotspot rows within a single transaction. |
TXSQL_FORCE_LOCK_INDEPENDENT_GROUP | single-hotspot-row level | Allows the same transaction to access the same hotspot row multiple times. |
/*+ ... */ syntax for the Hint, placing it immediately after the UPDATE / INSERT / DELETE keyword:UPDATE /*+ TXSQL_FORCE_LOCK */ table_name SET col = ... WHERE ...;UPDATE /*+ TXSQL_FORCE_LOCK TXSQL_FORCE_LOCK_INDEPENDENT_GROUP */ table_name SET col = ... WHERE ...;
Placement | Actual Effect |
On the DML of the transaction's first access to row X | Row X goes to the independent group, and all subsequent accesses to row X by this transaction are allowed. |
On the DML of the transaction's second and subsequent accesses to row X | The Hint is equivalent to not being written: Row X was recorded as a "non-independent group" during its first access, and this access is judged as "accessing the same hotspot row a second time", causing the transaction to roll back. |
The current transaction is not a TXSQL_FORCE_LOCK transaction. | A warning is generated during the parsing phase + the statement is discarded, then processed as a normal statement. |
BEGIN;-- ① The first DML statement must carry TXSQL_FORCE_LOCK.UPDATE /*+ TXSQL_FORCE_LOCK */ t_account SET balance = balance + 100 WHERE id = 1;-- ② The second and subsequent DML statements do not need to carry the hint, as the transaction is already in force_lock mode.UPDATE t_account SET balance = balance + 100 WHERE id = 2;UPDATE t_account SET balance = balance + 100 WHERE id = 3;COMMIT;
BEGIN;-- ① For the first access to id=1, both hints must be applied.UPDATE /*+ TXSQL_FORCE_LOCK TXSQL_FORCE_LOCK_INDEPENDENT_GROUP */t_account SET balance = balance + 1 WHERE id = 1;-- ② Subsequent accesses to id=1 do not need and should not carry INDEPENDENT_GROUP.UPDATE t_account SET balance = balance + 1 WHERE id = 1;COMMIT;
BEGIN;-- INDEPENDENT_GROUP was omitted during the first access to id=1.UPDATE /*+ TXSQL_FORCE_LOCK */ t_account SET balance = balance + 1 WHERE id = 1;-- Adding INDEPENDENT_GROUP only during the second access is already too late.-- At this point, id=1 has already been recorded as a "non-independent group". This operation will be judged as a "second access to the same hotspot row", causing the transaction to roll back.UPDATE /*+ TXSQL_FORCE_LOCK_INDEPENDENT_GROUP */t_account SET balance = balance + 1 WHERE id = 1;COMMIT;
SHOW WARNINGS to check whether it was ignored due to incorrect placement.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback