-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathselect_executor.go
More file actions
88 lines (79 loc) · 2.04 KB
/
select_executor.go
File metadata and controls
88 lines (79 loc) · 2.04 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package executor
import (
"backend"
"planner"
"xcontext"
"github.com/pkg/errors"
"github.com/xelabs/go-mysqlstack/xlog"
)
var (
_ Executor = &SelectExecutor{}
)
// SelectExecutor represents select executor
type SelectExecutor struct {
log *xlog.Log
plan planner.Plan
txn backend.Transaction
}
// NewSelectExecutor creates the new select executor.
func NewSelectExecutor(log *xlog.Log, plan planner.Plan, txn backend.Transaction) *SelectExecutor {
return &SelectExecutor{
log: log,
plan: plan,
txn: txn,
}
}
// Execute used to execute the executor.
func (executor *SelectExecutor) Execute(ctx *xcontext.ResultContext) error {
var err error
log := executor.log
plan := executor.plan.(*planner.SelectPlan)
subPlanTree := plan.Children()
reqCtx := xcontext.NewRequestContext()
reqCtx.Mode = plan.ReqMode
reqCtx.TxnMode = xcontext.TxnRead
reqCtx.Querys = plan.Querys
reqCtx.RawQuery = plan.RawQuery
// Execute the parent plan.
if ctx.Results, err = executor.txn.Execute(reqCtx); err != nil {
return err
}
// Execute all the chilren plan.
if subPlanTree != nil {
for _, subPlan := range subPlanTree.Plans() {
switch subPlan.Type() {
case planner.PlanTypeJoin:
joinExecutor := NewJoinExecutor(log, subPlan)
if err := joinExecutor.Execute(ctx); err != nil {
return err
}
case planner.PlanTypeAggregate:
aggrExecutor := NewAggregateExecutor(executor.log, subPlan)
if err := aggrExecutor.Execute(ctx); err != nil {
return err
}
case planner.PlanTypeOrderby:
orderByExecutor := NewOrderByExecutor(executor.log, subPlan)
if err := orderByExecutor.Execute(ctx); err != nil {
return err
}
case planner.PlanTypeLimit:
limitExecutor := NewLimitExecutor(executor.log, subPlan)
if err := limitExecutor.Execute(ctx); err != nil {
return err
}
case planner.PlanTypeDistinct:
default:
return errors.Errorf("unsupported.execute.type:%v", plan.Type())
}
}
}
return nil
}