-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathplan_engine.go
More file actions
72 lines (66 loc) · 2.01 KB
/
plan_engine.go
File metadata and controls
72 lines (66 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package executor
import (
"backend"
"planner"
"xcontext"
querypb "github.com/xelabs/go-mysqlstack/sqlparser/depends/query"
"github.com/xelabs/go-mysqlstack/xlog"
)
// PlanEngine interface.
type PlanEngine interface {
execute(ctx *xcontext.ResultContext) error
execBindVars(ctx *xcontext.ResultContext, bindVars map[string]*querypb.BindVariable, wantfields bool) error
getFields(ctx *xcontext.ResultContext, bindVars map[string]*querypb.BindVariable) error
}
// buildEngine used to build the executor tree.
func buildEngine(log *xlog.Log, plan planner.PlanNode, txn backend.Transaction) PlanEngine {
var engine PlanEngine
switch node := plan.(type) {
case *planner.MergeNode:
engine = NewMergeEngine(log, node, txn)
case *planner.JoinNode:
joinEngine := NewJoinEngine(log, node, txn)
joinEngine.left = buildEngine(log, node.Left, txn)
joinEngine.right = buildEngine(log, node.Right, txn)
engine = joinEngine
case *planner.UnionNode:
unionEngine := NewUnionEngine(log, node, txn)
unionEngine.left = buildEngine(log, node.Left, txn)
unionEngine.right = buildEngine(log, node.Right, txn)
engine = unionEngine
}
return engine
}
// execSubPlan used to execute all the children plan.
func execSubPlan(log *xlog.Log, node planner.PlanNode, ctx *xcontext.ResultContext) error {
subPlanTree := node.Children()
if subPlanTree != nil {
for _, subPlan := range subPlanTree.Plans() {
switch subPlan.Type() {
case planner.PlanTypeAggregate:
aggrExecutor := NewAggregateExecutor(log, subPlan)
if err := aggrExecutor.Execute(ctx); err != nil {
return err
}
case planner.PlanTypeOrderby:
orderByExecutor := NewOrderByExecutor(log, subPlan)
if err := orderByExecutor.Execute(ctx); err != nil {
return err
}
case planner.PlanTypeLimit:
limitExecutor := NewLimitExecutor(log, subPlan)
if err := limitExecutor.Execute(ctx); err != nil {
return err
}
}
}
}
return nil
}