Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: add correctness tests about direct reading with ORDER BY and LIMIT #24455

Merged
merged 51 commits into from
May 14, 2021
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d22b8d5
add correctness tests about direct reading with ORDER BY and LIMIT
zhuo-zhi May 7, 2021
73e8b20
sort results before check
zhuo-zhi May 7, 2021
ff7b060
bugfix: prevent dual table
zhuo-zhi May 7, 2021
bee66a8
increase query number
zhuo-zhi May 7, 2021
ca03eac
change ORDER BY columns
zhuo-zhi May 7, 2021
eab6148
skip in DATA RACE mode
zhuo-zhi May 7, 2021
43d4f1d
prevent LIMIT 0
zhuo-zhi May 7, 2021
2d3ea39
add more test cases
zhuo-zhi May 7, 2021
072f073
change partition range and data num
zhuo-zhi May 8, 2021
1e0bbb6
change data num
zhuo-zhi May 8, 2021
ac448dc
Merge branch 'master' of https://github.com/pingcap/tidb into dev_par…
zhuo-zhi May 8, 2021
aad8212
resolve conflict
zhuo-zhi May 8, 2021
14211d9
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 10, 2021
f64cc29
Merge branch 'master' into dev_partitionTest
zhuo-zhi May 10, 2021
2114d60
resolve merge conflict
zhuo-zhi May 10, 2021
7dd79d5
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 10, 2021
c6637d1
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 10, 2021
bab5d2f
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
a135d5d
Merge branch 'master' into dev_partitionTest
qw4990 May 11, 2021
f68207f
Merge branch 'master' of https://github.com/pingcap/tidb into dev_par…
zhuo-zhi May 11, 2021
d284f20
Merge branch 'master' into dev_partitionTest
qw4990 May 11, 2021
5f6ff78
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
44b10fc
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
0848a2b
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
4731782
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
75e3fed
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
51f3c86
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
2b8231e
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
d1ed259
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
852f9b6
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 11, 2021
c71d504
Merge branch 'master' into dev_partitionTest
qw4990 May 12, 2021
9e545fe
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
e8de776
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
e72eb48
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
27bfcbe
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
c58eb12
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
2cd645d
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
bfb49f0
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
5e767f9
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
8f7db0a
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
1a4bef8
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
f82b325
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
b9cde04
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
4bee259
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 12, 2021
0449db5
decrease query number
zhuo-zhi May 13, 2021
3dd9819
Merge branch 'dev_partitionTest' of github.com:zhuo-zhi/tidb into dev…
zhuo-zhi May 13, 2021
9822aad
Merge branch 'master' into dev_partitionTest
qw4990 May 14, 2021
5787399
Merge branch 'master' into dev_partitionTest
qw4990 May 14, 2021
35fda93
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 14, 2021
7430021
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 14, 2021
495ffb1
Merge branch 'master' into dev_partitionTest
ti-chi-bot May 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,85 @@ func (s *partitionTableSuite) TestPartitionInfoDisable(c *C) {
tk.MustQuery("select * from t_info_null where (date = '2020-10-02' or date = '2020-10-06') and app = 'xxx' and media = '19003006'").Check(testkit.Rows())
}

