forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plans.go
214 lines (177 loc) · 4.37 KB
/
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright 2015 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 (
"fmt"
"strings"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/util/types"
)
// TableRange represents a range of row handle.
type TableRange struct {
LowVal int64
HighVal int64
}
// ShowDDL is for showing DDL information.
type ShowDDL struct {
basePlan
}
// CheckTable is used for checking table data, built from the 'admin check table' statement.
type CheckTable struct {
basePlan
Tables []*ast.TableName
}
// IndexRange represents an index range to be scanned.
type IndexRange struct {
LowVal []types.Datum
LowExclude bool
HighVal []types.Datum
HighExclude bool
}
// IsPoint returns if the index range is a point.
func (ir *IndexRange) IsPoint() bool {
if len(ir.LowVal) != len(ir.HighVal) {
return false
}
for i := range ir.LowVal {
a := ir.LowVal[i]
b := ir.HighVal[i]
if a.Kind() == types.KindMinNotNull || b.Kind() == types.KindMaxValue {
return false
}
cmp, err := a.CompareDatum(b)
if err != nil {
return false
}
if cmp != 0 {
return false
}
}
return !ir.LowExclude && !ir.HighExclude
}
func (ir *IndexRange) String() string {
lowStrs := make([]string, 0, len(ir.LowVal))
for _, d := range ir.LowVal {
if d.Kind() == types.KindMinNotNull {
lowStrs = append(lowStrs, "-inf")
} else {
lowStrs = append(lowStrs, fmt.Sprintf("%v", d.GetValue()))
}
}
highStrs := make([]string, 0, len(ir.LowVal))
for _, d := range ir.HighVal {
if d.Kind() == types.KindMaxValue {
highStrs = append(highStrs, "+inf")
} else {
highStrs = append(highStrs, fmt.Sprintf("%v", d.GetValue()))
}
}
l, r := "[", "]"
if ir.LowExclude {
l = "("
}
if ir.HighExclude {
r = ")"
}
return l + strings.Join(lowStrs, " ") + "," + strings.Join(highStrs, " ") + r
}
// SelectLock represents a select lock plan.
type SelectLock struct {
baseLogicalPlan
Lock ast.SelectLockType
}
// Limit represents offset and limit plan.
type Limit struct {
baseLogicalPlan
Offset uint64
Count uint64
}
// Distinct represents Distinct plan.
type Distinct struct {
baseLogicalPlan
}
// Prepare represents prepare plan.
type Prepare struct {
basePlan
Name string
SQLText string
}
// Execute represents prepare plan.
type Execute struct {
basePlan
Name string
UsingVars []ast.ExprNode
ID uint32
}
// Deallocate represents deallocate plan.
type Deallocate struct {
basePlan
Name string
}
// Filter represents a plan that filter GetChildByIndex(0)plan result.
type Filter struct {
basePlan
// 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 []ast.ExprNode
}
// Show represents a show plan.
type Show struct {
basePlan
Tp ast.ShowStmtType // Databases/Tables/Columns/....
DBName string
Table *ast.TableName // Used for showing columns.
Column *ast.ColumnName // Used for `desc table column`.
Flag int // Some flag parsed from sql, such as FULL.
Full bool
User string // Used for show grants.
// Used by show variables
GlobalScope bool
}
// Simple represents a simple statement plan which doesn't need any optimization.
type Simple struct {
basePlan
Statement ast.StmtNode
}
// Insert represents an insert plan.
type Insert struct {
baseLogicalPlan
Table *ast.TableRefsClause
Columns []*ast.ColumnName
Lists [][]ast.ExprNode
Setlist []*ast.Assignment
OnDuplicate []*ast.Assignment
IsReplace bool
Priority int
Ignore bool
}
// LoadData represents a loaddata plan.
type LoadData struct {
basePlan
IsLocal bool
Path string
Table *ast.TableName
FieldsInfo *ast.FieldsClause
LinesInfo *ast.LinesClause
}
// DDL represents a DDL statement plan.
type DDL struct {
basePlan
Statement ast.DDLNode
}
// Explain represents a explain plan.
type Explain struct {
basePlan
StmtPlan Plan
}