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

plan: build separate required physical property for children #8635

Merged
merged 4 commits into from
Dec 10, 2018
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
12 changes: 12 additions & 0 deletions executor/merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ func (s *testSuite) TestMergeJoin(c *C) {
result.Check(testkit.Rows("1", "2", "3", "4", "5", "6", "7"))
result = tk.MustQuery("select /*+ TIDB_SMJ(a, b) */ a.c1 from t a , (select * from t1 limit 3) b where a.c1 = b.c1 order by b.c1;")
result.Check(testkit.Rows("1", "2", "3"))
// Test LogicalSelection under LogicalJoin.
result = tk.MustQuery("select /*+ TIDB_SMJ(a, b) */ a.c1 from t a , (select * from t1 limit 3) b where a.c1 = b.c1 and b.c1 is not null order by b.c1;")
result.Check(testkit.Rows("1", "2", "3"))
tk.MustExec("begin;")
// Test LogicalLock under LogicalJoin.
result = tk.MustQuery("select /*+ TIDB_SMJ(a, b) */ a.c1 from t a , (select * from t1 for update) b where a.c1 = b.c1 order by a.c1;")
result.Check(testkit.Rows("1", "2", "3", "4", "5", "6", "7"))
// Test LogicalUnionScan under LogicalJoin.
tk.MustExec("insert into t1 values(8);")
result = tk.MustQuery("select /*+ TIDB_SMJ(a, b) */ a.c1 from t a , t1 b where a.c1 = b.c1;")
result.Check(testkit.Rows("1", "2", "3", "4", "5", "6", "7"))
tk.MustExec("rollback;")

plannercore.AllowCartesianProduct = false
_, err := tk.Exec("select /*+ TIDB_SMJ(t,t1) */ * from t, t1")
Expand Down
9 changes: 6 additions & 3 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (
)

func (p *LogicalUnionScan) exhaustPhysicalPlans(prop *property.PhysicalProperty) []PhysicalPlan {
us := PhysicalUnionScan{Conditions: p.conditions}.Init(p.ctx, p.stats, prop)
childProp := prop.Clone()
us := PhysicalUnionScan{Conditions: p.conditions}.Init(p.ctx, p.stats, childProp)
return []PhysicalPlan{us}
}

Expand Down Expand Up @@ -857,9 +858,10 @@ func (la *LogicalAggregation) exhaustPhysicalPlans(prop *property.PhysicalProper
}

func (p *LogicalSelection) exhaustPhysicalPlans(prop *property.PhysicalProperty) []PhysicalPlan {
childProp := prop.Clone()
sel := PhysicalSelection{
Conditions: p.Conditions,
}.Init(p.ctx, p.stats.ScaleByExpectCnt(prop.ExpectedCnt), prop)
}.Init(p.ctx, p.stats.ScaleByExpectCnt(prop.ExpectedCnt), childProp)
return []PhysicalPlan{sel}
}

Expand All @@ -880,9 +882,10 @@ func (p *LogicalLimit) exhaustPhysicalPlans(prop *property.PhysicalProperty) []P
}

func (p *LogicalLock) exhaustPhysicalPlans(prop *property.PhysicalProperty) []PhysicalPlan {
childProp := prop.Clone()
lock := PhysicalLock{
Lock: p.Lock,
}.Init(p.ctx, p.stats.ScaleByExpectCnt(prop.ExpectedCnt), prop)
}.Init(p.ctx, p.stats.ScaleByExpectCnt(prop.ExpectedCnt), childProp)
return []PhysicalPlan{lock}
}

Expand Down
14 changes: 14 additions & 0 deletions planner/property/physical_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ func (p *PhysicalProperty) HashCode() []byte {
func (p *PhysicalProperty) String() string {
return fmt.Sprintf("Prop{cols: %v, desc: %v, TaskTp: %s, expectedCount: %v}", p.Cols, p.Desc, p.TaskTp, p.ExpectedCnt)
}

// Clone returns a copy of PhysicalProperty. Currently, this function is only used to build new
// required property for children plan in `exhaustPhysicalPlans`, so we don't copy `Enforced` field
// because if `Enforced` is true, the `Cols` must be empty now, this makes `Enforced` meaningless
// for children nodes.
func (p *PhysicalProperty) Clone() *PhysicalProperty {
prop := &PhysicalProperty{
Cols: p.Cols,
Desc: p.Desc,
TaskTp: p.TaskTp,
ExpectedCnt: p.ExpectedCnt,
eurekaka marked this conversation as resolved.
Show resolved Hide resolved
}
return prop
}