@@ -1190,11 +1190,9 @@ func (e *InsertValues) handleDuplicateKey(ctx context.Context, txn kv.Transactio
1190
1190
// All duplicate rows will be ignored and appended as duplicate warnings.
1191
1191
func (e * InsertValues ) batchCheckAndInsert (
1192
1192
ctx context.Context , rows [][]types.Datum ,
1193
- addRecord func (ctx context.Context , row []types.Datum ) error ,
1193
+ addRecord func (ctx context.Context , row []types.Datum , dupKeyCheck table. DupKeyCheckMode ) error ,
1194
1194
replace bool ,
1195
1195
) error {
1196
- // all the rows will be checked, so it is safe to set BatchCheck = true
1197
- e .Ctx ().GetSessionVars ().StmtCtx .BatchCheck = true
1198
1196
defer tracing .StartRegion (ctx , "InsertValues.batchCheckAndInsert" ).End ()
1199
1197
start := time .Now ()
1200
1198
// Get keys need to be checked.
@@ -1307,7 +1305,8 @@ func (e *InsertValues) batchCheckAndInsert(
1307
1305
// it should be added to values map for the further row check.
1308
1306
// There may be duplicate keys inside the insert statement.
1309
1307
e .Ctx ().GetSessionVars ().StmtCtx .AddCopiedRows (1 )
1310
- err = addRecord (ctx , rows [i ])
1308
+ // all the rows have been checked, so it is safe to use DupKeyCheckSkip
1309
+ err = addRecord (ctx , rows [i ], table .DupKeyCheckSkip )
1311
1310
if err != nil {
1312
1311
// throw warning when violate check constraint
1313
1312
if table .ErrCheckConstraintViolated .Equal (err ) {
@@ -1405,21 +1404,21 @@ func (e *InsertValues) equalDatumsAsBinary(a []types.Datum, b []types.Datum) (bo
1405
1404
return true , nil
1406
1405
}
1407
1406
1408
- func (e * InsertValues ) addRecord (ctx context.Context , row []types.Datum ) error {
1409
- return e .addRecordWithAutoIDHint (ctx , row , 0 )
1407
+ func (e * InsertValues ) addRecord (ctx context.Context , row []types.Datum , dupKeyCheck table. DupKeyCheckMode ) error {
1408
+ return e .addRecordWithAutoIDHint (ctx , row , 0 , dupKeyCheck )
1410
1409
}
1411
1410
1412
1411
func (e * InsertValues ) addRecordWithAutoIDHint (
1413
- ctx context.Context , row []types.Datum , reserveAutoIDCount int ,
1412
+ ctx context.Context , row []types.Datum , reserveAutoIDCount int , dupKeyCheck table. DupKeyCheckMode ,
1414
1413
) (err error ) {
1415
1414
vars := e .Ctx ().GetSessionVars ()
1416
1415
if ! vars .ConstraintCheckInPlace {
1417
1416
vars .PresumeKeyNotExists = true
1418
1417
}
1419
1418
if reserveAutoIDCount > 0 {
1420
- _ , err = e .Table .AddRecord (e .Ctx ().GetTableCtx (), row , table .WithCtx (ctx ), table .WithReserveAutoIDHint (reserveAutoIDCount ))
1419
+ _ , err = e .Table .AddRecord (e .Ctx ().GetTableCtx (), row , table .WithCtx (ctx ), table .WithReserveAutoIDHint (reserveAutoIDCount ), dupKeyCheck )
1421
1420
} else {
1422
- _ , err = e .Table .AddRecord (e .Ctx ().GetTableCtx (), row , table .WithCtx (ctx ))
1421
+ _ , err = e .Table .AddRecord (e .Ctx ().GetTableCtx (), row , table .WithCtx (ctx ), dupKeyCheck )
1423
1422
}
1424
1423
vars .PresumeKeyNotExists = false
1425
1424
if err != nil {
@@ -1429,7 +1428,7 @@ func (e *InsertValues) addRecordWithAutoIDHint(
1429
1428
if e .lastInsertID != 0 {
1430
1429
vars .SetLastInsertID (e .lastInsertID )
1431
1430
}
1432
- if ! vars . StmtCtx . BatchCheck {
1431
+ if dupKeyCheck != table . DupKeyCheckSkip {
1433
1432
for _ , fkc := range e .fkChecks {
1434
1433
err = fkc .insertRowNeedToCheck (vars .StmtCtx , row )
1435
1434
if err != nil {
0 commit comments