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)
| 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. |
| 54 | func 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 | |
| 95 | func getKeysNeedCheckOneRow(ctx sessionctx.Context, t table.Table, row []types.Datum, nUnique int, handleCols []*table.Column, |
| 96 | pkIdxInfo *model.IndexInfo, result []toBeCheckedRow) ([]toBeCheckedRow, error) { |
no test coverage detected