@@ -186,7 +186,7 @@ func (e *InsertValues) insertRows(ctx context.Context, exec func(ctx context.Con
186
186
rows := make ([][]types.Datum , 0 , len (e .Lists ))
187
187
for i , list := range e .Lists {
188
188
e .rowCount ++
189
- row , err := e .evalRow (list , i )
189
+ row , err := e .evalRow (ctx , list , i )
190
190
if err != nil {
191
191
return err
192
192
}
@@ -228,7 +228,7 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int
228
228
229
229
// evalRow evaluates a to-be-inserted row. The value of the column may base on another column,
230
230
// so we use setValueForRefColumn to fill the empty row some default values when needFillDefaultValues is true.
231
- func (e * InsertValues ) evalRow (list []expression.Expression , rowIdx int ) ([]types.Datum , error ) {
231
+ func (e * InsertValues ) evalRow (ctx context. Context , list []expression.Expression , rowIdx int ) ([]types.Datum , error ) {
232
232
rowLen := len (e .Table .Cols ())
233
233
if e .hasExtraHandle {
234
234
rowLen ++
@@ -259,7 +259,7 @@ func (e *InsertValues) evalRow(list []expression.Expression, rowIdx int) ([]type
259
259
e .evalBuffer .SetDatum (offset , val1 )
260
260
}
261
261
262
- return e .fillRow (row , hasValue )
262
+ return e .fillRow (ctx , row , hasValue )
263
263
}
264
264
265
265
// setValueForRefColumn set some default values for the row to eval the row value with other columns,
@@ -320,7 +320,7 @@ func (e *InsertValues) insertRowsFromSelect(ctx context.Context, exec func(ctx c
320
320
for innerChunkRow := iter .Begin (); innerChunkRow != iter .End (); innerChunkRow = iter .Next () {
321
321
innerRow := types .CloneRow (innerChunkRow .GetDatumRow (fields ))
322
322
e .rowCount ++
323
- row , err := e .getRow (innerRow )
323
+ row , err := e .getRow (ctx , innerRow )
324
324
if err != nil {
325
325
return err
326
326
}
@@ -361,7 +361,7 @@ func (e *InsertValues) doBatchInsert(ctx context.Context) error {
361
361
// getRow gets the row which from `insert into select from` or `load data`.
362
362
// The input values from these two statements are datums instead of
363
363
// expressions which are used in `insert into set x=y`.
364
- func (e * InsertValues ) getRow (vals []types.Datum ) ([]types.Datum , error ) {
364
+ func (e * InsertValues ) getRow (ctx context. Context , vals []types.Datum ) ([]types.Datum , error ) {
365
365
row := make ([]types.Datum , len (e .Table .Cols ()))
366
366
hasValue := make ([]bool , len (e .Table .Cols ()))
367
367
for i , v := range vals {
@@ -375,7 +375,7 @@ func (e *InsertValues) getRow(vals []types.Datum) ([]types.Datum, error) {
375
375
hasValue [offset ] = true
376
376
}
377
377
378
- return e .fillRow (row , hasValue )
378
+ return e .fillRow (ctx , row , hasValue )
379
379
}
380
380
381
381
func (e * InsertValues ) filterErr (err error ) error {
@@ -409,10 +409,10 @@ func (e *InsertValues) getColDefaultValue(idx int, col *table.Column) (d types.D
409
409
}
410
410
411
411
// fillColValue fills the column value if it is not set in the insert statement.
412
- func (e * InsertValues ) fillColValue (datum types.Datum , idx int , column * table.Column , hasValue bool ) (types.Datum ,
412
+ func (e * InsertValues ) fillColValue (ctx context. Context , datum types.Datum , idx int , column * table.Column , hasValue bool ) (types.Datum ,
413
413
error ) {
414
414
if mysql .HasAutoIncrementFlag (column .Flag ) {
415
- d , err := e .adjustAutoIncrementDatum (datum , hasValue , column )
415
+ d , err := e .adjustAutoIncrementDatum (ctx , datum , hasValue , column )
416
416
if err != nil {
417
417
return types.Datum {}, err
418
418
}
@@ -430,12 +430,12 @@ func (e *InsertValues) fillColValue(datum types.Datum, idx int, column *table.Co
430
430
431
431
// fillRow fills generated columns, auto_increment column and empty column.
432
432
// For NOT NULL column, it will return error or use zero value based on sql_mode.
433
- func (e * InsertValues ) fillRow (row []types.Datum , hasValue []bool ) ([]types.Datum , error ) {
433
+ func (e * InsertValues ) fillRow (ctx context. Context , row []types.Datum , hasValue []bool ) ([]types.Datum , error ) {
434
434
gIdx := 0
435
435
for i , c := range e .Table .Cols () {
436
436
var err error
437
437
// Get the default value for all no value columns, the auto increment column is different from the others.
438
- row [i ], err = e .fillColValue (row [i ], i , c , hasValue [i ])
438
+ row [i ], err = e .fillColValue (ctx , row [i ], i , c , hasValue [i ])
439
439
if err != nil {
440
440
return nil , err
441
441
}
@@ -462,7 +462,7 @@ func (e *InsertValues) fillRow(row []types.Datum, hasValue []bool) ([]types.Datu
462
462
return row , nil
463
463
}
464
464
465
- func (e * InsertValues ) adjustAutoIncrementDatum (d types.Datum , hasValue bool , c * table.Column ) (types.Datum , error ) {
465
+ func (e * InsertValues ) adjustAutoIncrementDatum (ctx context. Context , d types.Datum , hasValue bool , c * table.Column ) (types.Datum , error ) {
466
466
retryInfo := e .ctx .GetSessionVars ().RetryInfo
467
467
if retryInfo .Retrying {
468
468
id , err := retryInfo .GetCurrAutoIncrementID ()
@@ -501,7 +501,7 @@ func (e *InsertValues) adjustAutoIncrementDatum(d types.Datum, hasValue bool, c
501
501
// Change NULL to auto id.
502
502
// Change value 0 to auto id, if NoAutoValueOnZero SQL mode is not set.
503
503
if d .IsNull () || e .ctx .GetSessionVars ().SQLMode & mysql .ModeNoAutoValueOnZero == 0 {
504
- recordID , err = e . Table . AllocAutoIncrementValue (e .ctx )
504
+ recordID , err = table . AllocAutoIncrementValue (ctx , e . Table , e .ctx )
505
505
if e .filterErr (err ) != nil {
506
506
return types.Datum {}, err
507
507
}
0 commit comments