optimizeDupKeyCheckForNormalInsert trys to optimize the DupKeyCheckMode for an insert statement according to the transaction and system variables. If the DupKeyCheckMode of the current statement can be optimized, it will return `DupKeyCheckLazy` to avoid the redundant requests to TiKV, otherwise, `D
(vars *variable.SessionVars, txn kv.Transaction)
| 328 | // This method only works for "normal" insert statements, that means the options like "IGNORE" and "ON DUPLICATE KEY" |
| 329 | // in a statement are not considerate, and callers should handle the above cases by themselves. |
| 330 | func optimizeDupKeyCheckForNormalInsert(vars *variable.SessionVars, txn kv.Transaction) table.DupKeyCheckMode { |
| 331 | if !vars.ConstraintCheckInPlace || txn.IsPessimistic() || txn.IsPipelined() { |
| 332 | // We can just check duplicated key lazily without keys in storage for the below cases: |
| 333 | // - `txn.Pipelined()` is true. |
| 334 | // It means the user is using `@@tidb_dml_type="bulk"` to insert rows in bulk mode. |
| 335 | // DupKeyCheckLazy should be used to improve the performance. |
| 336 | // - The current transaction is pessimistic. The duplicate key check can be postponed to the lock stage. |
| 337 | // - The current transaction is optimistic but `tidb_constraint_check_in_place` is set to false. |
| 338 | return table.DupKeyCheckLazy |
| 339 | } |
| 340 | return table.DupKeyCheckInPlace |
| 341 | } |
| 342 | |
| 343 | // getPessimisticLazyCheckMode returns the lazy check mode for pessimistic txn. |
| 344 | // The returned `PessimisticLazyDupKeyCheckMode` only takes effect for pessimistic txn with `DupKeyCheckLazy`; |
no test coverage detected
searching dependent graphs…