Documentation ¶
Index ¶
- func IsUnique(v Vindex) bool
- func Register(vindexType string, newVindexFunc NewVindexFunc)
- func ValidateVSchema(input []byte) error
- type Autoinc
- type AutoincFormal
- type ByCost
- type ColVindex
- type ColVindexFormal
- type Functional
- type Hash
- type Keyspace
- type KeyspaceFormal
- type KeyspaceSchema
- type Lookup
- type LookupHash
- func (vind *LookupHash) Cost() int
- func (vind *LookupHash) Create(vcursor VCursor, id interface{}, ksid []byte) error
- func (vind *LookupHash) Delete(vcursor VCursor, ids []interface{}, ksid []byte) error
- func (vind *LookupHash) Map(vcursor VCursor, ids []interface{}) ([][][]byte, error)
- func (vind *LookupHash) String() string
- func (vind *LookupHash) Verify(vcursor VCursor, id interface{}, ksid []byte) (bool, error)
- type LookupHashUnique
- func (vind *LookupHashUnique) Cost() int
- func (vind *LookupHashUnique) Create(vcursor VCursor, id interface{}, ksid []byte) error
- func (vind *LookupHashUnique) Delete(vcursor VCursor, ids []interface{}, ksid []byte) error
- func (vind *LookupHashUnique) Map(vcursor VCursor, ids []interface{}) ([][]byte, error)
- func (vind *LookupHashUnique) String() string
- func (vind *LookupHashUnique) Verify(vcursor VCursor, id interface{}, ksid []byte) (bool, error)
- type NewVindexFunc
- type NonUnique
- type Numeric
- type Reversible
- type Table
- type TableFormal
- type Unique
- type VCursor
- type VSchema
- type VSchemaFormal
- type Vindex
- func CreateVindex(vindexType, name string, params map[string]interface{}) (Vindex, error)
- func NewHash(name string, m map[string]interface{}) (Vindex, error)
- func NewLookupHash(name string, m map[string]interface{}) (Vindex, error)
- func NewLookupHashUnique(name string, m map[string]interface{}) (Vindex, error)
- func NewNumeric(name string, _ map[string]interface{}) (Vindex, error)
- type VindexFormal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(vindexType string, newVindexFunc NewVindexFunc)
Register registers a vindex under the specified vindexType. A duplicate vindexType will generate a panic. New vindexes will be created using these functions at the time of vschema loading.
func ValidateVSchema ¶
ValidateVSchema ensures that the the JSON representation of the keyspace vschema are valid. External references (like sequence) are not validated.
Types ¶
type Autoinc ¶
type Autoinc struct { Col string Sequence *Table // ColVindexNum is the index of the ColVindex // if the column is also a ColVindex. Otherwise, it's -1. ColVindexNum int }
Autoinc contains the auto-inc information for a table.
type AutoincFormal ¶
AutoincFormal represents the JSON format for auto-inc.
type ByCost ¶
type ByCost []*ColVindex
ByCost provides the interface needed for ColVindexes to be sorted by cost order.
type ColVindexFormal ¶
ColVindexFormal is the info for each indexed column of a table as loaded from the source.
type Functional ¶
type Functional interface { Unique }
A Functional vindex is an index that can compute the keyspace id from the id without a lookup. A Functional vindex is also required to be Unique. If it's not unique, we cannot determine the target shard for an insert operation.
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash defines vindex that hashes an int64 to a KeyspaceId by using null-key 3DES hash. It's Unique, Reversible and Functional.
func (*Hash) ReverseMap ¶
ReverseMap returns the id from ksid.
type KeyspaceFormal ¶
type KeyspaceFormal struct { Sharded bool Vindexes map[string]VindexFormal Tables map[string]TableFormal }
KeyspaceFormal is the keyspace info for each keyspace as loaded from the source.
type KeyspaceSchema ¶
KeyspaceSchema contains the schema(table) for a keyspace.
type Lookup ¶
type Lookup interface { Create(VCursor, interface{}, []byte) error Delete(VCursor, []interface{}, []byte) error }
A Lookup vindex is one that needs to lookup a previously stored map to compute the keyspace id from an id. This means that the creation of a lookup vindex entry requires a keyspace id as input. A Lookup vindex need not be unique because the keyspace_id, which must be supplied, can be used to determine the target shard for an insert operation.
type LookupHash ¶
type LookupHash struct {
// contains filtered or unexported fields
}
LookupHash defines a vindex that uses a lookup table. The table is expected to define the id column as unique. It's NonUnique and a Lookup.
func (*LookupHash) Cost ¶
func (vind *LookupHash) Cost() int
Cost returns the cost of this vindex as 20.
func (*LookupHash) Create ¶
func (vind *LookupHash) Create(vcursor VCursor, id interface{}, ksid []byte) error
Create reserves the id by inserting it into the vindex table.
func (*LookupHash) Delete ¶
func (vind *LookupHash) Delete(vcursor VCursor, ids []interface{}, ksid []byte) error
Delete deletes the entry from the vindex table.
func (*LookupHash) Map ¶
func (vind *LookupHash) Map(vcursor VCursor, ids []interface{}) ([][][]byte, error)
Map returns the corresponding KeyspaceId values for the given ids.
func (*LookupHash) String ¶
func (vind *LookupHash) String() string
String returns the name of the vindex.
type LookupHashUnique ¶
type LookupHashUnique struct {
// contains filtered or unexported fields
}
LookupHashUnique defines a vindex that uses a lookup table. The table is expected to define the id column as unique. It's Unique and a Lookup.
func (*LookupHashUnique) Cost ¶
func (vind *LookupHashUnique) Cost() int
Cost returns the cost of this vindex as 10.
func (*LookupHashUnique) Create ¶
func (vind *LookupHashUnique) Create(vcursor VCursor, id interface{}, ksid []byte) error
Create reserves the id by inserting it into the vindex table.
func (*LookupHashUnique) Delete ¶
func (vind *LookupHashUnique) Delete(vcursor VCursor, ids []interface{}, ksid []byte) error
Delete deletes the entry from the vindex table.
func (*LookupHashUnique) Map ¶
func (vind *LookupHashUnique) Map(vcursor VCursor, ids []interface{}) ([][]byte, error)
Map returns the corresponding KeyspaceId values for the given ids.
func (*LookupHashUnique) String ¶
func (vind *LookupHashUnique) String() string
String returns the name of the vindex.
type NewVindexFunc ¶
A NewVindexFunc is a function that creates a Vindex based on the properties specified in the input map. Every vindex must register a NewVindexFunc under a unique vindexType.
type NonUnique ¶
NonUnique defines the interface for a non-unique vindex. This means that an id can map to multiple keyspace ids.
type Numeric ¶
type Numeric struct {
// contains filtered or unexported fields
}
Numeric defines a bit-pattern mapping of a uint64 to the KeyspaceId. It's Unique and Reversible.
func (*Numeric) ReverseMap ¶
ReverseMap returns the associated id for the ksid.
type Reversible ¶
A Reversible vindex is one that can perform a reverse lookup from a keyspace id to an id. This is optional. If present, VTGate can use it to fill column values based on the target keyspace id.
type Table ¶
type Table struct { IsSequence bool Name string Keyspace *Keyspace ColVindexes []*ColVindex Ordered []*ColVindex Owned []*ColVindex Autoinc *Autoinc }
Table represents a table in VSchema.
type TableFormal ¶
type TableFormal struct { Type string ColVindexes []ColVindexFormal Autoinc *AutoincFormal }
TableFormal is the info for each table as loaded from the source.
type Unique ¶
Unique defines the interface for a unique vindex. For a vindex to be unique, an id has to map to at most one keyspace id.
type VCursor ¶
type VCursor interface {
Execute(query string, bindvars map[string]interface{}) (*sqltypes.Result, error)
}
A VCursor is an interface that allows you to execute queries in the current context and session of a VTGate request. Vindexes can use this interface to execute lookup queries.
type VSchema ¶
type VSchema struct { Keyspaces map[string]*KeyspaceSchema // contains filtered or unexported fields }
VSchema represents the denormalized version of VSchemaFormal, used for building routing plans.
func BuildVSchema ¶
func BuildVSchema(source *VSchemaFormal) (vschema *VSchema, err error)
BuildVSchema builds a VSchema from a VSchemaFormal.
func (*VSchema) Find ¶
Find returns a pointer to the Table. If a keyspace is specified, only tables from that keyspace are searched. If the specified keyspace is unsharded and no tables matched, it's considered valid: Find will construct a table of that name and return it. If no kesypace is specified, then a table is returned only if its name is unique across all keyspaces. If there is only one keyspace in the vschema, and it's unsharded, then all table requests are considered valid and belonging to that keyspace.
type VSchemaFormal ¶
type VSchemaFormal struct {
Keyspaces map[string]KeyspaceFormal
}
VSchemaFormal is the formal representation of the vschema as loaded from the source.
func LoadFormal ¶
func LoadFormal(filename string) (*VSchemaFormal, error)
LoadFormal loads the JSON representation of VSchema from a file.
func VSchemaFormalForKeyspace ¶
func VSchemaFormalForKeyspace(input []byte, name string) (*VSchemaFormal, error)
VSchemaFormalForKeyspace returns a VSchemaFormal for the single keyspace based on the JSON input.
type Vindex ¶
type Vindex interface { // String returns the name of the Vindex instance. // It's used for testing and diagnostics. Use pointer // comparison to see if two objects refer to the same // Vindex. String() string // Cost is used by planbuilder to prioritize vindexes. // The cost can be 0 if the id is basically a keyspace id. // The cost can be 1 if the id can be hashed to a keyspace id. // The cost can be 2 or above if the id needs to be looked up // from an external data source. These guidelines are subject // to change in the future. Cost() int // Verify must be implented by all vindexes. It should return // true if the id can be mapped to the keyspace id. Verify(cursor VCursor, id interface{}, ks []byte) (bool, error) }
Vindex defines the interface required to register a vindex. Additional to these functions, a vindex also needs to satisfy the Unique or NonUnique interface.
func CreateVindex ¶
CreateVindex creates a vindex of the specified type using the supplied params. The type must have been previously registered.
func NewLookupHash ¶
NewLookupHash creates a LookupHash vindex.
func NewLookupHashUnique ¶
NewLookupHashUnique creates a LookupHashUnique vindex.
type VindexFormal ¶
VindexFormal is the info for each index as loaded from the source.