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

planner: generate physical plan for IndexMergePath #11245

Merged
merged 8 commits into from
Sep 12, 2019
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
50 changes: 50 additions & 0 deletions cmd/explaintest/r/explain_indexmerge.result
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading