-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
vschema.go
109 lines (87 loc) · 4 KB
/
vschema.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
package plancontext
import (
"context"
"strings"
vschemapb "vitess.io/vitess/go/vt/proto/vschema"
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
"vitess.io/vitess/go/vt/vtenv"
"vitess.io/vitess/go/vt/vtgate/engine"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/vt/key"
querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtgate/semantics"
"vitess.io/vitess/go/vt/vtgate/vindexes"
)
// PlannerVersion is an alias here to make the code more readable
type PlannerVersion = querypb.ExecuteOptions_PlannerVersion
// VSchema defines the interface for this package to fetch
// info about tables.
type VSchema interface {
FindTable(tablename sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error)
FindView(name sqlparser.TableName) sqlparser.SelectStatement
FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error)
DefaultKeyspace() (*vindexes.Keyspace, error)
TargetString() string
Destination() key.Destination
TabletType() topodatapb.TabletType
TargetDestination(qualifier string) (key.Destination, *vindexes.Keyspace, topodatapb.TabletType, error)
AnyKeyspace() (*vindexes.Keyspace, error)
FirstSortedKeyspace() (*vindexes.Keyspace, error)
SysVarSetEnabled() bool
KeyspaceExists(keyspace string) bool
AllKeyspace() ([]*vindexes.Keyspace, error)
FindKeyspace(keyspace string) (*vindexes.Keyspace, error)
GetSemTable() *semantics.SemTable
Planner() PlannerVersion
SetPlannerVersion(pv PlannerVersion)
ConnCollation() collations.ID
Environment() *vtenv.Environment
// ErrorIfShardedF will return an error if the keyspace is sharded,
// and produce a warning if the vtgate if configured to do so
ErrorIfShardedF(keyspace *vindexes.Keyspace, warn, errFmt string, params ...any) error
// WarnUnshardedOnly is used when a feature is only supported in unsharded mode.
// This will let the user know that they are using something
// that could become a problem if they move to a sharded keyspace
WarnUnshardedOnly(format string, params ...any)
// PlannerWarning records warning created during planning.
PlannerWarning(message string)
// ForeignKeyMode returns the foreign_key flag value
ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error)
// KeyspaceError returns any error in the keyspace vschema.
KeyspaceError(keyspace string) error
GetForeignKeyChecksState() *bool
// GetVSchema returns the latest cached vindexes.VSchema
GetVSchema() *vindexes.VSchema
// GetSrvVschema returns the latest cached vschema.SrvVSchema
GetSrvVschema() *vschemapb.SrvVSchema
// FindRoutedShard looks up shard routing rules for a shard
FindRoutedShard(keyspace, shard string) (string, error)
// IsShardRoutingEnabled returns true if partial shard routing is enabled
IsShardRoutingEnabled() bool
// IsViewsEnabled returns true if Vitess manages the views.
IsViewsEnabled() bool
// GetUDV returns user defined value from the variable passed.
GetUDV(name string) *querypb.BindVariable
// PlanPrepareStatement plans the prepared statement.
PlanPrepareStatement(ctx context.Context, query string) (*engine.Plan, sqlparser.Statement, error)
// ClearPrepareData clears the prepared data from the session.
ClearPrepareData(stmtName string)
// GetPrepareData returns the prepared data for the statement from the session.
GetPrepareData(stmtName string) *vtgatepb.PrepareData
// StorePrepareData stores the prepared data in the session.
StorePrepareData(name string, v *vtgatepb.PrepareData)
}
// PlannerNameToVersion returns the numerical representation of the planner
func PlannerNameToVersion(s string) (PlannerVersion, bool) {
switch strings.ToLower(s) {
case "gen4":
return querypb.ExecuteOptions_Gen4, true
case "gen4greedy", "greedy":
return querypb.ExecuteOptions_Gen4Greedy, true
case "left2right":
return querypb.ExecuteOptions_Gen4Left2Right, true
}
return 0, false
}