Skip to content

Commit

Permalink
Fix bug: get params index error when retry prepare insert stmt (#17904)
Browse files Browse the repository at this point in the history
Fix bug: get params index error when retry prepare insert stmt

Approved by: @daviszhen, @heni02
  • Loading branch information
ouyuanning authored Aug 6, 2024
1 parent 6c3e439 commit f3491fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,7 @@ func buildPlan(reqCtx context.Context, ses FeSession, ctx plan2.CompilerContext,
}
}
if ret != nil {
ret.IsPrepare = isPrepareStmt
if ses != nil && ses.GetTenantInfo() != nil && !ses.IsBackgroundSession() {
err = authenticateCanExecuteStatementAndPlan(reqCtx, ses.(*Session), stmt, ret)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions test/distributed/cases/pessimistic_transaction/prepare.result
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ CREATE TABLE `t_mes_product_bom` (
INSERT INTO `t_mes_product_bom` VALUES (?);
invalid input: only prepare statement can use ? expr
DROP TABLE IF EXISTS `t_mes_product_bom`;
drop table if exists t1;
create table t1 (a int primary key, b int);
begin;
alter table t1 alter column b drop default;
use prepare;
prepare s1 from insert into t1 values (?, 2);
set @a=1;
execute s1 using @a;
select * from t1;
a b
1 2
commit;
16 changes: 15 additions & 1 deletion test/distributed/cases/pessimistic_transaction/prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ CREATE TABLE `t_mes_product_bom` (
`a_id` int(10)
);
INSERT INTO `t_mes_product_bom` VALUES (?);
DROP TABLE IF EXISTS `t_mes_product_bom`;
DROP TABLE IF EXISTS `t_mes_product_bom`;

drop table if exists t1;
create table t1 (a int primary key, b int);
begin;
alter table t1 alter column b drop default;
-- @session:id=1{
use prepare;
prepare s1 from insert into t1 values (?, 2);
set @a=1;
-- @wait:0:commit
execute s1 using @a;
select * from t1;
-- @session}
commit;

0 comments on commit f3491fe

Please sign in to comment.