Skip to content

Commit

Permalink
executor, tests: move test cases from executor to integrationtest (
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored and wuhuizuo committed Apr 2, 2024
1 parent 1b40ef9 commit b3755ac
Show file tree
Hide file tree
Showing 24 changed files with 3,509 additions and 1,551 deletions.
1 change: 0 additions & 1 deletion pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ go_test(
"inspection_result_test.go",
"inspection_summary_test.go",
"join_pkg_test.go",
"join_test.go",
"joiner_test.go",
"main_test.go",
"memtable_reader_test.go",
Expand Down
64 changes: 0 additions & 64 deletions pkg/executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ package executor_test

import (
"fmt"
"os"
"strconv"
"strings"
"testing"

"github.com/pingcap/tidb/pkg/domain"
Expand Down Expand Up @@ -102,25 +100,6 @@ func TestAnalyzeIndexExtractTopN(t *testing.T) {
}
}

func TestAnalyzePartitionTableForFloat(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@tidb_partition_prune_mode='dynamic'")
tk.MustExec("use test")
tk.MustExec("CREATE TABLE t1 ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, num float(9,8) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH (id) PARTITIONS 128;")
// To reproduce the error we meet in https://github.com/pingcap/tidb/issues/35910, we should use the data provided in this issue
b, err := os.ReadFile("testdata/analyze_test_data.sql")
require.NoError(t, err)
sqls := strings.Split(string(b), ";")
for _, sql := range sqls {
if len(sql) < 1 {
continue
}
tk.MustExec(sql)
}
tk.MustExec("analyze table t1")
}

func TestAnalyzePartitionTableByConcurrencyInDynamic(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -198,46 +177,3 @@ func TestAnalyzePartitionTableByConcurrencyInDynamic(t *testing.T) {
tk.MustQuery("show stats_topn where partition_name = 'global' and table_name = 't'").CheckAt([]int{5, 6}, expected)
}
}

func TestMergeGlobalStatsWithUnAnalyzedPartition(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_partition_prune_mode=dynamic;")
tk.MustExec("CREATE TABLE `t` ( `id` int(11) DEFAULT NULL, `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL ) PARTITION BY RANGE (`id`) (PARTITION `p0` VALUES LESS THAN (3), PARTITION `p1` VALUES LESS THAN (7), PARTITION `p2` VALUES LESS THAN (11));")
tk.MustExec("insert into t values (1,1,1,1),(2,2,2,2),(4,4,4,4),(5,5,5,5),(6,6,6,6),(8,8,8,8),(9,9,9,9);")
tk.MustExec("create index idxa on t (a);")
tk.MustExec("create index idxb on t (b);")
tk.MustExec("create index idxc on t (c);")
tk.MustExec("analyze table t partition p0 index idxa;")
tk.MustExec("analyze table t partition p1 index idxb;")
tk.MustExec("analyze table t partition p2 index idxc;")
tk.MustQuery("show warnings").Check(testkit.Rows(
"Warning 1105 The version 2 would collect all statistics not only the selected indexes",
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p2, reason to use this rate is \"use min(1, 110000/10000) as the sample-rate=1\""))
tk.MustExec("analyze table t partition p0;")
tk.MustQuery("show warnings").Check(testkit.Rows(
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0, reason to use this rate is \"use min(1, 110000/2) as the sample-rate=1\""))
}

func TestSetFastAnalyzeSystemVariable(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@session.tidb_enable_fast_analyze=1")
tk.MustQuery("show warnings").Check(testkit.Rows(
"Warning 1105 the fast analyze feature has already been removed in TiDB v7.5.0, so this will have no effect"))
}

func TestIncrementalAnalyze(t *testing.T) {
msg := "the incremental analyze feature has already been removed in TiDB v7.5.0, so this will have no effect"
store := testkit.CreateMockStore(t)
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, primary key(a), index idx(b))")
tk.MustMatchErrMsg("analyze incremental table t index", msg)
// Create a partition table.
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, primary key(a), index idx(b)) partition by range(a) (partition p0 values less than (10), partition p1 values less than (20))")
tk.MustMatchErrMsg("analyze incremental table t partition p0 index idx", msg)
}
174 changes: 0 additions & 174 deletions pkg/executor/batch_point_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,135 +30,6 @@ import (
"github.com/tikv/client-go/v2/tikv"
)

func TestBatchPointGetExec(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int primary key auto_increment not null, b int, c int, unique key idx_abc(a, b, c))")
tk.MustExec("insert into t values(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 5)")
tk.MustQuery("select * from t").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"3 3 3",
"4 4 5",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (1, 1, 1), (1, 1, 1))").Check(testkit.Rows(
"1 1 1",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (2, 2, 2), (1, 1, 1))").Check(testkit.Rows(
"1 1 1",
"2 2 2",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (2, 2, 2), (100, 1, 1))").Check(testkit.Rows(
"1 1 1",
"2 2 2",
))
tk.MustQuery("select a, b, c from t where (a, b, c) in ((1, 1, 1), (2, 2, 2), (100, 1, 1), (4, 4, 5))").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"4 4 5",
))
tk.MustQuery("select * from t where a in (1, 2, 4, 1, 2)").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"4 4 5",
))
tk.MustQuery("select * from t where a in (1, 2, 4, 1, 2, 100)").Check(testkit.Rows(
"1 1 1",
"2 2 2",
"4 4 5",
))
tk.MustQuery("select a from t where a in (1, 2, 4, 1, 2, 100)").Check(testkit.Rows(
"1",
"2",
"4",
))
}

func TestBatchPointGetInTxn(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int primary key auto_increment, name varchar(30))")

