MCPcopy Index your code
hub / github.com/pingcap/tidb / optimizeDupKeyCheckForNormalInsert

Function optimizeDupKeyCheckForNormalInsert

pkg/executor/insert.go:330–341  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
330func 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`;

Callers 4

execMethod · 0.85
execMethod · 0.85
batchUpdateDupRowsMethod · 0.85

Calls 2

IsPessimisticMethod · 0.65
IsPipelinedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…