Skip to content

Commit

Permalink
executor: close recordset again (#40010)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei committed Dec 19, 2022
1 parent f150d37 commit 47f5460
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
startup --host_jvm_args=-Xmx5g
startup --host_jvm_args=-Xmx8g
startup --unlimit_coredumps

run:ci --color=yes
Expand Down
3 changes: 1 addition & 2 deletions ddl/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func TestCreateSequence(t *testing.T) {
// test unsupported table option in sequence.
tk.MustGetErrCode("create sequence seq CHARSET=utf8", mysql.ErrSequenceUnsupportedTableOption)

_, err := tk.Exec("create sequence seq comment=\"test\"")
require.NoError(t, err)
tk.MustExec("create sequence seq comment=\"test\"")

sequenceTable := external.GetTableByName(t, tk, "test", "seq")

Expand Down
2 changes: 1 addition & 1 deletion executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestAdminCheckIndexInLocalTemporaryMode(t *testing.T) {
tk.MustExec("drop table if exists local_temporary_admin_test;")
tk.MustExec("create temporary table local_temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2))")
tk.MustExec("insert local_temporary_admin_test (c1, c2) values (1,1), (2,2), (3,3);")
_, err := tk.Exec("admin check table local_temporary_admin_test;")
err := tk.ExecToErr("admin check table local_temporary_admin_test;")
require.EqualError(t, err, core.ErrOptOnTemporaryTable.GenWithStackByArgs("admin check table").Error())
tk.MustExec("drop table if exists temporary_admin_test;")

Expand Down
3 changes: 1 addition & 2 deletions executor/autoidtest/autoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ func TestAlterTableAutoIDCache(t *testing.T) {

// Note that auto_id_cache=1 use a different implementation, switch between them is not allowed.
// TODO: relax this restriction and update the test case.
_, err = tk.Exec("alter table t_473 auto_id_cache = 1")
require.Error(t, err)
tk.MustExecToErr("alter table t_473 auto_id_cache = 1")
}

func TestMockAutoIDServiceError(t *testing.T) {
Expand Down
26 changes: 9 additions & 17 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4623,13 +4623,10 @@ func TestUnion2(t *testing.T) {
terr = errors.Cause(err).(*terror.Error)
require.Equal(t, errors.ErrCode(mysql.ErrWrongUsage), terr.Code())

_, err = tk.Exec("(select a from t order by a) union all select a from t limit 1 union all select a from t limit 1")
require.Truef(t, terror.ErrorEqual(err, plannercore.ErrWrongUsage), "err %v", err)
tk.MustGetDBError("(select a from t order by a) union all select a from t limit 1 union all select a from t limit 1", plannercore.ErrWrongUsage)

_, err = tk.Exec("(select a from t limit 1) union all select a from t limit 1")
require.NoError(t, err)
_, err = tk.Exec("(select a from t order by a) union all select a from t order by a")
require.NoError(t, err)
tk.MustExec("(select a from t limit 1) union all select a from t limit 1")
tk.MustExec("(select a from t order by a) union all select a from t order by a")

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
Expand Down Expand Up @@ -4700,8 +4697,8 @@ func TestUnion2(t *testing.T) {
tk.MustExec("insert into t2 values(3,'c'),(4,'d'),(5,'f'),(6,'e')")
tk.MustExec("analyze table t1")
tk.MustExec("analyze table t2")
_, err = tk.Exec("(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b")
require.Equal(t, "[planner:1250]Table 't1' from one of the SELECTs cannot be used in global ORDER clause", err.Error())
tk.MustGetErrMsg("(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b",
"[planner:1250]Table 't1' from one of the SELECTs cannot be used in global ORDER clause")

// #issue 9900
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -4855,15 +4852,11 @@ func TestSQLMode(t *testing.T) {
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a tinyint not null)")
tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'")
_, err := tk.Exec("insert t values ()")
require.Error(t, err)

_, err = tk.Exec("insert t values ('1000')")
require.Error(t, err)
tk.ExecToErr("insert t values ()")
tk.ExecToErr("insert t values ('1000')")

tk.MustExec("create table if not exists tdouble (a double(3,2))")
_, err = tk.Exec("insert tdouble values (10.23)")
require.Error(t, err)
tk.ExecToErr("insert tdouble values (10.23)")

tk.MustExec("set sql_mode = ''")
tk.MustExec("insert t values ()")
Expand Down Expand Up @@ -4891,8 +4884,7 @@ func TestSQLMode(t *testing.T) {
tk2.MustQuery("select * from t2").Check(testkit.Rows("abc"))

// session1 is still in strict mode.
_, err = tk.Exec("insert t2 values ('abcd')")
require.Error(t, err)
tk.ExecToErr("insert t2 values ('abcd')")
// Restore original global strict mode.
tk.MustExec("set @@global.sql_mode = 'STRICT_TRANS_TABLES'")
}
Expand Down
12 changes: 6 additions & 6 deletions executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func TestGrantDBScope(t *testing.T) {
}

// Grant in wrong scope.
_, err := tk.Exec(` grant create user on test.* to 'testDB1'@'localhost';`)
err := tk.ExecToErr(` grant create user on test.* to 'testDB1'@'localhost';`)
require.True(t, terror.ErrorEqual(err, executor.ErrWrongUsage.GenWithStackByArgs("DB GRANT", "GLOBAL PRIVILEGES")))

_, err = tk.Exec("GRANT SUPER ON test.* TO 'testDB1'@'localhost';")
err = tk.ExecToErr("GRANT SUPER ON test.* TO 'testDB1'@'localhost';")
require.True(t, terror.ErrorEqual(err, executor.ErrWrongUsage.GenWithStackByArgs("DB GRANT", "NON-DB PRIVILEGES")))
}

Expand Down Expand Up @@ -168,8 +168,8 @@ func TestGrantTableScope(t *testing.T) {
require.Greater(t, strings.Index(p, mysql.Priv2SetStr[v]), -1)
}

_, err := tk.Exec("GRANT SUPER ON test2 TO 'testTbl1'@'localhost';")
require.EqualError(t, err, "[executor:1144]Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used")
tk.MustGetErrMsg("GRANT SUPER ON test2 TO 'testTbl1'@'localhost';",
"[executor:1144]Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used")
}

func TestGrantColumnScope(t *testing.T) {
Expand Down Expand Up @@ -213,8 +213,8 @@ func TestGrantColumnScope(t *testing.T) {
require.Greater(t, strings.Index(p, mysql.Priv2SetStr[v]), -1)
}

_, err := tk.Exec("GRANT SUPER(c2) ON test3 TO 'testCol1'@'localhost';")
require.EqualError(t, err, "[executor:1221]Incorrect usage of COLUMN GRANT and NON-COLUMN PRIVILEGES")
tk.MustGetErrMsg("GRANT SUPER(c2) ON test3 TO 'testCol1'@'localhost';",
"[executor:1221]Incorrect usage of COLUMN GRANT and NON-COLUMN PRIVILEGES")
}

func TestIssue2456(t *testing.T) {
Expand Down
19 changes: 6 additions & 13 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func TestPrepareMaxParamCountCheck(t *testing.T) {
require.NoError(t, err)

bigSQL, bigParams := generateBatchSQL(math.MaxUint16 + 2)
_, err = tk.Exec(bigSQL, bigParams...)
err = tk.ExecToErr(bigSQL, bigParams...)
require.Error(t, err)
require.EqualError(t, err, "[executor:1390]Prepared statement contains too many placeholders")
}
Expand Down Expand Up @@ -987,16 +987,12 @@ func TestBatchInsertDelete(t *testing.T) {

// Test tidb_batch_insert could not work if enable-batch-dml is disabled.
tk.MustExec("set @@session.tidb_batch_insert=1;")
_, err = tk.Exec("insert into batch_insert (c) select * from batch_insert;")
require.Error(t, err)
require.True(t, kv.ErrTxnTooLarge.Equal(err))
tk.MustGetErrCode("insert into batch_insert (c) select * from batch_insert;", errno.ErrTxnTooLarge)
tk.MustExec("set @@session.tidb_batch_insert=0;")

// for on duplicate key
_, err = tk.Exec(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
on duplicate key update batch_insert_on_duplicate.id=batch_insert_on_duplicate.id+1000;`)
require.Error(t, err)
require.Truef(t, kv.ErrTxnTooLarge.Equal(err), "%v", err)
tk.MustGetErrCode(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
on duplicate key update batch_insert_on_duplicate.id=batch_insert_on_duplicate.id+1000;`, errno.ErrTxnTooLarge)
r = tk.MustQuery("select count(*) from batch_insert;")
r.Check(testkit.Rows("320"))

Expand All @@ -1022,17 +1018,14 @@ func TestBatchInsertDelete(t *testing.T) {
tk.MustExec("set @@session.tidb_dml_batch_size=50;")

// for on duplicate key
_, err = tk.Exec(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
tk.MustExec(`insert into batch_insert_on_duplicate select * from batch_insert_on_duplicate as tt
on duplicate key update batch_insert_on_duplicate.id=batch_insert_on_duplicate.id+1000;`)
require.NoError(t, err)
r = tk.MustQuery("select count(*) from batch_insert_on_duplicate;")
r.Check(testkit.Rows("320"))

// Disable BachInsert mode in transition.
tk.MustExec("begin;")
_, err = tk.Exec("insert into batch_insert (c) select * from batch_insert;")
require.Error(t, err)
require.True(t, kv.ErrTxnTooLarge.Equal(err))
tk.MustGetErrCode("insert into batch_insert (c) select * from batch_insert;", errno.ErrTxnTooLarge)
tk.MustExec("rollback;")
r = tk.MustQuery("select count(*) from batch_insert;")
r.Check(testkit.Rows("640"))
Expand Down

0 comments on commit 47f5460

Please sign in to comment.