Skip to content

Commit

Permalink
tests: move IT in executor to tests/integrationtest (PART 8) (#48098
Browse files Browse the repository at this point in the history
)

ref #47076
  • Loading branch information
Defined2014 authored Nov 1, 2023
1 parent 522d461 commit d380ef4
Show file tree
Hide file tree
Showing 39 changed files with 4,019 additions and 2,313 deletions.
3 changes: 0 additions & 3 deletions pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,11 @@ go_test(
"show_stats_test.go",
"show_test.go",
"shuffle_test.go",
"simple_test.go",
"slow_query_sql_test.go",
"slow_query_test.go",
"sort_test.go",
"split_test.go",
"stale_txn_test.go",
"statement_context_test.go",
"stmtsummary_test.go",
"table_readers_required_rows_test.go",
"temporary_table_test.go",
Expand Down Expand Up @@ -434,7 +432,6 @@ go_test(
"//pkg/util/disk",
"//pkg/util/execdetails",
"//pkg/util/gcutil",
"//pkg/util/globalconn",
"//pkg/util/hack",
"//pkg/util/logutil",
"//pkg/util/memory",
Expand Down
152 changes: 0 additions & 152 deletions pkg/executor/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

"github.com/pingcap/tidb/pkg/ddl"
"github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/testkit"
Expand Down Expand Up @@ -118,157 +117,6 @@ func TestTableSamplePlan(t *testing.T) {
require.Regexp(t, ".*TableSample.*", tableSample)
}

func TestTableSampleSchema(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn
// Clustered index
tk.MustExec("create table t (a varchar(255) primary key, b bigint);")
tk.MustExec("insert into t values ('b', 100), ('y', 100);")
tk.MustQuery("split table t between ('a') and ('z') regions 2;").Check(testkit.Rows("1 1"))
tk.MustQuery("select a from t tablesample regions();").Check(testkit.Rows("b", "y"))

tk.MustExec("drop table t;")
tk.MustExec("create table t (a varchar(255), b int, c decimal, primary key (a, b, c));")
tk.MustQuery("split table t between ('a', 0, 0) and ('z', 100, 100) regions 2;").Check(testkit.Rows("1 1"))
tk.MustExec("insert into t values ('b', 10, 100), ('y', 100, 10);")
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("b 10 100", "y 100 10"))

// PKIsHandle
tk.MustExec("drop table t;")
tk.MustExec("create table t (a bigint primary key, b int default 10);")
tk.MustQuery("split table t between (1) and (100000) regions 4;").Check(testkit.Rows("3 1"))
tk.MustExec("insert into t(a) values (200), (25600), (50300), (99900), (99901)")
tk.MustQuery("select a from t tablesample regions();").Check(testkit.Rows("200", "25600", "50300", "99900"))

// _tidb_rowid
tk.MustExec("drop table t;")
tk.MustExec("create table t (a bigint, b int default 10);")
tk.MustQuery("split table t between (0) and (100000) regions 4;").Check(testkit.Rows("3 1"))
tk.MustExec("insert into t(a) values (1), (2), (3);")
tk.MustQuery("select a from t tablesample regions();").Check(testkit.Rows("1"))
}

func TestTableSampleInvalid(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.MustExec("create table t (a int, b varchar(255));")
tk.MustExec("insert into t values (1, 'abc');")
tk.MustExec("create view v as select * from t;")
tk.MustGetErrCode("select * from v tablesample regions();", errno.ErrInvalidTableSample)
tk.MustGetErrCode("select * from information_schema.tables tablesample regions();", errno.ErrInvalidTableSample)

tk.MustGetErrCode("select a from t tablesample system();", errno.ErrInvalidTableSample)
tk.MustGetErrCode("select a from t tablesample bernoulli(10 percent);", errno.ErrInvalidTableSample)
tk.MustGetErrCode("select a from t as t1 tablesample regions(), t as t2 tablesample system();", errno.ErrInvalidTableSample)
tk.MustGetErrCode("select a from t tablesample ();", errno.ErrInvalidTableSample)
}

func TestTableSampleWithTiDBRowID(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.MustExec("create table t (a int, b varchar(255));")
tk.MustExec("insert into t values (1, 'abc');")
tk.MustQuery("select _tidb_rowid from t tablesample regions();").Check(testkit.Rows("1"))
tk.MustQuery("select a, _tidb_rowid from t tablesample regions();").Check(testkit.Rows("1 1"))
tk.MustQuery("select _tidb_rowid, b from t tablesample regions();").Check(testkit.Rows("1 abc"))
tk.MustQuery("select b, _tidb_rowid, a from t tablesample regions();").Check(testkit.Rows("abc 1 1"))
}

func TestTableSampleWithPartition(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.MustExec("create table t (a int, b varchar(255), primary key (a)) partition by hash(a) partitions 2;")
tk.MustExec("insert into t values (1, '1'), (2, '2'), (3, '3');")
rows := tk.MustQuery("select * from t tablesample regions();").Rows()
require.Len(t, rows, 2)

tk.MustExec("delete from t;")
tk.MustExec("insert into t values (1, '1');")
rows = tk.MustQuery("select * from t partition (p0) tablesample regions();").Rows()
require.Len(t, rows, 0)
rows = tk.MustQuery("select * from t partition (p1) tablesample regions();").Rows()
require.Len(t, rows, 1)

// Test https://github.com/pingcap/tidb/issues/27349.
tk.MustExec("drop table if exists t;")
tk.MustExec(`create table t (a int, b int, unique key idx(a)) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (10),
partition p2 values less than (30),
partition p3 values less than (maxvalue));`)
tk.MustExec("insert into t values (2, 2), (31, 31), (12, 12);")
tk.MustQuery("select _tidb_rowid from t tablesample regions() order by _tidb_rowid;").
Check(testkit.Rows("1", "2", "3")) // The order of _tidb_rowid should be correct.
}

func TestTableSampleGeneratedColumns(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.MustExec("create table t (a int primary key, b int as (a + 1), c int as (b + 1), d int as (c + 1));")
tk.MustQuery("split table t between (0) and (10000) regions 4;").Check(testkit.Rows("3 1"))
tk.MustExec("insert into t(a) values (1), (2), (2999), (4999), (9999);")
tk.MustQuery("select a from t tablesample regions()").Check(testkit.Rows("1", "2999", "9999"))
tk.MustQuery("select c from t tablesample regions()").Check(testkit.Rows("3", "3001", "10001"))
tk.MustQuery("select a, b from t tablesample regions()").Check(
testkit.Rows("1 2", "2999 3000", "9999 10000"))
tk.MustQuery("select d, c from t tablesample regions()").Check(
testkit.Rows("4 3", "3002 3001", "10002 10001"))
tk.MustQuery("select a, d from t tablesample regions()").Check(
testkit.Rows("1 4", "2999 3002", "9999 10002"))
}

func TestTableSampleUnionScanIgnorePendingKV(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.MustExec("create table t (a int primary key);")
tk.MustQuery("split table t between (0) and (40000) regions 4;").Check(testkit.Rows("3 1"))
tk.MustExec("insert into t values (1), (1000), (10002);")
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1", "10002"))

tk.MustExec("begin;")
tk.MustExec("insert into t values (20006), (50000);")
// The memory DB values in transactions are ignored.
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1", "10002"))
tk.MustExec("delete from t where a = 1;")
// The memory DB values in transactions are ignored.
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1", "10002"))
tk.MustExec("commit;")
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1000", "10002", "20006", "50000"))
}

func TestTableSampleTransactionConsistency(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk2 := createSampleTestkit(t, store)

tk.MustExec("create table t (a int primary key);")
tk.MustQuery("split table t between (0) and (40000) regions 4;").Check(testkit.Rows("3 1"))
tk.MustExec("insert into t values (1), (1000), (10002);")

tk.MustExec("begin;")
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1", "10002"))
tk2.MustExec("insert into t values (20006), (50000);")
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1", "10002"))
tk.MustExec("commit;")
tk.MustQuery("select * from t tablesample regions();").Check(testkit.Rows("1", "10002", "20006", "50000"))
}

func TestTableSampleNotSupportedPlanWarning(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
tk.MustExec("create table t (a int primary key, b int, c varchar(255));")
tk.MustQuery("split table t between (0) and (10000) regions 5;").Check(testkit.Rows("4 1"))
tk.MustExec("insert into t values (1000, 1, '1'), (1001, 1, '1'), (2100, 2, '2'), (4500, 3, '3');")

tk.MustExec("create index idx_0 on t (b);")
tk.MustQuery("select a from t tablesample regions() order by a;").Check(
testkit.Rows("1000", "2100", "4500"))
tk.MustQuery("select a from t use index (idx_0) tablesample regions() order by a;").Check(
testkit.Rows("1000", "1001", "2100", "4500"))
tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 8128 Invalid TABLESAMPLE: plan not supported"))
}

func TestMaxChunkSize(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := createSampleTestkit(t, store)
Expand Down
163 changes: 0 additions & 163 deletions pkg/executor/simple_test.go

This file was deleted.

Loading

0 comments on commit d380ef4

Please sign in to comment.