func (s *partitionTableSuite) TestOrderByandLimit(c *C) {
qw4990 marked this conversation as resolved.
Show resolved Hide resolved
if israce.RaceEnabled {
c.Skip("exhaustive types test, skip race test")
}

tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("create database test_orderby_limit")
tk.MustExec("use test_orderby_limit")
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'")

// range partition table
tk.MustExec(`create table trange(a int, b int, index idx_a(a)) partition by range(a) (
partition p0 values less than(300),
partition p1 values less than (500),
partition p2 values less than(1100));`)

// hash partition table
tk.MustExec("create table thash(a int, b int, index idx_a(a), index idx_b(b)) partition by hash(a) partitions 4;")

// regular table
tk.MustExec("create table tregular(a int, b int, index idx_a(a))")

// generate some random data to be inserted
vals := make([]string, 0, 2000)
for i := 0; i < 2000; i++ {
vals = append(vals, fmt.Sprintf("(%v, %v)", rand.Intn(1100), rand.Intn(2000)))
}
tk.MustExec("insert into trange values " + strings.Join(vals, ","))
tk.MustExec("insert into thash values " + strings.Join(vals, ","))
tk.MustExec("insert into tregular values " + strings.Join(vals, ","))

// test indexLookUp
for i := 0; i < 100; i++ {
// explain select * from t where a > {y} use index(idx_a) order by a limit {x}; // check if IndexLookUp is used
// select * from t where a > {y} use index(idx_a) order by a limit {x}; // it can return the correct result
x := rand.Intn(1099)
y := rand.Intn(2000) + 1
queryPartition := fmt.Sprintf("select * from trange use index(idx_a) where a > %v order by a, b limit %v;", x, y)
queryRegular := fmt.Sprintf("select * from tregular use index(idx_a) where a > %v order by a, b limit %v;", x, y)
c.Assert(tk.HasPlan(queryPartition, "IndexLookUp"), IsTrue) // check if IndexLookUp is used
tk.MustQuery(queryPartition).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows())
}

// test tableReader
for i := 0; i < 100; i++ {
// explain select * from t where a > {y} ignore index(idx_a) order by a limit {x}; // check if IndexLookUp is used
// select * from t where a > {y} ignore index(idx_a) order by a limit {x}; // it can return the correct result
x := rand.Intn(1099)
y := rand.Intn(2000) + 1
queryPartition := fmt.Sprintf("select * from trange ignore index(idx_a) where a > %v order by a, b limit %v;", x, y)
queryRegular := fmt.Sprintf("select * from tregular ignore index(idx_a) where a > %v order by a, b limit %v;", x, y)
c.Assert(tk.HasPlan(queryPartition, "TableReader"), IsTrue) // check if tableReader is used
tk.MustQuery(queryPartition).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows())
}

// test indexReader
for i := 0; i < 100; i++ {
// explain select a from t where a > {y} use index(idx_a) order by a limit {x}; // check if IndexLookUp is used
// select a from t where a > {y} use index(idx_a) order by a limit {x}; // it can return the correct result
x := rand.Intn(1099)
y := rand.Intn(2000) + 1
queryPartition := fmt.Sprintf("select a from trange use index(idx_a) where a > %v order by a limit %v;", x, y)
queryRegular := fmt.Sprintf("select a from tregular use index(idx_a) where a > %v order by a limit %v;", x, y)
c.Assert(tk.HasPlan(queryPartition, "IndexReader"), IsTrue) // check if indexReader is used
tk.MustQuery(queryPartition).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows())
}

// test indexMerge
for i := 0; i < 100; i++ {
// explain select /*+ use_index_merge(t) */ * from t where a > 2 or b < 5 order by a limit {x}; // check if IndexMerge is used
// select /*+ use_index_merge(t) */ * from t where a > 2 or b < 5 order by a limit {x}; // can return the correct value
y := rand.Intn(2000) + 1
queryPartition := fmt.Sprintf("select /*+ use_index_merge(thash) */ * from thash where a > 2 or b < 5 order by a, b limit %v;", y)
queryRegular := fmt.Sprintf("select * from tregular where a > 2 or b < 5 order by a, b limit %v;", y)
c.Assert(tk.HasPlan(queryPartition, "IndexMerge"), IsTrue) // check if indexMerge is used
tk.MustQuery(queryPartition).Sort().Check(tk.MustQuery(queryRegular).Sort().Rows())
}
}

func (s *partitionTableSuite) TestBatchGetandPointGetwithHashPartition(c *C) {
if israce.RaceEnabled {
c.Skip("exhaustive types test, skip race test")
Expand Down