-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bindinfo: migrate testSerialSuite to testify (#28385)
- Loading branch information
Showing
4 changed files
with
133 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package bindinfo_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/failpoint" | ||
"github.com/pingcap/tidb/testkit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOptimizeOnlyOnce(t *testing.T) { | ||
store, clean := testkit.CreateMockStore(t) | ||
defer clean() | ||
|
||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists t") | ||
tk.MustExec("create table t(a int, b int, index idxa(a))") | ||
tk.MustExec("create global binding for select * from t using select * from t use index(idxa)") | ||
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/planner/checkOptimizeCountOne", "return")) | ||
defer func() { | ||
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/planner/checkOptimizeCountOne")) | ||
}() | ||
tk.MustQuery("select * from t").Check(testkit.Rows()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package bindinfo_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/pingcap/tidb/errno" | ||
"github.com/pingcap/tidb/testkit" | ||
) | ||
|
||
// TestSelectBindingOnGlobalTempTableProhibited covers https://github.com/pingcap/tidb/issues/26377 | ||
func TestSelectBindingOnGlobalTempTableProhibited(t *testing.T) { | ||
store, clean := testkit.CreateMockStore(t) | ||
defer clean() | ||
|
||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("set tidb_enable_global_temporary_table = true") | ||
tk.MustExec("drop table if exists t1,tmp1") | ||
tk.MustExec("create table t1(a int(11))") | ||
tk.MustExec("create global temporary table tmp1(a int(11), key idx_a(a)) on commit delete rows;") | ||
tk.MustExec("create temporary table tmp2(a int(11), key idx_a(a));") | ||
|
||
queries := []string{ | ||
"create global binding for with cte1 as (select a from tmp1) select * from cte1 using with cte1 as (select a from tmp1) select * from cte1", | ||
"create global binding for select * from t1 inner join tmp1 on t1.a=tmp1.a using select * from t1 inner join tmp1 on t1.a=tmp1.a;", | ||
"create global binding for select * from t1 where t1.a in (select a from tmp1) using select * from t1 where t1.a in (select a from tmp1 use index (idx_a));", | ||
"create global binding for select a from t1 union select a from tmp1 using select a from t1 union select a from tmp1 use index (idx_a);", | ||
"create global binding for select t1.a, (select a from tmp1 where tmp1.a=1) as t2 from t1 using select t1.a, (select a from tmp1 where tmp1.a=1) as t2 from t1;", | ||
"create global binding for select * from (select * from tmp1) using select * from (select * from tmp1);", | ||
"create global binding for select * from t1 where t1.a = (select a from tmp1) using select * from t1 where t1.a = (select a from tmp1)", | ||
} | ||
genLocalTemporarySQL := func(sql string) string { | ||
return strings.Replace(sql, "tmp1", "tmp2", -1) | ||
} | ||
for _, query := range queries { | ||
localSQL := genLocalTemporarySQL(query) | ||
queries = append(queries, localSQL) | ||
} | ||
|
||
for _, q := range queries { | ||
tk.MustGetErrCode(q, errno.ErrOptOnTemporaryTable) | ||
} | ||
} | ||
|
||
// TestDMLBindingOnGlobalTempTableProhibited covers https://github.com/pingcap/tidb/issues/27422 | ||
func TestDMLBindingOnGlobalTempTableProhibited(t *testing.T) { | ||
store, clean := testkit.CreateMockStore(t) | ||
defer clean() | ||
|
||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("set tidb_enable_global_temporary_table = true") | ||
tk.MustExec("drop table if exists t1,tmp1,tmp2") | ||
tk.MustExec("create table t1(a int(11))") | ||
tk.MustExec("create global temporary table tmp1(a int(11), key idx_a(a)) on commit delete rows;") | ||
tk.MustExec("create temporary table tmp2(a int(11), key idx_a(a));") | ||
|
||
queries := []string{ | ||
"create global binding for insert into t1 (select * from tmp1) using insert into t1 (select * from tmp1);", | ||
"create global binding for update t1 inner join tmp1 on t1.a=tmp1.a set t1.a=1 using update t1 inner join tmp1 on t1.a=tmp1.a set t1.a=1", | ||
"create global binding for update t1 set t1.a=(select a from tmp1) using update t1 set t1.a=(select a from tmp1)", | ||
"create global binding for update t1 set t1.a=1 where t1.a = (select a from tmp1) using update t1 set t1.a=1 where t1.a = (select a from tmp1)", | ||
"create global binding for with cte1 as (select a from tmp1) update t1 set t1.a=1 where t1.a in (select a from cte1) using with cte1 as (select a from tmp1) update t1 set t1.a=1 where t1.a in (select a from cte1)", | ||
"create global binding for delete from t1 where t1.a in (select a from tmp1) using delete from t1 where t1.a in (select a from tmp1)", | ||
"create global binding for delete from t1 where t1.a = (select a from tmp1) using delete from t1 where t1.a = (select a from tmp1)", | ||
"create global binding for delete t1 from t1,tmp1 using delete t1 from t1,tmp1", | ||
} | ||
genLocalTemporarySQL := func(sql string) string { | ||
return strings.Replace(sql, "tmp1", "tmp2", -1) | ||
} | ||
for _, query := range queries { | ||
localSQL := genLocalTemporarySQL(query) | ||
queries = append(queries, localSQL) | ||
} | ||
|
||
for _, q := range queries { | ||
tk.MustGetErrCode(q, errno.ErrOptOnTemporaryTable) | ||
} | ||
} |