forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_plans.go
172 lines (142 loc) · 3.88 KB
/
new_plans.go
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2016 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package plan
import (
"github.com/juju/errors"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/model"
)
// JoinType contains CrossJoin, InnerJoin, LeftOuterJoin, RightOuterJoin, FullOuterJoin, SemiJoin.
type JoinType int
const (
// CrossJoin means Cartesian Product, but not used now.
CrossJoin JoinType = iota
// InnerJoin means inner join.
InnerJoin
// LeftOuterJoin means left join.
LeftOuterJoin
// RightOuterJoin means right join.
RightOuterJoin
// TODO: support semi join.
)
// Join is the logical join plan.
type Join struct {
baseLogicalPlan
JoinType JoinType
EqualConditions []*expression.ScalarFunction
LeftConditions []expression.Expression
RightConditions []expression.Expression
OtherConditions []expression.Expression
}
// Projection represents a select fields plan.
type Projection struct {
baseLogicalPlan
Exprs []expression.Expression
}
// Aggregation represents an aggregate plan.
type Aggregation struct {
baseLogicalPlan
AggFuncs []expression.AggregationFunction
GroupByItems []expression.Expression
}
// Selection means a filter.
type Selection struct {
baseLogicalPlan
// Originally the WHERE or ON condition is parsed into a single expression,
// but after we converted to CNF(Conjunctive normal form), it can be
// split into a list of AND conditions.
Conditions []expression.Expression
}
// Apply gets one row from outer executor and gets one row from inner executor according to outer row.
type Apply struct {
baseLogicalPlan
InnerPlan LogicalPlan
OuterSchema expression.Schema
Checker *ApplyConditionChecker
}
// Exists checks if a query returns result.
type Exists struct {
baseLogicalPlan
}
// MaxOneRow checks if a query returns no more than one row.
type MaxOneRow struct {
baseLogicalPlan
}
// NewTableDual represents a dual table plan.
type NewTableDual struct {
baseLogicalPlan
}
// NewTableScan represents a tablescan without condition push down.
type NewTableScan struct {
baseLogicalPlan
Table *model.TableInfo
Columns []*model.ColumnInfo
DBName *model.CIStr
Desc bool
Ranges []TableRange
AccessCondition []expression.Expression
TableAsName *model.CIStr
LimitCount *int64
}
// Trim trims child's rows.
type Trim struct {
baseLogicalPlan
}
// NewUnion represents Union plan.
type NewUnion struct {
baseLogicalPlan
Selects []LogicalPlan
}
// NewSort stands for the order by plan.
type NewSort struct {
baseLogicalPlan
ByItems []ByItems
ExecLimit *Limit
}
// AddChild for parent.
func addChild(parent Plan, child Plan) {
if child == nil || parent == nil {
return
}
child.AddParent(parent)
parent.AddChild(child)
}
// InsertPlan means inserting plan between two plans.
func InsertPlan(parent Plan, child Plan, insert Plan) error {
err := child.ReplaceParent(parent, insert)
if err != nil {
return errors.Trace(err)
}
err = parent.ReplaceChild(child, insert)
if err != nil {
return errors.Trace(err)
}
insert.AddChild(child)
insert.AddParent(parent)
return nil
}
// RemovePlan means removing a plan.
func RemovePlan(p Plan) error {
parents := p.GetParents()
children := p.GetChildren()
if len(parents) != 1 || len(children) != 1 {
return SystemInternalErrorType.Gen("can't remove this plan")
}
parent, child := parents[0], children[0]
err := parent.ReplaceChild(p, child)
if err != nil {
return errors.Trace(err)
}
err = child.ReplaceParent(p, parent)
return errors.Trace(err)
}