Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix runtime error when use on uplicate key update #29207

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion executor/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (e *InsertExec) initEvalBuffer4Dup() {
evalBufferTypes = append(evalBufferTypes, &col.FieldType)
}
if extraLen > 0 {
evalBufferTypes = append(evalBufferTypes, e.SelectExec.base().retFieldTypes[numWritableCols:]...)
evalBufferTypes = append(evalBufferTypes, e.SelectExec.base().retFieldTypes[0:]...)
Copy link
Collaborator

@guo-shaoge guo-shaoge Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 0 is not reasonable here. IMHO, we should use e.rowLen
  2. We also have some problem in line 371, you can reproduce by using the following case. The second insertStmt doesn't work.
drop table if exists t1;
drop table if exists t2;
create table t1(c1 int, c2 int, c3 varchar(100), unique key(c3));
create table t2(c1 int);
insert into t2 values(1);
insert into t1(c3) select "abc" from t2 on duplicate key update t1.c3 = t2.c1;
insert into t1(c3) select "abc" from t2 on duplicate key update t1.c3 = t2.c1;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're right, but it shouldn't be e.rowlen either.
I will think about how to solve this problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me, but do we have any update yet?

}
for _, col := range e.Table.Cols() {
evalBufferTypes = append(evalBufferTypes, &col.FieldType)
Expand Down
3 changes: 3 additions & 0 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func (s *testSuite8) TestInsertOnDuplicateKey(c *C) {
tk.MustExec("insert into a select x from b ON DUPLICATE KEY UPDATE a.x=b.y")
c.Assert(tk.Se.AffectedRows(), Equals, uint64(2))
tk.MustQuery("select * from a").Check(testkit.Rows("2"))
tk.MustExec("insert into a select 2 from b ON DUPLICATE KEY UPDATE a.x=b.y")
c.Assert(tk.Se.AffectedRows(), Equals, uint64(0))
tk.MustQuery("select * from a").Check(testkit.Rows("2"))

// reproduce insert on duplicate key update bug under new row format.
tk.MustExec(`drop table if exists t1`)
Expand Down