diff --git a/lightning/backend/tidb.go b/lightning/backend/tidb.go index 6c1e0793d..294ee333c 100644 --- a/lightning/backend/tidb.go +++ b/lightning/backend/tidb.go @@ -263,7 +263,10 @@ func (enc *tidbEncoder) Encode(logger log.Logger, row []types.Datum, _ int64, co enc.columnCnt = columnCount } - if len(row) != enc.columnCnt { + // TODO: since the column count doesn't exactly reflect the real column names, we only check the upper bound currently. + // See: tests/generated_columns/data/gencol.various_types.0.sql this sql has no columns, so encodeLoop will fill the + // column permutation with default, thus enc.columnCnt > len(row). + if len(row) > enc.columnCnt { log.L().Error("column count mismatch", zap.Ints("column_permutation", columnPermutation), zap.Array("data", rowArrayMarshaler(row))) return nil, errors.Errorf("column count mismatch, expected %d, got %d", enc.columnCnt, len(row)) diff --git a/lightning/backend/tidb_test.go b/lightning/backend/tidb_test.go index 48ce6a51c..f81345a98 100644 --- a/lightning/backend/tidb_test.go +++ b/lightning/backend/tidb_test.go @@ -136,7 +136,7 @@ func (s *mysqlSuite) TestWriteRowsIgnoreOnDup(c *C) { c.Assert(err, IsNil) row, err := encoder.Encode(logger, []types.Datum{ types.NewIntDatum(1), - }, 1, []int{0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}) + }, 1, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1}) c.Assert(err, IsNil) row.ClassifyAndAppend(&dataRows, &dataChecksum, &indexRows, &indexChecksum) @@ -174,7 +174,7 @@ func (s *mysqlSuite) TestWriteRowsErrorOnDup(c *C) { c.Assert(err, IsNil) row, err := encoder.Encode(logger, []types.Datum{ types.NewIntDatum(1), - }, 1, []int{0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}) + }, 1, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1}) c.Assert(err, IsNil) row.ClassifyAndAppend(&dataRows, &dataChecksum, &indexRows, &indexChecksum)