planner: refine explain info for batch cop (#20360)
This commit is contained in:
@ -2516,26 +2516,6 @@ func containsLimit(execs []*tipb.Executor) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// When allow batch cop is 1, only agg / topN uses batch cop.
|
||||
// When allow batch cop is 2, every query uses batch cop.
|
||||
func (e *TableReaderExecutor) setBatchCop(v *plannercore.PhysicalTableReader) {
|
||||
if e.storeType != kv.TiFlash || e.keepOrder {
|
||||
return
|
||||
}
|
||||
switch e.ctx.GetSessionVars().AllowBatchCop {
|
||||
case 1:
|
||||
for _, p := range v.TablePlans {
|
||||
switch p.(type) {
|
||||
case *plannercore.PhysicalHashAgg, *plannercore.PhysicalStreamAgg, *plannercore.PhysicalTopN, *plannercore.PhysicalHashJoin:
|
||||
e.batchCop = true
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
e.batchCop = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func buildNoRangeTableReader(b *executorBuilder, v *plannercore.PhysicalTableReader) (*TableReaderExecutor, error) {
|
||||
tablePlans := v.TablePlans
|
||||
if v.StoreType == kv.TiFlash {
|
||||
@ -2570,8 +2550,8 @@ func buildNoRangeTableReader(b *executorBuilder, v *plannercore.PhysicalTableRea
|
||||
plans: v.TablePlans,
|
||||
tablePlan: v.GetTablePlan(),
|
||||
storeType: v.StoreType,
|
||||
batchCop: v.BatchCop,
|
||||
}
|
||||
e.setBatchCop(v)
|
||||
e.buildVirtualColumnInfo()
|
||||
if containsLimit(dagReq.Executors) {
|
||||
e.feedback = statistics.NewQueryFeedback(0, nil, 0, ts.Desc)
|
||||
|
||||
@ -1059,7 +1059,11 @@ func (e *Explain) explainPlanInRowFormat(p Plan, taskType, driverSide, indent st
|
||||
return errors.Errorf("the store type %v is unknown", x.StoreType)
|
||||
}
|
||||
storeType = x.StoreType.Name()
|
||||
err = e.explainPlanInRowFormat(x.tablePlan, "cop["+storeType+"]", "", childIndent, true)
|
||||
taskName := "cop"
|
||||
if x.BatchCop {
|
||||
taskName = "batchCop"
|
||||
}
|
||||
err = e.explainPlanInRowFormat(x.tablePlan, taskName+"["+storeType+"]", "", childIndent, true)
|
||||
case *PhysicalIndexReader:
|
||||
err = e.explainPlanInRowFormat(x.indexPlan, "cop[tikv]", "", childIndent, true)
|
||||
case *PhysicalIndexLookUpReader:
|
||||
|
||||
@ -15,6 +15,7 @@ package core
|
||||
|
||||
import (
|
||||
"github.com/pingcap/tidb/expression"
|
||||
"github.com/pingcap/tidb/kv"
|
||||
"github.com/pingcap/tidb/planner/property"
|
||||
"github.com/pingcap/tidb/sessionctx"
|
||||
"github.com/pingcap/tidb/types"
|
||||
@ -418,6 +419,21 @@ func (p PhysicalTableReader) Init(ctx sessionctx.Context, offset int) *PhysicalT
|
||||
if p.tablePlan != nil {
|
||||
p.TablePlans = flattenPushDownPlan(p.tablePlan)
|
||||
p.schema = p.tablePlan.Schema()
|
||||
if p.StoreType == kv.TiFlash && !p.GetTableScan().KeepOrder {
|
||||
// When allow batch cop is 1, only agg / topN uses batch cop.
|
||||
// When allow batch cop is 2, every query uses batch cop.
|
||||
switch ctx.GetSessionVars().AllowBatchCop {
|
||||
case 1:
|
||||
for _, plan := range p.TablePlans {
|
||||
switch plan.(type) {
|
||||
case *PhysicalHashAgg, *PhysicalStreamAgg, *PhysicalTopN:
|
||||
p.BatchCop = true
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
p.BatchCop = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
@ -582,8 +582,8 @@ func (s *testIntegrationSerialSuite) TestAggPushDownEngine(c *C) {
|
||||
tk.MustQuery("desc select approx_count_distinct(a) from t").Check(testkit.Rows(
|
||||
"StreamAgg_16 1.00 root funcs:approx_count_distinct(Column#5)->Column#3",
|
||||
"└─TableReader_17 1.00 root data:StreamAgg_8",
|
||||
" └─StreamAgg_8 1.00 cop[tiflash] funcs:approx_count_distinct(test.t.a)->Column#5",
|
||||
" └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"))
|
||||
" └─StreamAgg_8 1.00 batchCop[tiflash] funcs:approx_count_distinct(test.t.a)->Column#5",
|
||||
" └─TableFullScan_15 10000.00 batchCop[tiflash] table:t keep order:false, stats:pseudo"))
|
||||
|
||||
tk.MustExec("set @@session.tidb_isolation_read_engines = 'tikv'")
|
||||
|
||||
|
||||
@ -75,6 +75,9 @@ type PhysicalTableReader struct {
|
||||
// StoreType indicates table read from which type of store.
|
||||
StoreType kv.StoreType
|
||||
|
||||
// BatchCop = true means the cop task in the physical table reader will be executed in batch mode(use in TiFlash only)
|
||||
BatchCop bool
|
||||
|
||||
IsCommonHandle bool
|
||||
|
||||
// Used by partition table.
|
||||
@ -143,6 +146,7 @@ func (p *PhysicalTableReader) Clone() (PhysicalPlan, error) {
|
||||
}
|
||||
cloned.physicalSchemaProducer = *base
|
||||
cloned.StoreType = p.StoreType
|
||||
cloned.BatchCop = p.BatchCop
|
||||
cloned.IsCommonHandle = p.IsCommonHandle
|
||||
if cloned.tablePlan, err = p.tablePlan.Clone(); err != nil {
|
||||
return nil, err
|
||||
|
||||
1190
planner/core/testdata/integration_serial_suite_out.json
vendored
1190
planner/core/testdata/integration_serial_suite_out.json
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user