Skip to content

Commit

Permalink
cherry pick pingcap#34449 to release-5.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
time-and-fate authored and ti-srebot committed May 9, 2022
1 parent ab1f4b0 commit 3f25851
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
40 changes: 39 additions & 1 deletion planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,45 @@ END:
return bestTask, cntPlan, nil
}

<<<<<<< HEAD
func (p *LogicalMemTable) findBestTask(prop *property.PhysicalProperty, planCounter *PlanCounterTp) (t task, cntPlan int64, err error) {
=======
func (p *LogicalMemTable) findBestTask(prop *property.PhysicalProperty, planCounter *PlanCounterTp, opt *physicalOptimizeOp) (t task, cntPlan int64, err error) {
if prop.MPPPartitionTp != property.AnyType {
return invalidTask, 0, nil
}

// If prop.CanAddEnforcer is true, the prop.SortItems need to be set nil for p.findBestTask.
// Before function return, reset it for enforcing task prop.
oldProp := prop.CloneEssentialFields()
if prop.CanAddEnforcer {
// First, get the bestTask without enforced prop
prop.CanAddEnforcer = false
cnt := int64(0)
t, cnt, err = p.findBestTask(prop, planCounter, opt)
if err != nil {
return nil, 0, err
}
prop.CanAddEnforcer = true
if t != invalidTask {
cntPlan = cnt
return
}
// Next, get the bestTask with enforced prop
prop.SortItems = []property.SortItem{}
}
defer func() {
if err != nil {
return
}
if prop.CanAddEnforcer {
*prop = *oldProp
t = enforceProperty(prop, t, p.basePlan.ctx)
prop.CanAddEnforcer = true
}
}()

>>>>>>> 1f4fd0720... planner: enable memtable operator support enforced property (#34449)
if !prop.IsEmpty() || planCounter.Empty() {
return invalidTask, 0, nil
}
Expand Down Expand Up @@ -625,7 +663,7 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter
return
}
var cnt int64
// If prop.enforced is true, the prop.cols need to be set nil for ds.findBestTask.
// If prop.CanAddEnforcer is true, the prop.SortItems need to be set nil for ds.findBestTask.
// Before function return, reset it for enforcing task prop and storing map<prop,task>.
oldProp := prop.CloneEssentialFields()
if prop.CanAddEnforcer {
Expand Down
15 changes: 15 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4145,3 +4145,18 @@ func (s *testIntegrationSuite) TestIssues29711(c *C) {
))

}

func TestIssue31609(t *testing.T) {
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

tk.MustQuery("explain select rank() over (partition by table_name) from information_schema.tables").Check(testkit.Rows(
"Projection_7 10000.00 root Column#27",
"└─Shuffle_11 10000.00 root execution info: concurrency:5, data sources:[MemTableScan_9]",
" └─Window_8 10000.00 root rank()->Column#27 over(partition by Column#3)",
" └─Sort_10 10000.00 root Column#3",
" └─MemTableScan_9 10000.00 root table:TABLES ",
))
}

0 comments on commit 3f25851

Please sign in to comment.