Skip to content

Commit

Permalink
planner: enable memtable operator support enforced property (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
time-and-fate authored May 9, 2022
1 parent 8a2966c commit 1f4fd07
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
36 changes: 35 additions & 1 deletion planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,40 @@ END:
}

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
}
}()

if !prop.IsEmpty() || planCounter.Empty() {
return invalidTask, 0, nil
}
Expand Down Expand Up @@ -778,7 +812,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 @@ -6590,3 +6590,18 @@ func TestIssue29663(t *testing.T) {
" └─Selection_25 2.00 cop[tikv] eq(test.t2.c, test.t1.b)",
" └─TableFullScan_24 2000.00 cop[tikv] table:two keep order:false, stats:pseudo"))
}

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 1f4fd07

Please sign in to comment.