Skip to content

Commit

Permalink
planner: allow TableDual to match the required property if the row co…
Browse files Browse the repository at this point in the history
…unt is 0 (#16927) (#17014)
  • Loading branch information
sre-bot authored May 7, 2020
1 parent 9b64288 commit 19e5905
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func getPropByOrderByItems(items []*ByItems) (*property.PhysicalProperty, bool)
}

func (p *LogicalTableDual) findBestTask(prop *property.PhysicalProperty) (task, error) {
if !prop.IsEmpty() {
// If the required property is not empty and the row count > 1,
// we cannot ensure this required property.
// But if the row count is 0 or 1, we don't need to care about the property.
if !prop.IsEmpty() && p.RowCount > 1 {
return invalidTask, nil
}
dual := PhysicalTableDual{
Expand Down
10 changes: 10 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,13 @@ partition p2 values less than (unix_timestamp('2020-04-15 00:00:00')))`)
tk.MustQuery("select count(*) from floor_unix_timestamp where ts <= '2020-04-05 23:00:00'").Check(testkit.Rows("4"))
tk.MustQuery("select * from floor_unix_timestamp partition(p1, p2) where ts > '2020-04-14 00:00:00'").Check(testkit.Rows("2020-04-14 00:00:42.000"))
}

func (s *testIntegrationSuite) TestTableDualWithRequiredProperty(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2;")
tk.MustExec("create table t1 (a int, b int) partition by range(a) " +
"(partition p0 values less than(10), partition p1 values less than MAXVALUE)")
tk.MustExec("create table t2 (a int, b int)")
tk.MustExec("select /*+ MERGE_JOIN(t1, t2) */ * from t1 partition (p0), t2 where t1.a > 100 and t1.a = t2.a")
}

0 comments on commit 19e5905

Please sign in to comment.