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 more tests for pushing IsNull to prefix index #38697

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7710,9 +7710,11 @@ func TestNullConditionForPrefixIndex(t *testing.T) {
KEY idx2 (c1,c2(5))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`)
tk.MustExec("create table t2(a int, b varchar(10), index idx(b(5)))")
tk.MustExec("create table t3(a int, b varchar(10), c int, primary key (a, b(5)) clustered)")
tk.MustExec("set tidb_opt_prefix_index_single_scan = 1")
tk.MustExec("insert into t1 values ('a', '0xfff', '111111'), ('b', '0xfff', '222222'), ('c', '0xfff', ''), ('d', '0xfff', null)")
tk.MustExec("insert into t2 values (1, 'aaaaaa'), (2, 'bbb'), (3, ''), (4, null)")
tk.MustExec("insert into t1 values ('a', '0xfff', '111111'), ('b', '0xfff', '22 '), ('c', '0xfff', ''), ('d', '0xfff', null)")
tk.MustExec("insert into t2 values (1, 'aaaaaa'), (2, 'bb '), (3, ''), (4, null)")
tk.MustExec("insert into t3 values (1, 'aaaaaa', 2), (1, 'bb ', 3), (1, '', 4)")

var input []string
var output []struct {
Expand Down
6 changes: 5 additions & 1 deletion planner/core/testdata/integration_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,12 @@
"select c2 from t1 use index(idx2) where c1 = '0xfff' and c2 is null",
"select c2 from t1 use index(idx2) where c1 >= '0xfff' and c2 is not null",
"select c2 from t1 use index(idx2) where c1 >= '0xfff' and c2 is null",
"select count(1) from t2 use index(idx) where b is not null",
"select count(1) from t2 use index(idx) where b is null",
"select b from t2 use index(idx) where b is not null",
"select b from t2 use index(idx) where b is null"
"select b from t2 use index(idx) where b is null",
"select b from t3 where a = 1 and b is not null",
"select b from t3 where a = 1 and b is null"
]
}
]
50 changes: 47 additions & 3 deletions planner/core/testdata/integration_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -7652,7 +7652,7 @@
"Result": [
"",
"111111",
"222222"
"22 "
]
},
{
Expand All @@ -7679,7 +7679,7 @@
"Result": [
"",
"111111",
"222222"
"22 "
]
},
{
Expand All @@ -7695,6 +7695,30 @@
"<nil>"
]
},
{
"SQL": "select count(1) from t2 use index(idx) where b is not null",
"Plan": [
"StreamAgg 1.00 root funcs:count(Column#6)->Column#4",
"└─IndexReader 1.00 root index:StreamAgg",
" └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#6",
" └─IndexFullScan 9990.00 cop[tikv] table:t2, index:idx(b) keep order:false, stats:pseudo"
],
"Result": [
"3"
]
},
{
"SQL": "select count(1) from t2 use index(idx) where b is null",
"Plan": [
"StreamAgg 1.00 root funcs:count(Column#6)->Column#4",
"└─IndexReader 1.00 root index:StreamAgg",
" └─StreamAgg 1.00 cop[tikv] funcs:count(1)->Column#6",
" └─IndexRangeScan 10.00 cop[tikv] table:t2, index:idx(b) range:[NULL,NULL], keep order:false, stats:pseudo"
],
"Result": [
"1"
]
},
{
"SQL": "select b from t2 use index(idx) where b is not null",
"Plan": [
Expand All @@ -7705,7 +7729,7 @@
"Result": [
"",
"aaaaaa",
"bbb"
"bb "
]
},
{
Expand All @@ -7718,6 +7742,26 @@
"Result": [
"<nil>"
]
},
{
"SQL": "select b from t3 where a = 1 and b is not null",
"Plan": [
"Projection 10.00 root test.t3.b",
"└─TableReader 10.00 root data:TableRangeScan",
" └─TableRangeScan 10.00 cop[tikv] table:t3 range:[1,1], keep order:false, stats:pseudo"
],
"Result": [
"",
"aaaaaa",
"bb "
]
},
{
"SQL": "select b from t3 where a = 1 and b is null",
"Plan": [
"TableDual 0.00 root rows:0"
],
"Result": null
}
]
}
Expand Down