Skip to content

Commit

Permalink
executor: make the inserting errors more easier to understand (pingca…
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomxi committed Jul 19, 2021
1 parent 014005a commit ebf4384
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 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
12 changes: 12 additions & 0 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
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

0 comments on commit ebf4384

Please sign in to comment.