forked from maddyblue/sqlfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_only_session_data.go
executable file
·352 lines (325 loc) · 11.2 KB
/
local_only_session_data.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package sessiondatapb
import (
"fmt"
"strings"
)
// ExperimentalDistSQLPlanningMode controls if and when the opt-driven DistSQL
// planning is used to create physical plans.
type ExperimentalDistSQLPlanningMode int64
const (
// ExperimentalDistSQLPlanningOff means that we always use the old path of
// going from opt.Expr to planNodes and then to processor specs.
ExperimentalDistSQLPlanningOff ExperimentalDistSQLPlanningMode = iota
// ExperimentalDistSQLPlanningOn means that we will attempt to use the new
// path for performing DistSQL planning in the optimizer, and if that
// doesn't succeed for some reason, we will fallback to the old path.
ExperimentalDistSQLPlanningOn
// ExperimentalDistSQLPlanningAlways means that we will only use the new path,
// and if it fails for any reason, the query will fail as well.
ExperimentalDistSQLPlanningAlways
)
func (m ExperimentalDistSQLPlanningMode) String() string {
switch m {
case ExperimentalDistSQLPlanningOff:
return "off"
case ExperimentalDistSQLPlanningOn:
return "on"
case ExperimentalDistSQLPlanningAlways:
return "always"
default:
return fmt.Sprintf("invalid (%d)", m)
}
}
// ExperimentalDistSQLPlanningModeFromString converts a string into a
// ExperimentalDistSQLPlanningMode. False is returned if the conversion was
// unsuccessful.
func ExperimentalDistSQLPlanningModeFromString(val string) (ExperimentalDistSQLPlanningMode, bool) {
var m ExperimentalDistSQLPlanningMode
switch strings.ToUpper(val) {
case "OFF":
m = ExperimentalDistSQLPlanningOff
case "ON":
m = ExperimentalDistSQLPlanningOn
case "ALWAYS":
m = ExperimentalDistSQLPlanningAlways
default:
return 0, false
}
return m, true
}
// DistSQLExecMode controls if and when the Executor distributes queries.
// Since 2.1, we run everything through the DistSQL infrastructure,
// and these settings control whether to use a distributed plan, or use a plan
// that only involves local DistSQL processors.
type DistSQLExecMode int64
const (
// DistSQLOff means that we never distribute queries.
DistSQLOff DistSQLExecMode = iota
// DistSQLAuto means that we automatically decide on a case-by-case basis if
// we distribute queries.
DistSQLAuto
// DistSQLOn means that we distribute queries that are supported.
DistSQLOn
// DistSQLAlways means that we only distribute; unsupported queries fail.
DistSQLAlways
)
func (m DistSQLExecMode) String() string {
switch m {
case DistSQLOff:
return "off"
case DistSQLAuto:
return "auto"
case DistSQLOn:
return "on"
case DistSQLAlways:
return "always"
default:
return fmt.Sprintf("invalid (%d)", m)
}
}
// DistSQLExecModeFromString converts a string into a DistSQLExecMode
func DistSQLExecModeFromString(val string) (_ DistSQLExecMode, ok bool) {
switch strings.ToUpper(val) {
case "OFF":
return DistSQLOff, true
case "AUTO":
return DistSQLAuto, true
case "ON":
return DistSQLOn, true
case "ALWAYS":
return DistSQLAlways, true
default:
return 0, false
}
}
// SerialNormalizationMode controls if and when the Executor uses DistSQL.
// NB: The values of the enums must be stable across releases.
type SerialNormalizationMode int64
const (
// SerialUsesRowID means use INT NOT NULL DEFAULT unique_rowid().
SerialUsesRowID SerialNormalizationMode = 0
// SerialUsesVirtualSequences means create a virtual sequence and
// use INT NOT NULL DEFAULT nextval(...).
SerialUsesVirtualSequences SerialNormalizationMode = 1
// SerialUsesSQLSequences means create a regular SQL sequence and
// use INT NOT NULL DEFAULT nextval(...). Each call to nextval()
// is a distributed call to kv. This minimizes the size of gaps
// between successive sequence numbers (which occur due to
// node failures or errors), but the multiple kv calls
// can impact performance negatively.
SerialUsesSQLSequences SerialNormalizationMode = 2
// SerialUsesCachedSQLSequences is identical to SerialUsesSQLSequences with
// the exception that nodes can cache sequence values. This significantly
// reduces contention and distributed calls to kv, which results in better
// performance. Gaps between sequences may be larger as a result of cached
// values being lost to errors and/or node failures.
SerialUsesCachedSQLSequences SerialNormalizationMode = 3
// SerialUsesUnorderedRowID means use INT NOT NULL DEFAULT unordered_unique_rowid().
SerialUsesUnorderedRowID SerialNormalizationMode = 4
)
func (m SerialNormalizationMode) String() string {
switch m {
case SerialUsesRowID:
return "rowid"
case SerialUsesUnorderedRowID:
return "unordered_rowid"
case SerialUsesVirtualSequences:
return "virtual_sequence"
case SerialUsesSQLSequences:
return "sql_sequence"
case SerialUsesCachedSQLSequences:
return "sql_sequence_cached"
default:
return fmt.Sprintf("invalid (%d)", m)
}
}
// SerialNormalizationModeFromString converts a string into a SerialNormalizationMode
func SerialNormalizationModeFromString(val string) (_ SerialNormalizationMode, ok bool) {
switch strings.ToUpper(val) {
case "ROWID":
return SerialUsesRowID, true
case "UNORDERED_ROWID":
return SerialUsesUnorderedRowID, true
case "VIRTUAL_SEQUENCE":
return SerialUsesVirtualSequences, true
case "SQL_SEQUENCE":
return SerialUsesSQLSequences, true
case "SQL_SEQUENCE_CACHED":
return SerialUsesCachedSQLSequences, true
default:
return 0, false
}
}
// NewSchemaChangerMode controls if and when the new schema changer (in
// sql/schemachanger) is in use.
type NewSchemaChangerMode int64
const (
// UseNewSchemaChangerOff means that we never use the new schema changer.
UseNewSchemaChangerOff NewSchemaChangerMode = iota
// UseNewSchemaChangerOn means that we use the new schema changer for
// supported statements in implicit transactions, but fall back to the old
// schema changer otherwise.
UseNewSchemaChangerOn
// UseNewSchemaChangerUnsafe means that we attempt to use the new schema
// changer for implemented statements including ones which aren't production
// ready. Used for testing/development.
UseNewSchemaChangerUnsafe
// UseNewSchemaChangerUnsafeAlways means that we attempt to use the new schema
// changer for all statements and return errors for unsupported statements.
// Used for testing/development.
UseNewSchemaChangerUnsafeAlways
)
func (m NewSchemaChangerMode) String() string {
switch m {
case UseNewSchemaChangerOff:
return "off"
case UseNewSchemaChangerOn:
return "on"
case UseNewSchemaChangerUnsafe:
return "unsafe"
case UseNewSchemaChangerUnsafeAlways:
return "unsafe_always"
default:
return fmt.Sprintf("invalid (%d)", m)
}
}
// NewSchemaChangerModeFromString converts a string into a NewSchemaChangerMode
func NewSchemaChangerModeFromString(val string) (_ NewSchemaChangerMode, ok bool) {
switch strings.ToUpper(val) {
case "OFF":
return UseNewSchemaChangerOff, true
case "ON":
return UseNewSchemaChangerOn, true
case "UNSAFE":
return UseNewSchemaChangerUnsafe, true
case "UNSAFE_ALWAYS":
return UseNewSchemaChangerUnsafeAlways, true
default:
return 0, false
}
}
//// QoSLevel controls the level of admission control to use for new SQL requests.
//type QoSLevel admission.WorkPriority
//
//const (
// // SystemLow denotes the minimum system QoS level, which is not settable as a
// // session default_transaction_quality_of_service value.
// SystemLow = QoSLevel(admission.LowPri)
//
// // TTLStatsLow denotes a QoS level used internally by the TTL feature, which
// // is not settable as a session default_transaction_quality_of_service value.
// TTLStatsLow = QoSLevel(admission.TTLLowPri)
//
// // TTLLow denotes a QoS level used internally by the TTL feature, which is not
// // settable as a session default_transaction_quality_of_service value.
// TTLLow = QoSLevel(admission.TTLLowPri)
//
// // UserLow denotes an end user QoS level lower than the default.
// UserLow = QoSLevel(admission.UserLowPri)
//
// // Normal denotes an end user QoS level unchanged from the default.
// Normal = QoSLevel(admission.NormalPri)
//
// // UserHigh denotes an end user QoS level higher than the default.
// UserHigh = QoSLevel(admission.UserHighPri)
//
// // Locking denotes an internal increased priority for transactions that are
// // acquiring locks.
// Locking = QoSLevel(admission.LockingPri)
//
// // SystemHigh denotes the maximum system QoS level, which is not settable as a
// // session default_transaction_quality_of_service value.
// SystemHigh = QoSLevel(admission.HighPri)
//)
const (
// NormalName is the external session setting string value to use to mean
// Normal QoS level.
NormalName = "regular"
// UserHighName is the external session setting string value to use to mean
// UserHigh QoS level.
UserHighName = "critical"
// UserLowName is the external session setting string value to use to mean
// UserLow QoS level.
UserLowName = "background"
// SystemHighName is the string value to display indicating a SystemHigh
// QoS level.
SystemHighName = "maximum"
// SystemLowName is the string value to display indicating a SystemLow
// QoS level.
SystemLowName = "minimum"
// TTLLowName is the string value to display indicating a TTLLow QoS level.
TTLLowName = "ttl_low"
// LockingName is the string value to display indicating a Locking QoS level.
LockingName = "locking"
)
//
//var qosLevelsDict = map[QoSLevel]string{
// SystemLow: SystemLowName,
// TTLLow: TTLLowName,
// UserLow: UserLowName,
// Normal: NormalName,
// UserHigh: UserHighName,
// Locking: LockingName,
// SystemHigh: SystemHighName,
//}
//
//// ParseQoSLevelFromString converts a string into a QoSLevel
//func ParseQoSLevelFromString(val string) (_ QoSLevel, ok bool) {
// switch strings.ToUpper(val) {
// case strings.ToUpper(UserHighName):
// return UserHigh, true
// case strings.ToUpper(UserLowName):
// return UserLow, true
// case strings.ToUpper(NormalName):
// return Normal, true
// default:
// return 0, false
// }
//}
//
//// String prints the string representation of the
//// default_transaction_quality_of_service session setting.
//func (e QoSLevel) String() string {
// if name, ok := qosLevelsDict[e]; ok {
// return name
// }
// return fmt.Sprintf("%d", int(e))
//}
//
//// ToQoSLevelString interprets an int32 value as a QoSLevel and returns its
//// String representation.
//func ToQoSLevelString(value int32) string {
// if value > int32(SystemHigh) || value < int32(SystemLow) {
// return fmt.Sprintf("%d", value)
// }
// qosLevel := QoSLevel(value)
// return qosLevel.String()
//}
//
//// Validate checks for a valid user QoSLevel setting before returning it.
//func (e QoSLevel) Validate() QoSLevel {
// switch e {
// case Normal, UserHigh, UserLow:
// return e
// default:
// panic(errors.AssertionFailedf("use of illegal user QoSLevel: %s", e.String()))
// }
//}
//
//// ValidateInternal checks for a valid internal QoSLevel setting before
//// returning it.
//func (e QoSLevel) ValidateInternal() QoSLevel {
// if _, ok := qosLevelsDict[e]; ok {
// return e
// }
// panic(errors.AssertionFailedf("use of illegal internal QoSLevel: %s", e.String()))
//}