MCPcopy
hub / github.com/pingcap/tidb / getKeysNeedCheck

Function getKeysNeedCheck

pkg/executor/batch_checker.go:54–93  ·  view source on GitHub ↗

getKeysNeedCheck gets keys converted from to-be-insert rows to record keys and unique index keys, which need to be checked whether they are duplicate keys.

(sctx sessionctx.Context, t table.Table, rows [][]types.Datum)

Source from the content-addressed store, hash-verified

52// getKeysNeedCheck gets keys converted from to-be-insert rows to record keys and unique index keys,
53// which need to be checked whether they are duplicate keys.
54func getKeysNeedCheck(sctx sessionctx.Context, t table.Table, rows [][]types.Datum) ([]toBeCheckedRow, error) {
55 nUnique := 0
56 for _, v := range t.Indices() {
57 if !tables.IsIndexWritable(v) {
58 continue
59 }
60 if v.Meta().Unique {
61 nUnique++
62 }
63 }
64 toBeCheckRows := make([]toBeCheckedRow, 0, len(rows))
65
66 var (
67 tblHandleCols []*table.Column
68 pkIdxInfo *model.IndexInfo
69 )
70 // Get handle column if PK is handle.
71 if t.Meta().PKIsHandle {
72 for _, col := range t.Cols() {
73 if col.IsPKHandleColumn(t.Meta()) {
74 tblHandleCols = append(tblHandleCols, col)
75 break
76 }
77 }
78 } else if t.Meta().IsCommonHandle {
79 pkIdxInfo = tables.FindPrimaryIndex(t.Meta())
80 for _, idxCol := range pkIdxInfo.Columns {
81 tblHandleCols = append(tblHandleCols, t.Cols()[idxCol.Offset])
82 }
83 }
84
85 var err error
86 for _, row := range rows {
87 toBeCheckRows, err = getKeysNeedCheckOneRow(sctx, t, row, nUnique, tblHandleCols, pkIdxInfo, toBeCheckRows)
88 if err != nil {
89 return nil, err
90 }
91 }
92 return toBeCheckRows, nil
93}
94
95func getKeysNeedCheckOneRow(ctx sessionctx.Context, t table.Table, row []types.Datum, nUnique int, handleCols []*table.Column,
96 pkIdxInfo *model.IndexInfo, result []toBeCheckedRow) ([]toBeCheckedRow, error) {

Callers 3

execMethod · 0.85
batchUpdateDupRowsMethod · 0.85
batchCheckAndInsertMethod · 0.85

Calls 7

IsIndexWritableFunction · 0.92
FindPrimaryIndexFunction · 0.92
getKeysNeedCheckOneRowFunction · 0.85
IsPKHandleColumnMethod · 0.80
IndicesMethod · 0.65
MetaMethod · 0.65
ColsMethod · 0.65

Tested by

no test coverage detected