Skip to content

Commit facc820

Browse files
committed
fix test
1 parent 62807f7 commit facc820

5 files changed

Lines changed: 212 additions & 97 deletions

File tree

planner/core/physical_plan_test.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1112
// See the License for the specific language governing permissions and
1213
// limitations under the License.
1314

@@ -455,6 +456,41 @@ func (s *testPlanSuite) TestAggEliminator(c *C) {
455456
}
456457
}
457458

459+
func (s *testPlanSuite) TestINMJHint(c *C) {
460+
var (
461+
input []string
462+
output []struct {
463+
SQL string
464+
Plan []string
465+
Result []string
466+
}
467+
)
468+
s.testData.GetTestCases(c, &input, &output)
469+
store, dom, err := newStoreWithBootstrap()
470+
c.Assert(err, IsNil)
471+
defer func() {
472+
dom.Close()
473+
store.Close()
474+
}()
475+
tk := testkit.NewTestKit(c, store)
476+
tk.MustExec("use test")
477+
tk.MustExec("drop table if exists t1, t2")
478+
tk.MustExec("create table t1(a int primary key, b int not null)")
479+
tk.MustExec("create table t2(a int primary key, b int not null)")
480+
tk.MustExec("insert into t1 values(1,1),(2,2)")
481+
tk.MustExec("insert into t2 values(1,1),(2,1)")
482+
483+
for i, ts := range input {
484+
s.testData.OnRecord(func() {
485+
output[i].SQL = ts
486+
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + ts).Rows())
487+
output[i].Result = s.testData.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows())
488+
})
489+
tk.MustQuery("explain format = 'brief' " + ts).Check(testkit.Rows(output[i].Plan...))
490+
tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...))
491+
}
492+
}
493+
458494
func (s *testPlanSuite) TestEliminateMaxOneRow(c *C) {
459495
var (
460496
input []string
@@ -1568,6 +1604,20 @@ func (s *testPlanSuite) TestIndexJoinHint(c *C) {
15681604
}
15691605
}
15701606

1607+
func (s *testPlanSuite) TestTopNPushDownEmpty(c *C) {
1608+
store, dom, err := newStoreWithBootstrap()
1609+
c.Assert(err, IsNil)
1610+
defer func() {
1611+
dom.Close()
1612+
store.Close()
1613+
}()
1614+
tk := testkit.NewTestKit(c, store)
1615+
tk.MustExec("use test")
1616+
tk.MustExec("drop table if exists t")
1617+
tk.MustExec("create table t(a int, b int, c int, index idx_a(a))")
1618+
tk.MustQuery("select extract(day_hour from 'ziy') as res from t order by res limit 1").Check(testkit.Rows())
1619+
}
1620+
15711621
func (s *testPlanSuite) TestDAGPlanBuilderWindow(c *C) {
15721622
defer testleak.AfterTest(c)()
15731623
var input []string
@@ -1793,6 +1843,39 @@ func (s *testPlanSuite) TestEnumIndex(c *C) {
17931843
}
17941844
}
17951845

1846+
func (s *testPlanSuite) TestIssue27233(c *C) {
1847+
var (
1848+
input []string
1849+
output []struct {
1850+
SQL string
1851+
Plan []string
1852+
Result []string
1853+
}
1854+
)
1855+
s.testData.GetTestCases(c, &input, &output)
1856+
store, dom, err := newStoreWithBootstrap()
1857+
c.Assert(err, IsNil)
1858+
defer func() {
1859+
dom.Close()
1860+
store.Close()
1861+
}()
1862+
tk := testkit.NewTestKit(c, store)
1863+
tk.MustExec("use test")
1864+
tk.MustExec("drop table if exists t")
1865+
tk.MustExec("CREATE TABLE `PK_S_MULTI_31` (\n `COL1` tinyint(45) NOT NULL,\n `COL2` tinyint(45) NOT NULL,\n PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;")
1866+
tk.MustExec("insert into PK_S_MULTI_31 values(122,100),(124,-22),(124,34),(127,103);")
1867+
1868+
for i, ts := range input {
1869+
s.testData.OnRecord(func() {
1870+
output[i].SQL = ts
1871+
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows())
1872+
output[i].Result = s.testData.ConvertRowsToStrings(tk.MustQuery(ts).Sort().Rows())
1873+
})
1874+
tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...))
1875+
tk.MustQuery(ts).Sort().Check(testkit.Rows(output[i].Result...))
1876+
}
1877+
}
1878+
17961879
func (s *testPlanSuite) TestPossibleProperties(c *C) {
17971880
store, dom, err := newStoreWithBootstrap()
17981881
c.Assert(err, IsNil)
@@ -1811,3 +1894,33 @@ func (s *testPlanSuite) TestPossibleProperties(c *C) {
18111894
"1 58.0000",
18121895
))
18131896
}
1897+
1898+
func (s *testPlanSuite) TestSelectionPartialPushDown(c *C) {
1899+
var (
1900+
input []string
1901+
output []struct {
1902+
SQL string
1903+
Plan []string
1904+
}
1905+
)
1906+
s.testData.GetTestCases(c, &input, &output)
1907+
store, dom, err := newStoreWithBootstrap()
1908+
c.Assert(err, IsNil)
1909+
defer func() {
1910+
dom.Close()
1911+
store.Close()
1912+
}()
1913+
tk := testkit.NewTestKit(c, store)
1914+
tk.MustExec("use test")
1915+
tk.MustExec("drop table if exists t1, t2")
1916+
tk.MustExec("create table t1(a int, b int as (a+1) virtual)")
1917+
tk.MustExec("create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a))")
1918+
1919+
for i, ts := range input {
1920+
s.testData.OnRecord(func() {
1921+
output[i].SQL = ts
1922+
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows())
1923+
})
1924+
tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...))
1925+
}
1926+
}

