executor,server: fix pessimistic "insert select for update" return malformed packet (#20584)
Signed-off-by: lysu <sulifx@gmail.com>
This commit is contained in:
@ -763,7 +763,7 @@ func (a *ExecStmt) buildExecutor() (Executor, error) {
|
||||
}
|
||||
e = executorExec.stmtExec
|
||||
}
|
||||
a.isSelectForUpdate = b.hasLock && (!stmtCtx.InDeleteStmt && !stmtCtx.InUpdateStmt)
|
||||
a.isSelectForUpdate = b.hasLock && (!stmtCtx.InDeleteStmt && !stmtCtx.InUpdateStmt && !stmtCtx.InInsertStmt)
|
||||
return e, nil
|
||||
}
|
||||
|
||||
|
||||
@ -931,3 +931,24 @@ func (ts *tidbTestSuite) TestNullFlag(c *C) {
|
||||
expectFlag := uint16(tmysql.NotNullFlag | tmysql.BinaryFlag)
|
||||
c.Assert(dumpFlag(cols[0].Type, cols[0].Flag), Equals, expectFlag)
|
||||
}
|
||||
|
||||
func (ts *tidbTestSuite) TestPessimisticInsertSelectForUpdate(c *C) {
|
||||
qctx, err := ts.tidbdrv.OpenCtx(uint64(0), 0, uint8(tmysql.DefaultCollationID), "test", nil)
|
||||
c.Assert(err, IsNil)
|
||||
ctx := context.Background()
|
||||
_, err = Execute(ctx, qctx, "use test;")
|
||||
c.Assert(err, IsNil)
|
||||
_, err = Execute(ctx, qctx, "drop table if exists t1, t2")
|
||||
c.Assert(err, IsNil)
|
||||
_, err = Execute(ctx, qctx, "create table t1 (id int)")
|
||||
c.Assert(err, IsNil)
|
||||
_, err = Execute(ctx, qctx, "create table t2 (id int)")
|
||||
c.Assert(err, IsNil)
|
||||
_, err = Execute(ctx, qctx, "insert into t1 select 1")
|
||||
c.Assert(err, IsNil)
|
||||
_, err = Execute(ctx, qctx, "begin pessimistic")
|
||||
c.Assert(err, IsNil)
|
||||
rs, err := Execute(ctx, qctx, "INSERT INTO t2 (id) select id from t1 where id = 1 for update")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(rs, IsNil) // should be no delay
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user