diff --git a/executor/executor_test.go b/executor/executor_test.go index 2d784d2626e13..16e40483a55fb 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -3561,36 +3561,36 @@ func TestPointGetPreparedPlan(t *testing.T) { ctx := context.Background() // first time plan generated - rs, err := tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(0)}) + rs, err := tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) // using the generated plan but with different params - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(0)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3")) @@ -3599,98 +3599,98 @@ func TestPointGetPreparedPlan(t *testing.T) { require.NoError(t, err) tk.Session().GetSessionVars().PreparedStmts[psuk1Id].(*plannercore.CachedPrepareStmt).PreparedAst.UseCache = false - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(0)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) // test schema changed, cached plan should be invalidated tk.MustExec("alter table t add column col4 int default 10 after c") - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(0)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3 10")) tk.MustExec("alter table t drop index k_b") - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(0)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) tk.MustExec(`insert into t values(4, 3, 3, 11)`) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3 10", "4 3 3 11")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(0)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) tk.MustExec("delete from t where a = 4") tk.MustExec("alter table t add index k_b(b)") - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, []types.Datum{types.NewDatum(0)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, psuk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) // use pk again - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk2Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3 3 3 10")) } @@ -3719,12 +3719,12 @@ func TestPointGetPreparedPlanWithCommitMode(t *testing.T) { ctx := context.Background() // first time plan generated - rs, err := tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(0)}) + rs, err := tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(nil) // using the generated plan but with different params - rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1")) @@ -3732,7 +3732,7 @@ func TestPointGetPreparedPlanWithCommitMode(t *testing.T) { tk1.MustExec("set autocommit = 0") tk1.MustExec("begin") // try to exec using point get plan(this plan should not go short path) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1")) @@ -3742,7 +3742,7 @@ func TestPointGetPreparedPlanWithCommitMode(t *testing.T) { tk2.MustExec("update t set c = c + 10 where c = 1") // try to point get again - rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 1")) @@ -3752,11 +3752,11 @@ func TestPointGetPreparedPlanWithCommitMode(t *testing.T) { require.True(t, kv.ErrWriteConflict.Equal(err), fmt.Sprintf("error: %s", err)) // verify - rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(1)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1 11")) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(2)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(2)) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("2 2 2")) @@ -3790,29 +3790,29 @@ func TestPointUpdatePreparedPlan(t *testing.T) { ctx := context.Background() // first time plan generated - rs, err := tk.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err := tk.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 4")) // using the generated plan but with different params - rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 5")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 6")) // updateID2 - rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID2, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID2, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 8")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID2, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID2, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 10")) @@ -3821,46 +3821,46 @@ func TestPointUpdatePreparedPlan(t *testing.T) { updUkID1, _, _, err := tk.Session().PrepareStmt(`update t set c = c + 10 where b = ?`) require.NoError(t, err) tk.Session().GetSessionVars().PreparedStmts[updUkID1].(*plannercore.CachedPrepareStmt).PreparedAst.UseCache = false - rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 20")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 30")) // test schema changed, cached plan should be invalidated tk.MustExec("alter table t add column col4 int default 10 after c") - rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 31 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 32 10")) tk.MustExec("alter table t drop index k_b") - rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 42 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 52 10")) tk.MustExec("alter table t add unique index k_b(b)") - rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 62 10")) - rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, updUkID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 72 10")) @@ -3893,12 +3893,12 @@ func TestPointUpdatePreparedPlanWithCommitMode(t *testing.T) { require.NoError(t, err) // first time plan generated - rs, err := tk1.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err := tk1.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk1.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 4")) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk1.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 5")) @@ -3907,7 +3907,7 @@ func TestPointUpdatePreparedPlanWithCommitMode(t *testing.T) { tk1.MustExec("set autocommit = 0") tk1.MustExec("begin") // try to exec using point get plan(this plan should not go short path) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk1.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 6")) @@ -3938,12 +3938,12 @@ func TestPointUpdatePreparedPlanWithCommitMode(t *testing.T) { // again next start a non autocommit txn tk1.MustExec("set autocommit = 0") tk1.MustExec("begin") - rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk1.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 10")) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, []types.Datum{types.NewDatum(3)}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, updateID1, expression.Args2Expressions4Test(3)) require.Nil(t, rs) require.NoError(t, err) tk1.MustQuery("select * from t where a = 3").Check(testkit.Rows("3 3 11")) diff --git a/executor/seqtest/prepared_test.go b/executor/seqtest/prepared_test.go index db25f96cdf5a0..572c23fae43d4 100644 --- a/executor/seqtest/prepared_test.go +++ b/executor/seqtest/prepared_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/pingcap/tidb/executor" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/parser/ast" @@ -31,7 +32,6 @@ import ( "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/session/txninfo" "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/kvcache" dto "github.com/prometheus/client_model/go" @@ -100,7 +100,7 @@ func TestPrepared(t *testing.T) { query := "select c1, c2 from prepare_test where c1 = ?" stmtID, _, _, err := tk.Session().PrepareStmt(query) require.NoError(t, err) - rs, err := tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + rs, err := tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 ")) @@ -118,7 +118,7 @@ func TestPrepared(t *testing.T) { tk1.MustExec("use test") tk1.MustExec("insert prepare_test (c1) values (3)") - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3")) @@ -126,11 +126,11 @@ func TestPrepared(t *testing.T) { query = "select c1 from prepare_test where c1 = (select c1 from prepare_test where c1 = ?)" stmtID, _, _, err = tk.Session().PrepareStmt(query) require.NoError(t, err) - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(3)) require.NoError(t, err) require.NoError(t, rs.Close()) tk1.MustExec("insert prepare_test (c1) values (3)") - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3")) @@ -138,11 +138,11 @@ func TestPrepared(t *testing.T) { query = "select c1 from prepare_test where c1 in (select c1 from prepare_test where c1 = ?)" stmtID, _, _, err = tk.Session().PrepareStmt(query) require.NoError(t, err) - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(3)) require.NoError(t, err) require.NoError(t, rs.Close()) tk1.MustExec("insert prepare_test (c1) values (3)") - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(3)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(3)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("3")) @@ -152,11 +152,11 @@ func TestPrepared(t *testing.T) { stmtID, _, _, err = tk.Session().PrepareStmt(query) require.NoError(t, err) tk.MustExec("rollback") - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(4)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(4)) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows()) - execStmt := &ast.ExecuteStmt{ExecID: stmtID, BinaryArgs: []types.Datum{types.NewDatum(1)}} + execStmt := &ast.ExecuteStmt{ExecID: stmtID, BinaryArgs: expression.Args2Expressions4Test(1)} // Check that ast.Statement created by executor.CompileExecutePreparedStmt has query text. stmt, err := executor.CompileExecutePreparedStmt(context.TODO(), tk.Session(), execStmt, tk.Session().GetInfoSchema().(infoschema.InfoSchema)) @@ -181,7 +181,7 @@ func TestPrepared(t *testing.T) { require.NoError(t, err) // Should success as the changed schema do not affect the prepared statement. - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.NoError(t, err) if rs != nil { require.NoError(t, rs.Close()) @@ -193,11 +193,11 @@ func TestPrepared(t *testing.T) { require.NoError(t, err) tk.MustExec("alter table prepare_test drop column c2") - _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.True(t, plannercore.ErrUnknownColumn.Equal(err)) tk.MustExec("drop table prepare_test") - _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.True(t, plannercore.ErrSchemaChanged.Equal(err)) // issue 3381 @@ -282,11 +282,11 @@ func TestPrepared(t *testing.T) { // issue 8065 stmtID, _, _, err = tk.Session().PrepareStmt("select ? from dual") require.NoError(t, err) - _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.NoError(t, err) stmtID, _, _, err = tk.Session().PrepareStmt("update prepare1 set a = ? where a = ?") require.NoError(t, err) - _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1), types.NewDatum(1)}) + _, err = tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1, 1)) require.NoError(t, err) } } @@ -327,7 +327,7 @@ func TestPreparedLimitOffset(t *testing.T) { stmtID, _, _, err := tk.Session().PrepareStmt("select id from prepare_test limit ?") require.NoError(t, err) - rs, err := tk.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + rs, err := tk.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.NoError(t, err) rs.Close() } @@ -910,7 +910,7 @@ func TestPreparedIssue17419(t *testing.T) { tk1.Session().SetSessionManager(sm) dom.ExpensiveQueryHandle().SetSessionManager(sm) - rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.NoError(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1", "2", "3")) tk1.Session().SetProcessInfo("", time.Now(), mysql.ComStmtExecute, 0) diff --git a/expression/expression.go b/expression/expression.go index 52a94c6056ec4..81d071287ad2a 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -1434,3 +1434,31 @@ func PropagateType(evalType types.EvalType, args ...Expression) { } } } + +// Args2Expressions4Test converts these values to an expression list. +// This conversion is incomplete, so only use for test. +func Args2Expressions4Test(args ...interface{}) []Expression { + exprs := make([]Expression, len(args)) + for i, v := range args { + d := types.NewDatum(v) + var ft *types.FieldType + switch d.Kind() { + case types.KindNull: + ft = types.NewFieldType(mysql.TypeNull) + case types.KindInt64: + ft = types.NewFieldType(mysql.TypeLong) + case types.KindUint64: + ft = types.NewFieldType(mysql.TypeLong) + ft.AddFlag(mysql.UnsignedFlag) + case types.KindFloat64: + ft = types.NewFieldType(mysql.TypeDouble) + case types.KindString: + ft = types.NewFieldType(mysql.TypeVarString) + default: + exprs[i] = nil + continue + } + exprs[i] = &Constant{Value: d, RetType: ft} + } + return exprs +} diff --git a/planner/core/plan_cache.go b/planner/core/plan_cache.go index 076a86a575cc8..c562be0218063 100644 --- a/planner/core/plan_cache.go +++ b/planner/core/plan_cache.go @@ -103,6 +103,12 @@ func parseParamTypes(sctx sessionctx.Context, isBinProtocol bool, binProtoVars [ } else { // txt protocol varsNum = len(txtProtoVars) for _, param := range txtProtoVars { + if c, ok := param.(*expression.Constant); ok { // from binary protocol + txtVarTypes = append(txtVarTypes, c.GetType()) + continue + } + + // from text protocol, there must be a GetVar function name := param.(*expression.ScalarFunction).GetArgs()[0].String() tp := sctx.GetSessionVars().UserVarTypes[name] if tp == nil { diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index fb6eb9475b033..4ca575b4b6a7f 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -801,7 +801,7 @@ func (b *PlanBuilder) buildExecute(ctx context.Context, v *ast.ExecuteStmt) (Pla } exe := &Execute{Name: v.Name, TxtProtoVars: vars, ExecID: v.ExecID} if v.BinaryArgs != nil { - exe.BinProtoVars = v.BinaryArgs.([]types.Datum) + exe.TxtProtoVars = v.BinaryArgs.([]expression.Expression) } return exe, nil } diff --git a/planner/core/prepare_test.go b/planner/core/prepare_test.go index bae9b4d491a5d..dc95884aa6870 100644 --- a/planner/core/prepare_test.go +++ b/planner/core/prepare_test.go @@ -25,6 +25,7 @@ import ( "time" "github.com/pingcap/tidb/executor" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" @@ -35,7 +36,6 @@ import ( "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/hint" "github.com/pingcap/tidb/util/kvcache" "github.com/prometheus/client_golang/prometheus" @@ -71,11 +71,11 @@ func TestPointGetPreparedPlan4PlanCache(t *testing.T) { ctx := context.Background() // first time plan generated - _, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(0)}) + _, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(0)) require.NoError(t, err) // using the generated plan but with different params - _, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, []types.Datum{types.NewDatum(nil)}) + _, err = tk1.Session().ExecutePreparedStmt(ctx, pspk1Id, expression.Args2Expressions4Test(nil)) require.NoError(t, err) } @@ -2851,7 +2851,7 @@ func TestPlanCacheWithRCWhenInfoSchemaChange(t *testing.T) { tk2.MustExec("set tx_isolation='READ-COMMITTED'") tk2.MustExec("begin pessimistic") tk1.MustQuery("execute s").Check(testkit.Rows()) - rs, err := tk2.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err := tk2.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk2.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows()) @@ -2865,7 +2865,7 @@ func TestPlanCacheWithRCWhenInfoSchemaChange(t *testing.T) { tk1.MustQuery("execute s").Check(testkit.Rows("1 0")) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) // execute binary protocol - rs, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk2.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 0")) tk2.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) @@ -2895,7 +2895,7 @@ func TestConsistencyBetweenPrepareExecuteAndNormalSql(t *testing.T) { // Execute using sql tk1.MustQuery("execute s").Check(testkit.Rows("1 1", "2 2")) // Execute using binary - rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1", "2 2")) // Normal sql @@ -2907,7 +2907,7 @@ func TestConsistencyBetweenPrepareExecuteAndNormalSql(t *testing.T) { // Execute using sql tk1.MustQuery("execute s").Check(testkit.Rows("1 1", "2 2", "3 ")) // Execute using binary - rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1", "2 2", "3 ")) // Normal sql @@ -2925,7 +2925,7 @@ func verifyCache(ctx context.Context, t *testing.T, tk1 *testkit.TestKit, tk2 *t tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) // This time, the cache will be hit. - rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.NoError(t, err) require.NoError(t, rs.Close()) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) @@ -2937,7 +2937,7 @@ func verifyCache(ctx context.Context, t *testing.T, tk1 *testkit.TestKit, tk2 *t tk1.MustExec("execute s") tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) // Now the plan cache will be valid - rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.NoError(t, err) require.NoError(t, rs.Close()) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) @@ -3024,12 +3024,12 @@ func TestPointGetForUpdateAutoCommitCache(t *testing.T) { tk1.MustExec("prepare s from 'select * from t1 where id = 1 for update'") stmtID, _, _, err := tk1.Session().PrepareStmt("select * from t1 where id = 1 for update") require.Nil(t, err) - rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err := tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) @@ -3037,12 +3037,12 @@ func TestPointGetForUpdateAutoCommitCache(t *testing.T) { tk2.MustExec("alter table t1 drop column c") tk2.MustExec("update t1 set id = 10 where id = 1") - rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows()) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{}) + rs, err = tk1.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test()) require.Nil(t, err) tk1.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows()) tk1.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) diff --git a/server/conn_stmt.go b/server/conn_stmt.go index 375efd1532030..e1b7ff416b2c3 100644 --- a/server/conn_stmt.go +++ b/server/conn_stmt.go @@ -45,6 +45,7 @@ import ( "time" "github.com/pingcap/errors" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/mysql" @@ -163,7 +164,7 @@ func (cc *clientConn) handleStmtExecute(ctx context.Context, data []byte) (err e ) cc.initInputEncoder(ctx) numParams := stmt.NumParams() - args := make([]types.Datum, numParams) + args := make([]expression.Expression, numParams) if numParams > 0 { nullBitmapLen := (numParams + 7) >> 3 if len(data) < (pos + nullBitmapLen + 1) { @@ -229,7 +230,7 @@ func (cc *clientConn) handleStmtExecute(ctx context.Context, data []byte) (err e // The first return value indicates whether the call of executePreparedStmtAndWriteResult has no side effect and can be retried. // Currently the first return value is used to fallback to TiKV when TiFlash is down. -func (cc *clientConn) executePreparedStmtAndWriteResult(ctx context.Context, stmt PreparedStatement, args []types.Datum, useCursor bool) (bool, error) { +func (cc *clientConn) executePreparedStmtAndWriteResult(ctx context.Context, stmt PreparedStatement, args []expression.Expression, useCursor bool) (bool, error) { rs, err := stmt.Execute(ctx, args) if err != nil { return true, errors.Annotate(err, cc.preparedStmt2String(uint32(stmt.ID()))) @@ -318,7 +319,7 @@ func parseStmtFetchCmd(data []byte) (uint32, uint32, error) { return stmtID, fetchSize, nil } -func parseExecArgs(sc *stmtctx.StatementContext, args []types.Datum, boundParams [][]byte, +func parseExecArgs(sc *stmtctx.StatementContext, params []expression.Expression, boundParams [][]byte, nullBitmap, paramTypes, paramValues []byte, enc *inputDecoder) (err error) { pos := 0 var ( @@ -331,6 +332,7 @@ func parseExecArgs(sc *stmtctx.StatementContext, args []types.Datum, boundParams enc = newInputDecoder(charset.CharsetUTF8) } + args := make([]types.Datum, len(params)) for i := 0; i < len(args); i++ { // if params had received via ComStmtSendLongData, use them directly. // ref https://dev.mysql.com/doc/internals/en/com-stmt-send-long-data.html @@ -567,6 +569,12 @@ func parseExecArgs(sc *stmtctx.StatementContext, args []types.Datum, boundParams return } } + + for i := range params { + ft := new(types.FieldType) + types.DefaultParamTypeForValue(args[i].GetValue(), ft) + params[i] = &expression.Constant{Value: args[i], RetType: ft} + } return } diff --git a/server/conn_stmt_test.go b/server/conn_stmt_test.go index a4ff4c2ee7070..1b8ea55e61c35 100644 --- a/server/conn_stmt_test.go +++ b/server/conn_stmt_test.go @@ -17,6 +17,7 @@ package server import ( "testing" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/sessionctx/stmtctx" @@ -26,7 +27,7 @@ import ( func TestParseExecArgs(t *testing.T) { type args struct { - args []types.Datum + args []expression.Expression boundParams [][]byte nullBitmap []byte paramTypes []byte @@ -40,7 +41,7 @@ func TestParseExecArgs(t *testing.T) { // Tests for int overflow { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{1, 0}, @@ -51,7 +52,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{2, 0}, @@ -62,7 +63,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{3, 0}, @@ -74,7 +75,7 @@ func TestParseExecArgs(t *testing.T) { // Tests for date/datetime/timestamp { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{12, 0}, @@ -85,7 +86,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{10, 0}, @@ -96,7 +97,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{7, 0}, @@ -107,7 +108,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{7, 0}, @@ -118,7 +119,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{7, 0}, @@ -130,7 +131,7 @@ func TestParseExecArgs(t *testing.T) { // Tests for time { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{11, 0}, @@ -141,7 +142,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{11, 0}, @@ -152,7 +153,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{11, 0}, @@ -164,7 +165,7 @@ func TestParseExecArgs(t *testing.T) { // For error test { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{7, 0}, @@ -175,7 +176,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{11, 0}, @@ -186,7 +187,7 @@ func TestParseExecArgs(t *testing.T) { }, { args{ - make([]types.Datum, 1), + expression.Args2Expressions4Test(1), [][]byte{nil}, []byte{0x0}, []byte{11, 0}, @@ -199,12 +200,14 @@ func TestParseExecArgs(t *testing.T) { for _, tt := range tests { err := parseExecArgs(&stmtctx.StatementContext{}, tt.args.args, tt.args.boundParams, tt.args.nullBitmap, tt.args.paramTypes, tt.args.paramValues, nil) require.Truef(t, terror.ErrorEqual(err, tt.err), "err %v", err) - require.Equal(t, tt.expect, tt.args.args[0].GetValue()) + if err == nil { + require.Equal(t, tt.expect, tt.args.args[0].(*expression.Constant).Value.GetValue()) + } } } func TestParseExecArgsAndEncode(t *testing.T) { - dt := make([]types.Datum, 1) + dt := expression.Args2Expressions4Test(1) err := parseExecArgs(&stmtctx.StatementContext{}, dt, [][]byte{nil}, @@ -213,7 +216,7 @@ func TestParseExecArgsAndEncode(t *testing.T) { []byte{4, 178, 226, 202, 212}, newInputDecoder("gbk")) require.NoError(t, err) - require.Equal(t, "测试", dt[0].GetValue()) + require.Equal(t, "测试", dt[0].(*expression.Constant).Value.GetValue()) err = parseExecArgs(&stmtctx.StatementContext{}, dt, @@ -223,7 +226,7 @@ func TestParseExecArgsAndEncode(t *testing.T) { []byte{}, newInputDecoder("gbk")) require.NoError(t, err) - require.Equal(t, "测试", dt[0].GetString()) + require.Equal(t, "测试", dt[0].(*expression.Constant).Value.GetString()) } func TestParseStmtFetchCmd(t *testing.T) { diff --git a/server/driver.go b/server/driver.go index ae996715113ae..a805e531f056a 100644 --- a/server/driver.go +++ b/server/driver.go @@ -18,7 +18,7 @@ import ( "context" "crypto/tls" - "github.com/pingcap/tidb/types" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/util/chunk" ) @@ -34,7 +34,7 @@ type PreparedStatement interface { ID() int // Execute executes the statement. - Execute(context.Context, []types.Datum) (ResultSet, error) + Execute(context.Context, []expression.Expression) (ResultSet, error) // AppendParam appends parameter to the statement. AppendParam(paramID int, data []byte) error diff --git a/server/driver_tidb.go b/server/driver_tidb.go index 13f568e089239..17b6553c69c73 100644 --- a/server/driver_tidb.go +++ b/server/driver_tidb.go @@ -22,6 +22,7 @@ import ( "sync/atomic" "github.com/pingcap/errors" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/charset" @@ -74,7 +75,7 @@ func (ts *TiDBStatement) ID() int { } // Execute implements PreparedStatement Execute method. -func (ts *TiDBStatement) Execute(ctx context.Context, args []types.Datum) (rs ResultSet, err error) { +func (ts *TiDBStatement) Execute(ctx context.Context, args []expression.Expression) (rs ResultSet, err error) { tidbRecordset, err := ts.ctx.ExecutePreparedStmt(ctx, ts.id, args) if err != nil { return nil, err diff --git a/session/bench_test.go b/session/bench_test.go index 44178871a124e..78b58948a0f64 100644 --- a/session/bench_test.go +++ b/session/bench_test.go @@ -27,6 +27,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/executor" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" @@ -326,7 +327,7 @@ func BenchmarkPreparedPointGet(b *testing.B) { alloc := chunk.NewAllocator() b.ResetTimer() for i := 0; i < b.N; i++ { - rs, err := se.ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(64)}) + rs, err := se.ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(64)) if err != nil { b.Fatal(err) } diff --git a/session/main_test.go b/session/main_test.go index 06db872864bb4..a54a3378a4d8a 100644 --- a/session/main_test.go +++ b/session/main_test.go @@ -23,6 +23,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/testkit/testdata" @@ -116,10 +117,7 @@ func exec(se Session, sql string, args ...interface{}) (sqlexec.RecordSet, error if err != nil { return nil, err } - params := make([]types.Datum, len(args)) - for i := 0; i < len(params); i++ { - params[i] = types.NewDatum(args[i]) - } + params := expression.Args2Expressions4Test(args...) rs, err := se.ExecutePreparedStmt(ctx, stmtID, params) if err != nil { return nil, err diff --git a/session/session.go b/session/session.go index e186e455d62f5..d6c462e1f0bab 100644 --- a/session/session.go +++ b/session/session.go @@ -49,6 +49,7 @@ import ( "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/executor" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" @@ -83,7 +84,6 @@ import ( "github.com/pingcap/tidb/table/temptable" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/telemetry" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/collate" @@ -155,7 +155,7 @@ type Session interface { // PrepareStmt executes prepare statement in binary protocol. PrepareStmt(sql string) (stmtID uint32, paramCount int, fields []*ast.ResultField, err error) // ExecutePreparedStmt executes a prepared statement. - ExecutePreparedStmt(ctx context.Context, stmtID uint32, param []types.Datum) (sqlexec.RecordSet, error) + ExecutePreparedStmt(ctx context.Context, stmtID uint32, param []expression.Expression) (sqlexec.RecordSet, error) DropPreparedStmt(stmtID uint32) error // SetSessionStatesHandler sets SessionStatesHandler for type stateType. SetSessionStatesHandler(stateType sessionstates.SessionStateType, handler sessionctx.SessionStatesHandler) @@ -2300,7 +2300,7 @@ func (s *session) preparedStmtExec(ctx context.Context, execStmt *ast.ExecuteStm } // ExecutePreparedStmt executes a prepared statement. -func (s *session) ExecutePreparedStmt(ctx context.Context, stmtID uint32, args []types.Datum) (sqlexec.RecordSet, error) { +func (s *session) ExecutePreparedStmt(ctx context.Context, stmtID uint32, args []expression.Expression) (sqlexec.RecordSet, error) { var err error if err = s.PrepareTxnCtx(ctx); err != nil { return nil, err diff --git a/session/session_test/session_test.go b/session/session_test/session_test.go index 7105497341467..4d8307d49ab95 100644 --- a/session/session_test/session_test.go +++ b/session/session_test/session_test.go @@ -30,6 +30,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/errno" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/auth" @@ -2629,7 +2630,7 @@ func TestPrepare(t *testing.T) { require.Equal(t, uint32(1), id) require.Equal(t, 1, ps) tk.MustExec(`set @a=1`) - rs, err := tk.Session().ExecutePreparedStmt(ctx, id, []types.Datum{types.NewDatum("1")}) + rs, err := tk.Session().ExecutePreparedStmt(ctx, id, expression.Args2Expressions4Test("1")) require.NoError(t, err) require.NoError(t, rs.Close()) err = tk.Session().DropPreparedStmt(id) @@ -2651,10 +2652,10 @@ func TestPrepare(t *testing.T) { tk.MustExec("insert multiexec values (1, 1), (2, 2)") id, _, _, err = tk.Session().PrepareStmt("select a from multiexec where b = ? order by b") require.NoError(t, err) - rs, err = tk.Session().ExecutePreparedStmt(ctx, id, []types.Datum{types.NewDatum(1)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, id, expression.Args2Expressions4Test(1)) require.NoError(t, err) require.NoError(t, rs.Close()) - rs, err = tk.Session().ExecutePreparedStmt(ctx, id, []types.Datum{types.NewDatum(2)}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, id, expression.Args2Expressions4Test(2)) require.NoError(t, err) require.NoError(t, rs.Close()) } @@ -3393,8 +3394,7 @@ func TestQueryString(t *testing.T) { tk.MustExec("show create table t") id, _, _, err := tk.Session().PrepareStmt("CREATE TABLE t2(id bigint PRIMARY KEY, age int)") require.NoError(t, err) - var params []types.Datum - _, err = tk.Session().ExecutePreparedStmt(context.Background(), id, params) + _, err = tk.Session().ExecutePreparedStmt(context.Background(), id, expression.Args2Expressions4Test()) require.NoError(t, err) qs := tk.Session().Value(sessionctx.QueryString) require.Equal(t, "CREATE TABLE t2(id bigint PRIMARY KEY, age int)", qs.(string)) @@ -4038,12 +4038,12 @@ func TestBinaryReadOnly(t *testing.T) { require.NoError(t, err) tk.MustExec("set autocommit = 0") tk.MustExec("set tidb_disable_txn_auto_retry = 0") - _, err = tk.Session().ExecutePreparedStmt(context.Background(), id, []types.Datum{types.NewDatum(1)}) + _, err = tk.Session().ExecutePreparedStmt(context.Background(), id, expression.Args2Expressions4Test(1)) require.NoError(t, err) require.Equal(t, 0, session.GetHistory(tk.Session()).Count()) tk.MustExec("insert into t values (1)") require.Equal(t, 1, session.GetHistory(tk.Session()).Count()) - _, err = tk.Session().ExecutePreparedStmt(context.Background(), id2, []types.Datum{types.NewDatum(2)}) + _, err = tk.Session().ExecutePreparedStmt(context.Background(), id2, expression.Args2Expressions4Test(2)) require.NoError(t, err) require.Equal(t, 2, session.GetHistory(tk.Session()).Count()) tk.MustExec("commit") diff --git a/sessionctx/sessionstates/session_states_test.go b/sessionctx/sessionstates/session_states_test.go index 5d35e168ec925..aad78a39924c3 100644 --- a/sessionctx/sessionstates/session_states_test.go +++ b/sessionctx/sessionstates/session_states_test.go @@ -26,12 +26,12 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/errno" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/server" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/sem" "github.com/stretchr/testify/require" ) @@ -855,8 +855,7 @@ func TestPreparedStatements(t *testing.T) { return stmtID }, checkFunc: func(tk *testkit.TestKit, conn server.MockConn, param any) { - datum := []types.Datum{types.NewDatum(1)} - rs, err := tk.Session().ExecutePreparedStmt(context.Background(), param.(uint32), datum) + rs, err := tk.Session().ExecutePreparedStmt(context.Background(), param.(uint32), expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, "").Check(testkit.Rows("1")) }, @@ -878,8 +877,7 @@ func TestPreparedStatements(t *testing.T) { }, checkFunc: func(tk *testkit.TestKit, conn server.MockConn, param any) { tk.MustQuery("execute stmt").Check(testkit.Rows("10")) - datum := []types.Datum{types.NewDatum(1)} - rs, err := tk.Session().ExecutePreparedStmt(context.Background(), param.(uint32), datum) + rs, err := tk.Session().ExecutePreparedStmt(context.Background(), param.(uint32), expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.ResultSetToResult(rs, "").Check(testkit.Rows("1")) }, @@ -911,8 +909,7 @@ func TestPreparedStatements(t *testing.T) { rs, err := tk.Session().ExecutePreparedStmt(context.Background(), stmtIDs[1], nil) require.NoError(t, err) tk.ResultSetToResult(rs, "").Check(testkit.Rows()) - datum := []types.Datum{types.NewDatum(1), types.NewDatum(2), types.NewDatum(3)} - _, err = tk.Session().ExecutePreparedStmt(context.Background(), stmtIDs[0], datum) + _, err = tk.Session().ExecutePreparedStmt(context.Background(), stmtIDs[0], expression.Args2Expressions4Test(1, 2, 3)) require.NoError(t, err) rs, err = tk.Session().ExecutePreparedStmt(context.Background(), stmtIDs[1], nil) require.NoError(t, err) diff --git a/sessiontxn/isolation/readcommitted_test.go b/sessiontxn/isolation/readcommitted_test.go index 896a4ddbc134e..537672819a123 100644 --- a/sessiontxn/isolation/readcommitted_test.go +++ b/sessiontxn/isolation/readcommitted_test.go @@ -25,6 +25,7 @@ import ( "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/executor" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser" @@ -35,7 +36,6 @@ import ( "github.com/pingcap/tidb/sessiontxn/isolation" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/testkit/testfork" - "github.com/pingcap/tidb/types" "github.com/stretchr/testify/require" tikverr "github.com/tikv/client-go/v2/error" ) @@ -164,7 +164,7 @@ func TestPessimisticRCTxnContextProviderRCCheckForPrepareExecute(t *testing.T) { // first ts should use the txn startTS stmt, _, _, err := tk.Session().PrepareStmt("select * from t") require.NoError(t, err) - rs, err := tk.Session().ExecutePreparedStmt(ctx, stmt, []types.Datum{}) + rs, err := tk.Session().ExecutePreparedStmt(ctx, stmt, expression.Args2Expressions4Test()) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) require.NoError(t, err) ts, err := provider.GetStmtForUpdateTS() @@ -172,7 +172,7 @@ func TestPessimisticRCTxnContextProviderRCCheckForPrepareExecute(t *testing.T) { require.Equal(t, txnStartTS, ts) // second ts should reuse the txn startTS - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmt, []types.Datum{}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmt, expression.Args2Expressions4Test()) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 1")) require.NoError(t, err) ts, err = provider.GetStmtForUpdateTS() @@ -181,7 +181,7 @@ func TestPessimisticRCTxnContextProviderRCCheckForPrepareExecute(t *testing.T) { tk2.MustExec("update t set v = v + 10 where id = 1") compareTS := getOracleTS(t, se) - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmt, []types.Datum{}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmt, expression.Args2Expressions4Test()) require.NoError(t, err) _, err = session.ResultSetToStringSlice(ctx, tk.Session(), rs) require.Error(t, err) @@ -192,7 +192,7 @@ func TestPessimisticRCTxnContextProviderRCCheckForPrepareExecute(t *testing.T) { require.Greater(t, compareTS, ts) // retry tk.Session().GetSessionVars().RetryInfo.Retrying = true - rs, err = tk.Session().ExecutePreparedStmt(ctx, stmt, []types.Datum{}) + rs, err = tk.Session().ExecutePreparedStmt(ctx, stmt, expression.Args2Expressions4Test()) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 11")) ts, err = provider.GetStmtForUpdateTS() diff --git a/sessiontxn/txn_context_test.go b/sessiontxn/txn_context_test.go index 74245fadd16f1..022563b36c046 100644 --- a/sessiontxn/txn_context_test.go +++ b/sessiontxn/txn_context_test.go @@ -23,6 +23,7 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/domain" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/planner/core" @@ -31,7 +32,6 @@ import ( "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/testkit/testfork" "github.com/pingcap/tidb/testkit/testsetup" - "github.com/pingcap/tidb/types" "github.com/stretchr/testify/require" "go.uber.org/goleak" ) @@ -907,18 +907,18 @@ func TestTSOCmdCountForPrepareExecute(t *testing.T) { for i := 1; i < 100; i++ { tk.MustExec("begin pessimistic") - stmt, err := tk.Session().ExecutePreparedStmt(ctx, sqlSelectID, []types.Datum{types.NewDatum(1)}) + stmt, err := tk.Session().ExecutePreparedStmt(ctx, sqlSelectID, expression.Args2Expressions4Test(1)) require.NoError(t, err) require.NoError(t, stmt.Close()) - stmt, err = tk.Session().ExecutePreparedStmt(ctx, sqlUpdateID, []types.Datum{types.NewDatum(1)}) + stmt, err = tk.Session().ExecutePreparedStmt(ctx, sqlUpdateID, expression.Args2Expressions4Test(1)) require.NoError(t, err) require.Nil(t, stmt) val := i * 10 - stmt, err = tk.Session().ExecutePreparedStmt(ctx, sqlInsertID1, []types.Datum{types.NewDatum(val), types.NewDatum(val)}) + stmt, err = tk.Session().ExecutePreparedStmt(ctx, sqlInsertID1, expression.Args2Expressions4Test(val, val)) require.NoError(t, err) require.Nil(t, stmt) - stmt, err = tk.Session().ExecutePreparedStmt(ctx, sqlInsertID2, []types.Datum{types.NewDatum(val), types.NewDatum(val)}) + stmt, err = tk.Session().ExecutePreparedStmt(ctx, sqlInsertID2, expression.Args2Expressions4Test(val, val)) require.NoError(t, err) require.Nil(t, stmt) tk.MustExec("commit") diff --git a/testkit/asynctestkit.go b/testkit/asynctestkit.go index cb9d013db20b6..aa0f3fcadf8ef 100644 --- a/testkit/asynctestkit.go +++ b/testkit/asynctestkit.go @@ -23,9 +23,9 @@ import ( "testing" "github.com/pingcap/errors" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/session" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/sqlexec" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -159,10 +159,7 @@ func (tk *AsyncTestKit) Exec(ctx context.Context, sql string, args ...interface{ return nil, err } - params := make([]types.Datum, len(args)) - for i := 0; i < len(params); i++ { - params[i] = types.NewDatum(args[i]) - } + params := expression.Args2Expressions4Test(args...) rs, err := se.ExecutePreparedStmt(ctx, stmtID, params) if err != nil { diff --git a/testkit/testkit.go b/testkit/testkit.go index d92163b8f8fbe..78605a88e296b 100644 --- a/testkit/testkit.go +++ b/testkit/testkit.go @@ -25,12 +25,12 @@ import ( "time" "github.com/pingcap/errors" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/sessionctx/variable" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/sqlexec" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -256,10 +256,7 @@ func (tk *TestKit) Exec(sql string, args ...interface{}) (sqlexec.RecordSet, err if err != nil { return nil, errors.Trace(err) } - params := make([]types.Datum, len(args)) - for i := 0; i < len(params); i++ { - params[i] = types.NewDatum(args[i]) - } + params := expression.Args2Expressions4Test(args...) rs, err := tk.session.ExecutePreparedStmt(ctx, stmtID, params) if err != nil { return rs, errors.Trace(err) diff --git a/tests/realtikvtest/pessimistictest/pessimistic_test.go b/tests/realtikvtest/pessimistictest/pessimistic_test.go index 89c818dca5d5f..6368a3e0f5250 100644 --- a/tests/realtikvtest/pessimistictest/pessimistic_test.go +++ b/tests/realtikvtest/pessimistictest/pessimistic_test.go @@ -28,6 +28,7 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/parser/auth" @@ -41,7 +42,6 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/tests/realtikvtest" - "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/deadlockhistory" "github.com/stretchr/testify/require" @@ -2767,7 +2767,7 @@ func TestPlanCacheSchemaChange(t *testing.T) { stmtID, _, _, err := tk2.Session().PrepareStmt("update t set vv = vv + 1 where v = ?") require.NoError(t, err) - _, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(1)}) + _, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(1)) require.NoError(t, err) tk.MustExec("begin pessimistic") @@ -2786,11 +2786,11 @@ func TestPlanCacheSchemaChange(t *testing.T) { tk.CheckExecResult(1, 0) tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) - _, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(4)}) + _, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(4)) require.NoError(t, err) tk2.CheckExecResult(0, 0) tk2.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) - _, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(5)}) + _, err = tk2.Session().ExecutePreparedStmt(ctx, stmtID, expression.Args2Expressions4Test(5)) require.NoError(t, err) tk2.CheckExecResult(1, 0) tk2.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) diff --git a/tests/realtikvtest/txntest/txn_state_test.go b/tests/realtikvtest/txntest/txn_state_test.go index 092c3af2f0b8d..59049dd129151 100644 --- a/tests/realtikvtest/txntest/txn_state_test.go +++ b/tests/realtikvtest/txntest/txn_state_test.go @@ -21,11 +21,11 @@ import ( "time" "github.com/pingcap/failpoint" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/session/txninfo" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/tests/realtikvtest" - "github.com/pingcap/tidb/types" "github.com/stretchr/testify/require" ) @@ -309,7 +309,7 @@ func TestTxnInfoWithPSProtocol(t *testing.T) { require.NoError(t, failpoint.Enable("tikvclient/beforePrewrite", "pause")) ch := make(chan interface{}) go func() { - _, err := tk.Session().ExecutePreparedStmt(context.Background(), idInsert, types.MakeDatums(1)) + _, err := tk.Session().ExecutePreparedStmt(context.Background(), idInsert, expression.Args2Expressions4Test(1)) require.NoError(t, err) ch <- nil }() @@ -338,12 +338,12 @@ func TestTxnInfoWithPSProtocol(t *testing.T) { tk.MustExec("begin pessimistic") - _, err = tk.Session().ExecutePreparedStmt(context.Background(), id1, types.MakeDatums(1)) + _, err = tk.Session().ExecutePreparedStmt(context.Background(), id1, expression.Args2Expressions4Test(1)) require.NoError(t, err) require.NoError(t, failpoint.Enable("tikvclient/beforePessimisticLock", "pause")) go func() { - _, err := tk.Session().ExecutePreparedStmt(context.Background(), id2, types.MakeDatums(1)) + _, err := tk.Session().ExecutePreparedStmt(context.Background(), id2, expression.Args2Expressions4Test(1)) require.NoError(t, err) ch <- nil }() diff --git a/tests/realtikvtest/txntest/txn_test.go b/tests/realtikvtest/txntest/txn_test.go index 3d7c512c14505..e282f3d84fada 100644 --- a/tests/realtikvtest/txntest/txn_test.go +++ b/tests/realtikvtest/txntest/txn_test.go @@ -19,10 +19,10 @@ import ( "fmt" "testing" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/tests/realtikvtest" - "github.com/pingcap/tidb/types" "github.com/stretchr/testify/require" ) @@ -41,7 +41,7 @@ func TestInTxnPSProtoPointGet(t *testing.T) { require.NoError(t, err) idForUpdate, _, _, err := tk.Session().PrepareStmt("select c1, c2 from t1 where c1 = ? for update") require.NoError(t, err) - params := []types.Datum{types.NewDatum(1)} + params := expression.Args2Expressions4Test(1) rs, err := tk.Session().ExecutePreparedStmt(ctx, id, params) require.NoError(t, err) tk.ResultSetToResult(rs, fmt.Sprintf("%v", rs)).Check(testkit.Rows("1 10"))