planner/core/plan_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
)
3434

3535
var _ = Suite(&testPlanNormalize{})
36-
var _ = Suite(&testProjectionPushDown{})
3736

3837
type testPlanNormalize struct {
3938
store kv.Storage
@@ -636,28 +635,3 @@ func (s *testPlanNormalize) TestIssue25729(c *C) {
636635
tk.MustExec("insert into t1 values(\"a\", \"adwa\");")
637636
tk.MustQuery("select * from t1 where concat(a, b) like \"aadwa\" and a = \"a\";").Check(testkit.Rows("a adwa"))
638637
}
639-
640-
type testProjectionPushDown struct {
641-
store kv.Storage
642-
dom *domain.Domain
643-
644-
testData testutil.TestData
645-
}
646-
647-
func (s *testProjectionPushDown) SetUpSuite(c *C) {
648-
testleak.BeforeTest()
649-
store, dom, err := newStoreWithBootstrap()
650-
c.Assert(err, IsNil)
651-
s.store = store
652-
s.dom = dom
653-
654-
s.testData, err = testutil.LoadTestSuiteData("testdata", "plan_normalized_suite")
655-
c.Assert(err, IsNil)
656-
}
657-
658-
func (s *testProjectionPushDown) TearDownSuite(c *C) {
659-
c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil)
660-
s.dom.Close()
661-
s.store.Close()
662-
testleak.AfterTest(c)()
663-
}

