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

planner: add partitioning pruning tests for range partitioning #24554

Merged
merged 9 commits into from
May 19, 2021
85 changes: 85 additions & 0 deletions executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,88 @@ func (s *globalIndexSuite) TestIssue21731(c *C) {
tk.MustExec("drop table if exists p, t")
tk.MustExec("create table t (a int, b int, unique index idx(a)) partition by list columns(b) (partition p0 values in (1), partition p1 values in (2));")
}

func (s *testSuiteWithData) TestRangePartitionBoundariesEq(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("create database TestRangePartitionBoundaries")
defer tk.MustExec("drop database TestRangePartitionBoundaries")
tk.MustExec("use TestRangePartitionBoundaries")
tk.MustExec(`CREATE TABLE t
(a INT, b varchar(255))
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (1000000),
PARTITION p1 VALUES LESS THAN (2000000),
PARTITION p2 VALUES LESS THAN (3000000));
`)
mjonss marked this conversation as resolved.
Show resolved Hide resolved

var input []string
var output []struct {
SQL string
Plan []string
Res []string
}
s.testData.GetTestCases(c, &input, &output)
for i, tt := range input {
var isInsert bool = false
if strings.HasPrefix(strings.ToLower(tt), "insert ") {
isInsert = true
}
s.testData.OnRecord(func() {
output[i].SQL = tt
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + tt).Rows())
if isInsert {
// to avoid double execution of INSERT (and INSERT does not return anything)
output[i].Res = nil
} else {
output[i].Res = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Sort().Rows())
}
})
tk.MustQuery("explain format = 'brief' " + tt).Check(testkit.Rows(output[i].Plan...))
tk.MayQuery(tt).Sort().Check(testkit.Rows(output[i].Res...))
}
}

