Skip to content

Commit

Permalink
planner: generate physical plan for IndexMergePath (#11245)
Browse files Browse the repository at this point in the history
  • Loading branch information
hailanwhu authored and sre-bot committed Sep 12, 2019
1 parent 5c48d93 commit 65edb2d
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 79 deletions.
50 changes: 50 additions & 0 deletions cmd/explaintest/r/explain_indexmerge.result
@@ -0,0 +1,50 @@
drop table if exists t;
create table t (a int primary key, b int, c int, d int, e int, f int);
create index tb on t (b);
create index tc on t (c);
create index td on t (d);
load stats 's/explain_indexmerge_stats_t.json';
set session tidb_enable_index_merge = on;
explain select * from t where a < 50 or b < 50;
id count task operator info
IndexMerge_11 98.00 root
├─TableScan_8 49.00 cop table:t, range:[-inf,50), keep order:false
├─IndexScan_9 49.00 cop table:t, index:b, range:[-inf,50), keep order:false
└─TableScan_10 98.00 cop table:t, keep order:false
explain select * from t where (a < 50 or b < 50) and f > 100;
id count task operator info
IndexMerge_12 98.00 root
├─TableScan_8 49.00 cop table:t, range:[-inf,50), keep order:false
├─IndexScan_9 49.00 cop table:t, index:b, range:[-inf,50), keep order:false
└─Selection_11 98.00 cop gt(test.t.f, 100)
└─TableScan_10 98.00 cop table:t, keep order:false
explain select * from t where a < 50 or b < 5000000;
id count task operator info
TableReader_7 4000000.00 root data:Selection_6
└─Selection_6 4000000.00 cop or(lt(test.t.a, 50), lt(test.t.b, 5000000))
└─TableScan_5 5000000.00 cop table:t, range:[-inf,+inf], keep order:false
explain select * from t where b < 50 or c < 50;
id count task operator info
IndexMerge_11 98.00 root
├─IndexScan_8 49.00 cop table:t, index:b, range:[-inf,50), keep order:false
├─IndexScan_9 49.00 cop table:t, index:c, range:[-inf,50), keep order:false
└─TableScan_10 98.00 cop table:t, keep order:false
explain select * from t where b < 50 or c < 5000000;
id count task operator info
TableReader_7 4000000.00 root data:Selection_6
└─Selection_6 4000000.00 cop or(lt(test.t.b, 50), lt(test.t.c, 5000000))
└─TableScan_5 5000000.00 cop table:t, range:[-inf,+inf], keep order:false
explain select * from t where a < 50 or b < 50 or c < 50;
id count task operator info
IndexMerge_12 147.00 root
├─TableScan_8 49.00 cop table:t, range:[-inf,50), keep order:false
├─IndexScan_9 49.00 cop table:t, index:b, range:[-inf,50), keep order:false
├─IndexScan_10 49.00 cop table:t, index:c, range:[-inf,50), keep order:false
└─TableScan_11 147.00 cop table:t, keep order:false
explain select * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10;
id count task operator info
IndexMerge_17 0.00 root
├─TableScan_13 9.00 cop table:t, range:[-inf,10), keep order:false
├─IndexScan_14 9.00 cop table:t, index:d, range:[-inf,10), keep order:false
└─Selection_16 0.00 cop lt(test.t.f, 10), or(lt(test.t.b, 10000), lt(test.t.c, 10000))
└─TableScan_15 18.00 cop table:t, keep order:false
1 change: 1 addition & 0 deletions cmd/explaintest/s/explain_indexmerge_stats_t.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions cmd/explaintest/t/explain_indexmerge.test
@@ -0,0 +1,14 @@
drop table if exists t;
create table t (a int primary key, b int, c int, d int, e int, f int);
create index tb on t (b);
create index tc on t (c);
create index td on t (d);
load stats 's/explain_indexmerge_stats_t.json';
set session tidb_enable_index_merge = on;
explain select * from t where a < 50 or b < 50;
explain select * from t where (a < 50 or b < 50) and f > 100;
explain select * from t where a < 50 or b < 5000000;
explain select * from t where b < 50 or c < 50;
explain select * from t where b < 50 or c < 5000000;
explain select * from t where a < 50 or b < 50 or c < 50;
explain select * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10;
11 changes: 11 additions & 0 deletions planner/core/common_plans.go
Expand Up @@ -622,6 +622,17 @@ func (e *Explain) explainPlanInRowFormat(p PhysicalPlan, taskType, indent string
case *PhysicalIndexLookUpReader:
e.explainPlanInRowFormat(copPlan.indexPlan, "cop", childIndent, false)
e.explainPlanInRowFormat(copPlan.tablePlan, "cop", childIndent, true)
case *PhysicalIndexMergeReader:
for i := 0; i < len(copPlan.partialPlans); i++ {
if copPlan.tablePlan == nil && i == len(copPlan.partialPlans)-1 {
e.explainPlanInRowFormat(copPlan.partialPlans[i], "cop", childIndent, true)
} else {
e.explainPlanInRowFormat(copPlan.partialPlans[i], "cop", childIndent, false)
}
}
if copPlan.tablePlan != nil {
e.explainPlanInRowFormat(copPlan.tablePlan, "cop", childIndent, true)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions planner/core/explain.go
Expand Up @@ -144,6 +144,11 @@ func (p *PhysicalIndexLookUpReader) ExplainInfo() string {
return ""
}

// ExplainInfo implements PhysicalPlan interface.
func (p *PhysicalIndexMergeReader) ExplainInfo() string {
return ""
}

// ExplainInfo implements PhysicalPlan interface.
func (p *PhysicalUnionScan) ExplainInfo() string {
return string(expression.SortedExplainExpressionList(p.Conditions))
Expand Down

0 comments on commit 65edb2d

Please sign in to comment.