// Fix a bug that BatchPointGetExec doesn't consider membuffer data in a transaction.
tk.MustExec("begin")
tk.MustExec("insert into t values (4, 'name')")
tk.MustQuery("select * from t where id in (4)").Check(testkit.Rows("4 name"))
tk.MustQuery("select * from t where id in (4) for update").Check(testkit.Rows("4 name"))
tk.MustExec("rollback")

tk.MustExec("begin pessimistic")
tk.MustExec("insert into t values (4, 'name')")
tk.MustQuery("select * from t where id in (4)").Check(testkit.Rows("4 name"))
tk.MustQuery("select * from t where id in (4) for update").Check(testkit.Rows("4 name"))
tk.MustExec("rollback")

tk.MustExec("create table s (a int, b int, c int, primary key (a, b))")
tk.MustExec("insert s values (1, 1, 1), (3, 3, 3), (5, 5, 5)")
tk.MustExec("begin pessimistic")
tk.MustExec("update s set c = 10 where a = 3")
tk.MustQuery("select * from s where (a, b) in ((1, 1), (2, 2), (3, 3)) for update").Check(testkit.Rows("1 1 1", "3 3 10"))
tk.MustExec("rollback")
}

func TestBatchPointGetCache(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table customers (id int primary key, token varchar(255) unique)")
tk.MustExec("INSERT INTO test.customers (id, token) VALUES (28, '07j')")
tk.MustExec("INSERT INTO test.customers (id, token) VALUES (29, '03j')")
tk.MustExec("BEGIN")
tk.MustQuery("SELECT id, token FROM test.customers WHERE id IN (28)")
tk.MustQuery("SELECT id, token FROM test.customers WHERE id IN (28, 29);").Check(testkit.Rows("28 07j", "29 03j"))
}

func TestIssue18843(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t18843 ( id bigint(10) primary key, f varchar(191) default null, unique key `idx_f` (`f`))")
tk.MustExec("insert into t18843 values (1, '')")
tk.MustQuery("select * from t18843 where f in (null)").Check(testkit.Rows())

tk.MustExec("insert into t18843 values (2, null)")
tk.MustQuery("select * from t18843 where f in (null)").Check(testkit.Rows())
tk.MustQuery("select * from t18843 where f is null").Check(testkit.Rows("2 <nil>"))
}

func TestIssue24562(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists ttt")
tk.MustExec("create table ttt(a enum(\"a\",\"b\",\"c\",\"d\"), primary key(a));")
tk.MustExec("insert into ttt values(1)")
tk.MustQuery("select * from ttt where ttt.a in (\"1\",\"b\")").Check(testkit.Rows())
tk.MustQuery("select * from ttt where ttt.a in (1,\"b\")").Check(testkit.Rows("a"))
}

func TestBatchPointGetUnsignedHandleWithSort(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t2 (id bigint(20) unsigned, primary key(id))")
tk.MustExec("insert into t2 values (8738875760185212610)")
tk.MustExec("insert into t2 values (9814441339970117597)")
tk.MustExec("insert into t2 values (1)")
tk.MustQuery("select id from t2 where id in (8738875760185212610, 1, 9814441339970117597) order by id").Check(testkit.Rows("1", "8738875760185212610", "9814441339970117597"))
tk.MustQuery("select id from t2 where id in (8738875760185212610, 1, 9814441339970117597) order by id desc").Check(testkit.Rows("9814441339970117597", "8738875760185212610", "1"))
}

func TestBatchPointGetLockExistKey(t *testing.T) {
var wg sync.WaitGroup
errCh := make(chan error)
Expand Down Expand Up @@ -303,22 +174,6 @@ func TestBatchPointGetLockExistKey(t *testing.T) {
}
}

func TestBatchPointGetIssue25167(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int primary key)")
defer func() {
tk.MustExec("drop table if exists t")
}()
time.Sleep(50 * time.Millisecond)
tk.MustExec("set @a=(select current_timestamp(3))")
tk.MustExec("insert into t values (1)")
tk.MustQuery("select * from t as of timestamp @a where a in (1,2,3)").Check(testkit.Rows())
}

func TestCacheSnapShot(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -370,32 +225,3 @@ func TestPointGetForTemporaryTable(t *testing.T) {
tk.MustQuery("select * from t1 where id = 1").Check(testkit.Rows("1 1"))
tk.MustQuery("select * from t1 where id = 2").Check(testkit.Rows())
}

func TestBatchPointGetIssue46779(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("CREATE TABLE t1 (id int, c varchar(128), primary key (id)) PARTITION BY HASH (id) PARTITIONS 3;")
tk.MustExec(`insert into t1 values (1, "a"), (11, "b"), (21, "c")`)
query := "select * from t1 where id in (1, 1, 11)"
tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b"))
query = "select * from t1 where id in (1, 11, 11, 21)"
tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b", "21 c"))

tk.MustExec("drop table if exists t2")
tk.MustExec(`CREATE TABLE t2 (id int, c varchar(128), primary key (id)) partition by range (id)(
partition p0 values less than (10),
partition p1 values less than (20),
partition p2 values less than (30));`)
tk.MustExec(`insert into t2 values (1, "a"), (11, "b"), (21, "c")`)
query = "select * from t2 where id in (1, 1, 11)"
tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b"))
tk.MustHavePlan(query, "Batch_Point_Get") // check if BatchPointGet is used
query = "select * from t2 where id in (1, 11, 11, 21)"
tk.MustQuery(query).Sort().Check(testkit.Rows("1 a", "11 b", "21 c"))
}
Loading

0 comments on commit b3755ac

Please sign in to comment.