-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathunion_node.go
More file actions
145 lines (122 loc) · 3.25 KB
/
union_node.go
File metadata and controls
145 lines (122 loc) · 3.25 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Radon
*
* Copyright 2019 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package builder
import (
"xcontext"
"github.com/xelabs/go-mysqlstack/sqlparser"
"github.com/xelabs/go-mysqlstack/xlog"
)
// UnionNode ...
// eg: select a, b from t1 union select t2.a,t3.b from t2 join t3 on t2.id=t3.id;
// PlanNode1
// / \
// / \
// PlanNode2 PlanNode3
// PlanNode1: UnionNode
// PlanNode2: MergeNode
// PlanNode3: JoinNode
// / \
// / \
// MergeNode MergeNode
// PlanNode2 and PlanNode3 are two independent trees, and they are also the Left
// and Right of PlanNode1.
type UnionNode struct {
log *xlog.Log
Left, Right PlanNode
// Union Type.
Typ string
children []ChildPlan
// referred tables' tableInfo map.
referTables map[string]*tableInfo
}
func newUnionNode(log *xlog.Log, left, right PlanNode, typ string) *UnionNode {
return &UnionNode{
log: log,
Left: left,
Right: right,
Typ: typ,
}
}
// buildQuery used to build the QueryTuple.
func (u *UnionNode) buildQuery(root PlanNode) {
u.Left.buildQuery(u.Left)
u.Right.buildQuery(u.Right)
}
// Children returns the children of the plan.
func (u *UnionNode) Children() []ChildPlan {
return u.children
}
// getReferTables get the referTables.
func (u *UnionNode) getReferTables() map[string]*tableInfo {
return u.referTables
}
// GetQuery used to get the Querys.
func (u *UnionNode) GetQuery() []xcontext.QueryTuple {
querys := u.Left.GetQuery()
querys = append(querys, u.Right.GetQuery()...)
return querys
}
func (u *UnionNode) getFields() []selectTuple {
return u.Left.getFields()
}
// pushOrderBy used to push the order by exprs.
func (u *UnionNode) pushOrderBy(orderBy sqlparser.OrderBy) error {
orderPlan := NewOrderByPlan(u.log, orderBy, u)
u.children = append(u.children, orderPlan)
return orderPlan.Build()
}
// pushLimit used to push limit.
func (u *UnionNode) pushLimit(limit *sqlparser.Limit) error {
limitPlan := NewLimitPlan(u.log, limit)
u.children = append(u.children, limitPlan)
return limitPlan.Build()
}
// Temporarily unreachable.
func (u *UnionNode) calcRoute() (PlanNode, error) {
panic("unreachable")
}
// Temporarily unreachable.
func (u *UnionNode) pushFilter(filter exprInfo) error {
panic("unreachable")
}
// Temporarily unreachable.
func (u *UnionNode) pushKeyFilter(filter exprInfo, table, field string) error {
panic("unreachable")
}
// Temporarily unreachable.
func (u *UnionNode) pushSelectExpr(field selectTuple) (int, error) {
panic("unreachable")
}
// Temporarily unreachable.
func (u *UnionNode) pushHaving(having exprInfo) error {
panic("unreachable")
}
// Temporarily unreachable.
func (u *UnionNode) pushMisc(sel *sqlparser.Select) {
panic("unreachable")
}
// Temporarily unreachable.
func (u *UnionNode) addNoTableFilter(exprs []sqlparser.Expr) {
panic("unreachable")
}
// unreachable.
func (u *UnionNode) pushSelectExprs(fields, groups []selectTuple, sel *sqlparser.Select, aggTyp aggrType) error {
panic("unreachable")
}
// unreachable.
func (u *UnionNode) setParent(p *JoinNode) {
panic("unreachable")
}
// unreachable.
func (u *UnionNode) reOrder(int) {
panic("unreachable")
}
// Order unreachable.
func (u *UnionNode) Order() int {
panic("unreachable")
}