planner/core/testdata/plan_suite_in.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609
{
610610
"name": "TestPushdownProjection",
611611
"cases": [
612-
"select i + 1 from t;", // InjectProjBelowAgg
612+
"select i + 1 from t;",
613613
"select DATE_FORMAT(t, '%Y-%m-%d %H') as date from t;",
614614
"select md5(s) from t;"
615615
]

planner/core/testdata/plan_suite_out.json

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,64 @@
23372337
},
23382338
{
23392339
"Name": "TestINMJHint",
2340-
"Cases": null
2340+
"Cases": [
2341+
{
2342+
"SQL": "select /*+ inl_merge_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b",
2343+
"Plan": [
2344+
"IndexMergeJoin 12500.00 root left outer join, inner:TableReader, outer key:test.t1.a, inner key:test.t2.a, other cond:eq(test.t1.b, test.t2.b)",
2345+
"├─TableReader(Build) 10000.00 root data:TableFullScan",
2346+
"│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
2347+
"└─TableReader(Probe) 1.00 root data:TableRangeScan",
2348+
" └─TableRangeScan 1.00 cop[tikv] table:t2 range: decided by [test.t1.a], keep order:true, stats:pseudo"
2349+
],
2350+
"Result": [
2351+
"1 1",
2352+
"2 <nil>"
2353+
]
2354+
},
2355+
{
2356+
"SQL": "select /*+ inl_hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b",
2357+
"Plan": [
2358+
"IndexHashJoin 12500.00 root left outer join, inner:TableReader, outer key:test.t1.a, inner key:test.t2.a, equal cond:eq(test.t1.a, test.t2.a), eq(test.t1.b, test.t2.b)",
2359+
"├─TableReader(Build) 10000.00 root data:TableFullScan",
2360+
"│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
2361+
"└─TableReader(Probe) 1.00 root data:TableRangeScan",
2362+
" └─TableRangeScan 1.00 cop[tikv] table:t2 range: decided by [test.t1.a], keep order:false, stats:pseudo"
2363+
],
2364+
"Result": [
2365+
"1 1",
2366+
"2 <nil>"
2367+
]
2368+
},
2369+
{
2370+
"SQL": "select /*+ inl_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b",
2371+
"Plan": [
2372+
"IndexJoin 12500.00 root left outer join, inner:TableReader, outer key:test.t1.a, inner key:test.t2.a, equal cond:eq(test.t1.a, test.t2.a), eq(test.t1.b, test.t2.b)",
2373+
"├─TableReader(Build) 10000.00 root data:TableFullScan",
2374+
"│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
2375+
"└─TableReader(Probe) 1.00 root data:TableRangeScan",
2376+
" └─TableRangeScan 1.00 cop[tikv] table:t2 range: decided by [test.t1.a], keep order:false, stats:pseudo"
2377+
],
2378+
"Result": [
2379+
"1 1",
2380+
"2 <nil>"
2381+
]
2382+
},
2383+
{
2384+
"SQL": "select /*+ hash_join(t2) */ t1.a, t2.a from t1 left join t2 on t1.a=t2.a and t1.b=t2.b",
2385+
"Plan": [
2386+
"HashJoin 12500.00 root left outer join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]",
2387+
"├─TableReader(Build) 10000.00 root data:TableFullScan",
2388+
"│ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
2389+
"└─TableReader(Probe) 10000.00 root data:TableFullScan",
2390+
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
2391+
],
2392+
"Result": [
2393+
"1 1",
2394+
"2 <nil>"
2395+
]
2396+
}
2397+
]
23412398
},
23422399
{
23432400
"Name": "TestEliminateMaxOneRow",
@@ -2598,10 +2655,48 @@
25982655
},
25992656
{
26002657
"Name": "TestIssue27233",
2601-
"Cases": null
2658+
"Cases": [
2659+
{
2660+
"SQL": "SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 order by col2;",
2661+
"Plan": [
2662+
"Sort 0.80 root test.pk_s_multi_31.col2",
2663+
"└─Projection 0.80 root test.pk_s_multi_31.col2",
2664+
" └─Selection 0.80 root gt(Column#7, 2)",
2665+
" └─HashAgg 1.00 root group by:test.pk_s_multi_31.col1, test.pk_s_multi_31.col2, funcs:firstrow(test.pk_s_multi_31.col2)->test.pk_s_multi_31.col2, funcs:count(distinct test.pk_s_multi_31.col1, test.pk_s_multi_31.col2)->Column#7",
2666+
" └─HashJoin 100000000.00 root CARTESIAN left outer join, other cond:gt(test.pk_s_multi_31.col1, test.pk_s_multi_31.col1)",
2667+
" ├─IndexReader(Build) 10000.00 root index:IndexFullScan",
2668+
" │ └─IndexFullScan 10000.00 cop[tikv] table:T2, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo",
2669+
" └─IndexReader(Probe) 10000.00 root index:IndexFullScan",
2670+
" └─IndexFullScan 10000.00 cop[tikv] table:T1, index:PRIMARY(COL1, COL2) keep order:false, stats:pseudo"
2671+
],
2672+
"Result": [
2673+
"100"
2674+
]
2675+
}
2676+
]
26022677
},
26032678
{
26042679
"Name": "TestSelectionPartialPushDown",
2605-
"Cases": null
2680+
"Cases": [
2681+
{
2682+
"SQL": "select * from t1 where a > 1 and b > 1",
2683+
"Plan": [
2684+
"Selection 1111.11 root gt(test.t1.b, 1)",
2685+
"└─TableReader 3333.33 root data:Selection",
2686+
" └─Selection 3333.33 cop[tikv] gt(test.t1.a, 1)",
2687+
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
2688+
]
2689+
},
2690+
{
2691+
"SQL": "select * from t2 use index(idx_a) where a > 1 and b > 1 and c > 1",
2692+
"Plan": [
2693+
"Selection 370.37 root gt(test.t2.b, 1)",
2694+
"└─IndexLookUp 1111.11 root ",
2695+
" ├─IndexRangeScan(Build) 3333.33 cop[tikv] table:t2, index:idx_a(a) range:(1,+inf], keep order:false, stats:pseudo",
2696+
" └─Selection(Probe) 1111.11 cop[tikv] gt(test.t2.c, 1)",
2697+
" └─TableRowIDScan 3333.33 cop[tikv] table:t2 keep order:false, stats:pseudo"
2698+
]
2699+
}
2700+
]
26062701
}
26072702
]

0 commit comments

Comments
 (0)