Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
elsa0520 committed Jun 14, 2024
1 parent 9b769ff commit 3617b94
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/planner/core/casetest/index/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,28 @@ func TestInvisibleIndex(t *testing.T) {
`IndexReader_7 10000.00 root index:IndexFullScan_6`,
`└─IndexFullScan_6 10000.00 cop[tikv] table:t1, index:a(a) keep order:false, stats:pseudo`))
}

func TestRowFunctionMatchTheIndexRangeScan(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`CREATE TABLE t1 (k1 int , k2 int, k3 int, index pk1(k1, k2))`)
tk.MustExec(`create table t2 (k1 int, k2 int)`)
var input []string
var output []struct {
SQL string
Plan []string
Result []string
}
integrationSuiteData := GetIntegrationSuiteData()
integrationSuiteData.LoadTestCases(t, &input, &output)
for i, tt := range input {
testdata.OnRecord(func() {
output[i].SQL = tt
output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format='brief' " + tt).Rows())
output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Sort().Rows())
})
tk.MustQuery("explain format='brief' " + tt).Check(testkit.Rows(output[i].Plan...))
tk.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Result...))
}
}
13 changes: 13 additions & 0 deletions pkg/planner/core/casetest/index/testdata/integration_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@
"select b from t3 where a = 1 and b is not null",
"select b from t3 where a = 1 and b is null"
]
},
{
"name": "TestRowFunctionMatchTheIndexRangeScan",
"cases": [
"select k1 from t1 where (k1,k2) > (1,2)",
"select k1 from t1 where (k1,k2) >= (1,2)",
"select k1 from t1 where (k1,k2) < (1,2)",
"select k1 from t1 where (k1, k2) <= (1,2)",
"select k1 from t1 where (k1,k2) = (1,2)",
"select k1 from t1 where (k1, k2) != (1,2); -- could not match range scan",
"select k1 from t1 where (k1) <=> (1); -- could not match range scan",
"select k1 from t1 where (k1, k2) in ((1,2), (3,4))"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,82 @@
"Result": null
}
]
},
{
"Name": "TestRowFunctionMatchTheIndexRangeScan",
"Cases": [
{
"SQL": "select k1 from t1 where (k1,k2) > (1,2)",
"Plan": [
"Projection 3366.67 root test.t1.k1",
"└─IndexReader 3366.67 root index:IndexRangeScan",
" └─IndexRangeScan 3366.67 cop[tikv] table:t1, index:pk1(k1, k2) range:(1 2,1 +inf], (1,+inf], keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1,k2) >= (1,2)",
"Plan": [
"Projection 3366.67 root test.t1.k1",
"└─IndexReader 3366.67 root index:IndexRangeScan",
" └─IndexRangeScan 3366.67 cop[tikv] table:t1, index:pk1(k1, k2) range:[1 2,1 +inf], (1,+inf], keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1,k2) < (1,2)",
"Plan": [
"Projection 3356.57 root test.t1.k1",
"└─IndexReader 3356.57 root index:IndexRangeScan",
" └─IndexRangeScan 3356.57 cop[tikv] table:t1, index:pk1(k1, k2) range:[-inf,1), [1 -inf,1 2), keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1, k2) <= (1,2)",
"Plan": [
"Projection 3356.57 root test.t1.k1",
"└─IndexReader 3356.57 root index:IndexRangeScan",
" └─IndexRangeScan 3356.57 cop[tikv] table:t1, index:pk1(k1, k2) range:[-inf,1), [1 -inf,1 2], keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1,k2) = (1,2)",
"Plan": [
"Projection 0.10 root test.t1.k1",
"└─IndexReader 0.10 root index:IndexRangeScan",
" └─IndexRangeScan 0.10 cop[tikv] table:t1, index:pk1(k1, k2) range:[1 2,1 2], keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1, k2) != (1,2); -- could not match range scan",
"Plan": [
"Projection 8882.21 root test.t1.k1",
"└─IndexReader 8882.21 root index:Selection",
" └─Selection 8882.21 cop[tikv] or(ne(test.t1.k1, 1), ne(test.t1.k2, 2))",
" └─IndexFullScan 10000.00 cop[tikv] table:t1, index:pk1(k1, k2) keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1) <=> (1); -- could not match range scan",
"Plan": [
"IndexReader 10.00 root index:IndexRangeScan",
"└─IndexRangeScan 10.00 cop[tikv] table:t1, index:pk1(k1, k2) range:[1,1], keep order:false, stats:pseudo"
],
"Result": null
},
{
"SQL": "select k1 from t1 where (k1, k2) in ((1,2), (3,4))",
"Plan": [
"Projection 0.20 root test.t1.k1",
"└─IndexReader 0.20 root index:IndexRangeScan",
" └─IndexRangeScan 0.20 cop[tikv] table:t1, index:pk1(k1, k2) range:[1 2,1 2], [3 4,3 4], keep order:false, stats:pseudo"
],
"Result": null
}
]
}
]

0 comments on commit 3617b94

Please sign in to comment.