Skip to content

Commit

Permalink
executor: make the inserting error messages more easier to understand (
Browse files Browse the repository at this point in the history
…pingcap#24044) and a few changes hinted by lint
  • Loading branch information
zoomxi committed Jul 13, 2021
1 parent 9abf9d0 commit b65ed00
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
7 changes: 4 additions & 3 deletions executor/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,13 @@ func (e *InsertExec) doDupRowUpdate(ctx context.Context, handle kv.Handle, oldRo
// Update old row when the key is duplicated.
e.evalBuffer4Dup.SetDatums(e.row4Update...)
for _, col := range cols {
val, err1 := col.Expr.Eval(e.evalBuffer4Dup.ToRow())
if err1 != nil {
row := e.evalBuffer4Dup.ToRow()
val, err1 := col.Expr.Eval(row)
if err1 = e.handleErr(e.Table.WritableCols()[col.Col.Index], &val, row.Idx(), err1); err1 != nil {
return err1
}
e.row4Update[col.Col.Index], err1 = table.CastValue(e.ctx, val, col.Col.ToInfo(), false, false)
if err1 != nil {
if err1 = e.handleErr(e.Table.WritableCols()[col.Col.Index], &val, row.Idx(), err1); err1 != nil {
return err1
}
e.evalBuffer4Dup.SetDatum(col.Col.Index, e.row4Update[col.Col.Index])
Expand Down
16 changes: 14 additions & 2 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ func (s *testSuite3) TestInsertFloatOverflow(c *C) {
tk.MustExec("drop table if exists t,t1")
}

// There is a potential issue in MySQL: when the value of auto_increment_offset is greater
// TestAutoIDIncrementAndOffset There is a potential issue in MySQL: when the value of auto_increment_offset is greater
// than that of auto_increment_increment, the value of auto_increment_offset is ignored
// (https://dev.mysql.com/doc/refman/8.0/en/replication-options-master.html#sysvar_auto_increment_increment),
// This issue is a flaw of the implementation of MySQL and it doesn't exist in TiDB.
Expand Down Expand Up @@ -1537,6 +1537,18 @@ func (s *testSerialSuite) TestIssue20768(c *C) {
tk.MustQuery("select /*+ merge_join(t1) */ * from t1 join t2 on t1.a = t2.a").Check(testkit.Rows("0 0"))
}

func (s *testSerialSuite) TestIssue24044(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("CREATE TABLE `t1` (`id` int NOT NULL, `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPACT;")
tk.MustExec("insert into t1 values(1,\"a\")")
tk.MustExec("insert into t1 values(2,\"b\")")

err := tk.ExecToErr("insert into t1 select * from t1 on duplicate key update id = \"\"")
c.Assert(err.Error(), Equals, "[table:1366]Incorrect int value: '' for column 'id' at row 1")
}

func (s *testSuite9) TestIssue10402(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down Expand Up @@ -1571,7 +1583,7 @@ func combination(items []string) func() []string {
}
}

// See https://github.com/pingcap/tidb/issues/24582
// TestDuplicatedEntryErr https://github.com/pingcap/tidb/issues/24582
func (s *testSuite10) TestDuplicatedEntryErr(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
10 changes: 5 additions & 5 deletions executor/stale_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *testStaleTxnSerialSuite) TestSelectAsOf(c *C) {
sql string
expectPhysicalTS int64
preSec int64
// IsStaleness is auto cleanup in select stmt.
// errorStr is auto cleanup in select stmt.
errorStr string
}{
{
Expand Down Expand Up @@ -1020,7 +1020,7 @@ func (s *testStaleTxnSuite) TestStmtCtxStaleFlag(c *C) {
},
// assert select statement
{
sql: fmt.Sprintf("select * from t"),
sql: "select * from t",
hasStaleFlag: false,
},
// assert select statement in stale transaction
Expand All @@ -1029,7 +1029,7 @@ func (s *testStaleTxnSuite) TestStmtCtxStaleFlag(c *C) {
hasStaleFlag: false,
},
{
sql: fmt.Sprintf("select * from t"),
sql: "select * from t",
hasStaleFlag: true,
},
{
Expand All @@ -1042,12 +1042,12 @@ func (s *testStaleTxnSuite) TestStmtCtxStaleFlag(c *C) {
hasStaleFlag: false,
},
{
sql: fmt.Sprintf("select * from t"),
sql: "select * from t",
hasStaleFlag: true,
},
// assert select statement after consumed set transaction
{
sql: fmt.Sprintf("select * from t"),
sql: "select * from t",
hasStaleFlag: false,
},
// assert prepare statement with select as of statement
Expand Down
1 change: 1 addition & 0 deletions store/copr/coprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (s *testCoprocessorSuite) TestSplitRegionRanges(c *C) {
// nil --- 'g' --- 'n' --- 't' --- nil
// <- 0 -> <- 1 -> <- 2 -> <- 3 ->
_, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
c.Assert(err, IsNil)
testutils.BootstrapWithMultiRegions(cluster, []byte("g"), []byte("n"), []byte("t"))
pdCli := &tikv.CodecPDClient{Client: pdClient}
cache := NewRegionCache(tikv.NewRegionCache(pdCli))
Expand Down
3 changes: 1 addition & 2 deletions util/memory/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
type Tracker struct {
mu struct {
sync.Mutex
// The children memory trackers. If the Tracker is the Global Tracker, like executor.GlobalDiskUsageTracker,
// children memory trackers. If the Tracker is the Global Tracker, like executor.GlobalDiskUsageTracker,
// we wouldn't maintain its children in order to avoiding mutex contention.
children map[int][]*Tracker
}
Expand Down Expand Up @@ -95,7 +95,6 @@ func InitTracker(t *Tracker, label int, bytesLimit int64, action ActionOnExceed)
t.bytesSoftLimit = int64(float64(bytesLimit) * softScale)
t.maxConsumed = 0
t.isGlobal = false
return
}

// NewTracker creates a memory tracker.
Expand Down

0 comments on commit b65ed00

Please sign in to comment.