vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/plancontext/vschema.go (about)

     1  package plancontext
     2  
     3  import (
     4  	"strings"
     5  
     6  	"vitess.io/vitess/go/vt/log"
     7  	vschemapb "vitess.io/vitess/go/vt/proto/vschema"
     8  
     9  	"vitess.io/vitess/go/mysql/collations"
    10  	"vitess.io/vitess/go/vt/key"
    11  	querypb "vitess.io/vitess/go/vt/proto/query"
    12  	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
    13  	"vitess.io/vitess/go/vt/sqlparser"
    14  	"vitess.io/vitess/go/vt/vtgate/semantics"
    15  	"vitess.io/vitess/go/vt/vtgate/vindexes"
    16  )
    17  
    18  // PlannerVersion is an alias here to make the code more readable
    19  type PlannerVersion = querypb.ExecuteOptions_PlannerVersion
    20  
    21  // VSchema defines the interface for this package to fetch
    22  // info about tables.
    23  type VSchema interface {
    24  	FindTable(tablename sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error)
    25  	FindView(name sqlparser.TableName) sqlparser.SelectStatement
    26  	FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error)
    27  	DefaultKeyspace() (*vindexes.Keyspace, error)
    28  	TargetString() string
    29  	Destination() key.Destination
    30  	TabletType() topodatapb.TabletType
    31  	TargetDestination(qualifier string) (key.Destination, *vindexes.Keyspace, topodatapb.TabletType, error)
    32  	AnyKeyspace() (*vindexes.Keyspace, error)
    33  	FirstSortedKeyspace() (*vindexes.Keyspace, error)
    34  	SysVarSetEnabled() bool
    35  	KeyspaceExists(keyspace string) bool
    36  	AllKeyspace() ([]*vindexes.Keyspace, error)
    37  	FindKeyspace(keyspace string) (*vindexes.Keyspace, error)
    38  	GetSemTable() *semantics.SemTable
    39  	Planner() PlannerVersion
    40  	SetPlannerVersion(pv PlannerVersion)
    41  	ConnCollation() collations.ID
    42  
    43  	// ErrorIfShardedF will return an error if the keyspace is sharded,
    44  	// and produce a warning if the vtgate if configured to do so
    45  	ErrorIfShardedF(keyspace *vindexes.Keyspace, warn, errFmt string, params ...any) error
    46  
    47  	// WarnUnshardedOnly is used when a feature is only supported in unsharded mode.
    48  	// This will let the user know that they are using something
    49  	// that could become a problem if they move to a sharded keyspace
    50  	WarnUnshardedOnly(format string, params ...any)
    51  
    52  	// PlannerWarning records warning created during planning.
    53  	PlannerWarning(message string)
    54  
    55  	// ForeignKeyMode returns the foreign_key flag value
    56  	ForeignKeyMode() string
    57  
    58  	// GetVSchema returns the latest cached vindexes.VSchema
    59  	GetVSchema() *vindexes.VSchema
    60  
    61  	// GetSrvVschema returns the latest cached vschema.SrvVSchema
    62  	GetSrvVschema() *vschemapb.SrvVSchema
    63  	// FindRoutedShard looks up shard routing rules for a shard
    64  	FindRoutedShard(keyspace, shard string) (string, error)
    65  
    66  	// IsShardRoutingEnabled returns true if partial shard routing is enabled
    67  	IsShardRoutingEnabled() bool
    68  
    69  	// IsViewsEnabled returns true if Vitess manages the views.
    70  	IsViewsEnabled() bool
    71  }
    72  
    73  // PlannerNameToVersion returns the numerical representation of the planner
    74  func PlannerNameToVersion(s string) (PlannerVersion, bool) {
    75  	deprecationMessage := "The V3 planner is deprecated and will be removed in V17 of Vitess"
    76  	switch strings.ToLower(s) {
    77  	case "v3":
    78  		log.Warning(deprecationMessage)
    79  		return querypb.ExecuteOptions_V3, true
    80  	case "gen4":
    81  		return querypb.ExecuteOptions_Gen4, true
    82  	case "gen4greedy", "greedy":
    83  		return querypb.ExecuteOptions_Gen4Greedy, true
    84  	case "left2right":
    85  		return querypb.ExecuteOptions_Gen4Left2Right, true
    86  	case "gen4fallback":
    87  		return querypb.ExecuteOptions_Gen4WithFallback, true
    88  	case "gen4comparev3":
    89  		log.Warning(deprecationMessage)
    90  		return querypb.ExecuteOptions_Gen4CompareV3, true
    91  	}
    92  	return 0, false
    93  }