func (s *testSuiteWithData) TestRangePartitionBoundariesNe(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("create database TestRangePartitionBoundariesNe")
defer tk.MustExec("drop database TestRangePartitionBoundariesNe")
tk.MustExec("use TestRangePartitionBoundariesNe")
tk.MustExec(`CREATE TABLE t
(a INT, b varchar(255))
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (1),
PARTITION p1 VALUES LESS THAN (2),
PARTITION p2 VALUES LESS THAN (3),
PARTITION p3 VALUES LESS THAN (4),
PARTITION p4 VALUES LESS THAN (5),
PARTITION p5 VALUES LESS THAN (6),
PARTITION p6 VALUES LESS THAN (7))`)

var input []string
var output []struct {
SQL string
Plan []string
Res []string
}
s.testData.GetTestCases(c, &input, &output)
for i, tt := range input {
var isInsert bool = false
if strings.HasPrefix(strings.ToLower(tt), "insert ") {
isInsert = true
}
s.testData.OnRecord(func() {
output[i].SQL = tt
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + tt).Rows())
if isInsert {
// to avoid double execution of INSERT (and INSERT does not return anything)
output[i].Res = nil
} else {
output[i].Res = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Sort().Rows())
}
})
tk.MustQuery("explain format = 'brief' " + tt).Check(testkit.Rows(output[i].Plan...))
tk.MayQuery(tt).Sort().Check(testkit.Rows(output[i].Res...))
}
}
89 changes: 89 additions & 0 deletions executor/testdata/executor_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,94 @@
"select count(*) from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL",
"select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 is not NULL"
]
},
{
"name": "TestRangePartitionBoundariesEq",
"cases": [
"INSERT INTO t VALUES (999998, '999998 Filler ...'), (999999, '999999 Filler ...'), (1000000, '1000000 Filler ...'), (1000001, '1000001 Filler ...'), (1000002, '1000002 Filler ...')",
"INSERT INTO t VALUES (1999998, '1999998 Filler ...'), (1999999, '1999999 Filler ...'), (2000000, '2000000 Filler ...'), (2000001, '2000001 Filler ...'), (2000002, '2000002 Filler ...')",
"INSERT INTO t VALUES (2999998, '2999998 Filler ...'), (2999999, '2999999 Filler ...')",
"INSERT INTO t VALUES (-2147483648, 'MIN_INT filler...'), (0, '0 Filler...')",
"SELECT * FROM t WHERE a = -2147483648",
"SELECT * FROM t WHERE a IN (-2147483648)",
"SELECT * FROM t WHERE a = 0",
"SELECT * FROM t WHERE a IN (0)",
"SELECT * FROM t WHERE a = 999998",
"SELECT * FROM t WHERE a IN (999998)",
"SELECT * FROM t WHERE a = 999999",
"SELECT * FROM t WHERE a IN (999999)",
"SELECT * FROM t WHERE a = 1000000",
"SELECT * FROM t WHERE a IN (1000000)",
"SELECT * FROM t WHERE a = 1000001",
"SELECT * FROM t WHERE a IN (1000001)",
"SELECT * FROM t WHERE a = 1000002",
"SELECT * FROM t WHERE a IN (1000002)",
"SELECT * FROM t WHERE a = 3000000",
"SELECT * FROM t WHERE a IN (3000000)",
"SELECT * FROM t WHERE a = 3000001",
"SELECT * FROM t WHERE a IN (3000001)",
"SELECT * FROM t WHERE a IN (-2147483648, -2147483647)",
"SELECT * FROM t WHERE a IN (-2147483647, -2147483646)",
"SELECT * FROM t WHERE a IN (999997, 999998, 999999)",
"SELECT * FROM t WHERE a IN (999998, 999999, 1000000)",
"SELECT * FROM t WHERE a IN (999999, 1000000, 1000001)",
"SELECT * FROM t WHERE a IN (1000000, 1000001, 1000002)",
"SELECT * FROM t WHERE a IN (1999997, 1999998, 1999999)",
"SELECT * FROM t WHERE a IN (1999998, 1999999, 2000000)",
"SELECT * FROM t WHERE a IN (1999999, 2000000, 2000001)",
"SELECT * FROM t WHERE a IN (2000000, 2000001, 2000002)",
"SELECT * FROM t WHERE a IN (2999997, 2999998, 2999999)",
"SELECT * FROM t WHERE a IN (2999998, 2999999, 3000000)",
"SELECT * FROM t WHERE a IN (2999999, 3000000, 3000001)",
"SELECT * FROM t WHERE a IN (3000000, 3000001, 3000002)"
]
},
{
"name": "TestRangePartitionBoundariesNe",
"cases": [
"INSERT INTO t VALUES (0, '0 Filler...')",
"INSERT INTO t VALUES (1, '1 Filler...')",
"INSERT INTO t VALUES (2, '2 Filler...')",
"INSERT INTO t VALUES (3, '3 Filler...')",
"INSERT INTO t VALUES (4, '4 Filler...')",
"INSERT INTO t VALUES (5, '5 Filler...')",
"INSERT INTO t VALUES (6, '6 Filler...')",
"SELECT * FROM t WHERE a != -1",
"SELECT * FROM t WHERE 1 = 1 AND a != -1",
"SELECT * FROM t WHERE a NOT IN (-2, -1)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1",
"SELECT * FROM t WHERE a != 0",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0",
"SELECT * FROM t WHERE a != 1",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1",
"SELECT * FROM t WHERE a != 2",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1 AND a != 2",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1, 2)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1 OR a = 2",
"SELECT * FROM t WHERE a != 3",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1 AND a != 2 AND a != 3",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1, 2, 3)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1 OR a = 2 OR a = 3",
"SELECT * FROM t WHERE a != 4",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1 AND a != 2 AND a != 3 AND a != 4",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1, 2, 3, 4)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1 OR a = 2 OR a = 3 OR a = 4",
"SELECT * FROM t WHERE a != 5",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1 AND a != 2 AND a != 3 AND a != 4 AND a != 5",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1, 2, 3, 4, 5)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1 OR a = 2 OR a = 3 OR a = 4 OR a = 5",
"SELECT * FROM t WHERE a != 6",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1 AND a != 2 AND a != 3 AND a != 4 AND a != 5 AND a != 6",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1, 2, 3, 4, 5, 6)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1 OR a = 2 OR a = 3 OR a = 4 OR a = 5 OR a = 6",
"SELECT * FROM t WHERE a != 7",
"SELECT * FROM t WHERE 1 = 1 AND a != -1 AND a != 0 AND a != 1 AND a != 2 AND a != 3 AND a != 4 AND a != 5 AND a != 6 AND a != 7",
"SELECT * FROM t WHERE a NOT IN (-2, -1, 0, 1, 2, 3, 4, 5, 6, 7)",
"SELECT * FROM t WHERE 1 = 0 OR a = -1 OR a = 0 OR a = 1 OR a = 2 OR a = 3 OR a = 4 OR a = 5 OR a = 6 OR a = 7"
]
}
]
Loading