vindexes

package
v2.1.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2017 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsUnique

func IsUnique(v Vindex) bool

IsUnique returns true if the Vindex is Unique.

func LoadFormal

func LoadFormal(filename string) (*vschemapb.SrvVSchema, error)

LoadFormal loads the JSON representation of VSchema from a file.

func LoadFormalKeyspace

func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error)

LoadFormalKeyspace loads the JSON representation of VSchema from a file, for a single keyspace.

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 ValidateKeyspace

func ValidateKeyspace(input *vschemapb.Keyspace) error

ValidateKeyspace ensures that the keyspace vschema is valid. External references (like sequence) are not validated.

Types

type AutoIncrement

type AutoIncrement struct {
	Column   sqlparser.ColIdent `json:"column"`
	Sequence *Table             `json:"sequence"`
	// ColumnVindexNum is the index of the ColumnVindex
	// if the column is also a ColumnVindex. Otherwise, it's -1.
	ColumnVindexNum int `json:"column_vindex_num"`
}

AutoIncrement contains the auto-inc information for a table.

type Binary

type Binary struct {
	// contains filtered or unexported fields
}

Binary is a vindex that converts binary bits to a keyspace id.

func (*Binary) Cost

func (vind *Binary) Cost() int

Cost returns the cost as 1.

func (*Binary) Map

func (vind *Binary) Map(_ VCursor, ids []interface{}) ([][]byte, error)

Map returns the corresponding keyspace id values for the given ids.

func (*Binary) ReverseMap

func (*Binary) ReverseMap(_ VCursor, ksids [][]byte) ([]interface{}, error)

ReverseMap returns the associated ids for the ksids.

func (*Binary) String

func (vind *Binary) String() string

String returns the name of the vindex.

func (*Binary) Verify

func (vind *Binary) Verify(_ VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type BinaryMD5

type BinaryMD5 struct {
	// contains filtered or unexported fields
}

BinaryMD5 is a vindex that hashes binary bits to a keyspace id.

func (*BinaryMD5) Cost

func (vind *BinaryMD5) Cost() int

Cost returns the cost as 1.

func (*BinaryMD5) Map

func (vind *BinaryMD5) Map(_ VCursor, ids []interface{}) ([][]byte, error)

Map returns the corresponding keyspace id values for the given ids.

func (*BinaryMD5) String

func (vind *BinaryMD5) String() string

String returns the name of the vindex.

func (*BinaryMD5) Verify

func (vind *BinaryMD5) Verify(_ VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type ByCost

type ByCost []*ColumnVindex

ByCost provides the interface needed for ColumnVindexes to be sorted by cost order.

func (ByCost) Len

func (bc ByCost) Len() int

func (ByCost) Less

func (bc ByCost) Less(i, j int) bool

func (ByCost) Swap

func (bc ByCost) Swap(i, j int)

type ColumnVindex

type ColumnVindex struct {
	Column sqlparser.ColIdent `json:"column"`
	Type   string             `json:"type"`
	Name   string             `json:"name"`
	Owned  bool               `json:"owned,omitempty"`
	Vindex Vindex             `json:"vindex"`
}

ColumnVindex contains the index info for each index of a table.

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) Cost

func (vind *Hash) Cost() int

Cost returns the cost of this index as 1.

func (*Hash) Map

func (vind *Hash) Map(_ VCursor, ids []interface{}) ([][]byte, error)

Map returns the corresponding KeyspaceId values for the given ids.

func (*Hash) ReverseMap

func (vind *Hash) ReverseMap(_ VCursor, ksids [][]byte) ([]interface{}, error)

ReverseMap returns the ids from ksids.

func (*Hash) String

func (vind *Hash) String() string

String returns the name of the vindex.

func (*Hash) Verify

func (vind *Hash) Verify(_ VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type Keyspace

type Keyspace struct {
	Name    string
	Sharded bool
}

Keyspace contains the keyspcae info for each Table.

type KeyspaceSchema

type KeyspaceSchema struct {
	Keyspace *Keyspace
	Tables   map[string]*Table
}

KeyspaceSchema contains the schema(table) for a keyspace.

func BuildKeyspaceSchema

func BuildKeyspaceSchema(input *vschemapb.Keyspace, keyspace string) (*KeyspaceSchema, error)

BuildKeyspaceSchema builds the vschema portion for one keyspace. The build ignores sequence references because those dependencies can go cross-keyspace.

func (*KeyspaceSchema) MarshalJSON

func (ks *KeyspaceSchema) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of KeyspaceSchema.

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{}, ksids [][]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) MarshalJSON

func (vind *LookupHash) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of LookupHash.

func (*LookupHash) String

func (vind *LookupHash) String() string

String returns the name of the vindex.

func (*LookupHash) Verify

func (vind *LookupHash) Verify(vcursor VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

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{}, ksids [][]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) MarshalJSON

func (vind *LookupHashUnique) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of LookupHashUnique.

func (*LookupHashUnique) String

func (vind *LookupHashUnique) String() string

String returns the name of the vindex.

func (*LookupHashUnique) Verify

func (vind *LookupHashUnique) Verify(vcursor VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type LookupNonUnique

type LookupNonUnique struct {
	// contains filtered or unexported fields
}

LookupNonUnique defines a vindex that uses a lookup table and create a mapping between id and KeyspaceId. It's NonUnique and a Lookup.

func (*LookupNonUnique) Cost

func (vindex *LookupNonUnique) Cost() int

Cost returns the cost of this vindex as 20.

func (*LookupNonUnique) Create

func (vindex *LookupNonUnique) Create(vcursor VCursor, id []interface{}, ksids [][]byte) error

Create reserves the id by inserting it into the vindex table.

func (*LookupNonUnique) Delete

func (vindex *LookupNonUnique) Delete(vcursor VCursor, ids []interface{}, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupNonUnique) Map

func (vindex *LookupNonUnique) Map(vcursor VCursor, ids []interface{}) ([][][]byte, error)

Map returns the corresponding KeyspaceId values for the given ids.

func (*LookupNonUnique) MarshalJSON

func (vindex *LookupNonUnique) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of LookupHash.

func (*LookupNonUnique) String

func (vindex *LookupNonUnique) String() string

String returns the name of the vindex.

func (*LookupNonUnique) Verify

func (vindex *LookupNonUnique) Verify(vcursor VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type LookupUnique

type LookupUnique struct {
	// contains filtered or unexported fields
}

LookupUnique 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 (*LookupUnique) Cost

func (vindex *LookupUnique) Cost() int

Cost returns the cost of this vindex as 10.

func (*LookupUnique) Create

func (vindex *LookupUnique) Create(vcursor VCursor, id []interface{}, ksids [][]byte) error

Create reserves the id by inserting it into the vindex table.

func (*LookupUnique) Delete

func (vindex *LookupUnique) Delete(vcursor VCursor, ids []interface{}, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupUnique) Map

func (vindex *LookupUnique) Map(vcursor VCursor, ids []interface{}) ([][]byte, error)

Map returns the corresponding KeyspaceId values for the given ids.

func (*LookupUnique) MarshalJSON

func (vindex *LookupUnique) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of LookupHashUnique.

func (*LookupUnique) String

func (vindex *LookupUnique) String() string

String returns the name of the vindex.

func (*LookupUnique) Verify

func (vindex *LookupUnique) Verify(vcursor VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type NewVindexFunc

type NewVindexFunc func(string, map[string]string) (Vindex, error)

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

type NonUnique interface {
	Map(cursor VCursor, ids []interface{}) ([][][]byte, error)
}

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) Cost

func (*Numeric) Cost() int

Cost returns the cost of this vindex as 0.

func (*Numeric) Map

func (*Numeric) Map(_ VCursor, ids []interface{}) ([][]byte, error)

Map returns the associated keyspace ids for the given ids.

func (*Numeric) ReverseMap

func (*Numeric) ReverseMap(_ VCursor, ksids [][]byte) ([]interface{}, error)

ReverseMap returns the associated ids for the ksids.

func (*Numeric) String

func (vind *Numeric) String() string

String returns the name of the vindex.

func (*Numeric) Verify

func (*Numeric) Verify(_ VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids and ksids match.

type NumericLookupTable

type NumericLookupTable map[uint64]uint64

NumericLookupTable stores the mapping of keys.

type NumericStaticMap

type NumericStaticMap struct {
	// contains filtered or unexported fields
}

NumericStaticMap is similar to vindex Numeric but first attempts a lookup via a JSON file.

func (*NumericStaticMap) Cost

func (*NumericStaticMap) Cost() int

Cost returns the cost of this vindex as 1.

func (*NumericStaticMap) Map

func (vind *NumericStaticMap) Map(_ VCursor, ids []interface{}) ([][]byte, error)

Map returns the associated keyspace ids for the given ids.

func (*NumericStaticMap) String

func (vind *NumericStaticMap) String() string

String returns the name of the vindex.

func (*NumericStaticMap) Verify

func (vind *NumericStaticMap) Verify(_ VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids and ksids match.

type Reversible

type Reversible interface {
	ReverseMap(cursor VCursor, ks [][]byte) ([]interface{}, error)
}

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                 `json:"is_sequence,omitempty"`
	Name           sqlparser.TableIdent `json:"name"`
	Keyspace       *Keyspace            `json:"-"`
	ColumnVindexes []*ColumnVindex      `json:"column_vindexes,omitempty"`
	Ordered        []*ColumnVindex      `json:"ordered,omitempty"`
	Owned          []*ColumnVindex      `json:"owned,omitempty"`
	AutoIncrement  *AutoIncrement       `json:"auto_increment,omitempty"`
}

Table represents a table in VSchema.

type UnicodeLooseMD5

type UnicodeLooseMD5 struct {
	// contains filtered or unexported fields
}

UnicodeLooseMD5 is a vindex that normalizes and hashes unicode strings to a keyspace id. It conservatively converts the string to its base characters before hashing. This is also known as UCA level 1. Ref: http://www.unicode.org/reports/tr10/#Multi_Level_Comparison. This is compatible with MySQL's utf8_unicode_ci collation.

func (*UnicodeLooseMD5) Cost

func (vind *UnicodeLooseMD5) Cost() int

Cost returns the cost as 1.

func (*UnicodeLooseMD5) Map

func (vind *UnicodeLooseMD5) Map(_ VCursor, ids []interface{}) ([][]byte, error)

Map returns the corresponding keyspace id values for the given ids.

func (*UnicodeLooseMD5) String

func (vind *UnicodeLooseMD5) String() string

String returns the name of the vindex.

func (*UnicodeLooseMD5) Verify

func (vind *UnicodeLooseMD5) Verify(_ VCursor, ids []interface{}, ksids [][]byte) (bool, error)

Verify returns true if ids maps to ksids.

type Unique

type Unique interface {
	Map(cursor VCursor, ids []interface{}) ([][]byte, error)
}

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 `json:"keyspaces"`
	// contains filtered or unexported fields
}

VSchema represents the denormalized version of SrvVSchema, used for building routing plans.

func BuildVSchema

func BuildVSchema(source *vschemapb.SrvVSchema) (vschema *VSchema, err error)

BuildVSchema builds a VSchema from a SrvVSchema.

func (*VSchema) Find

func (vschema *VSchema) Find(keyspace, tablename string) (table *Table, err error)

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 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 ids can be mapped to the keyspace ids.
	Verify(cursor VCursor, ids []interface{}, ksids [][]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

func CreateVindex(vindexType, name string, params map[string]string) (Vindex, error)

CreateVindex creates a vindex of the specified type using the supplied params. The type must have been previously registered.

func NewBinary

func NewBinary(name string, _ map[string]string) (Vindex, error)

NewBinary creates a new Binary.

func NewBinaryMD5

func NewBinaryMD5(name string, _ map[string]string) (Vindex, error)

NewBinaryMD5 creates a new BinaryMD5.

func NewHash

func NewHash(name string, m map[string]string) (Vindex, error)

NewHash creates a new Hash.

func NewLookup

func NewLookup(name string, m map[string]string) (Vindex, error)

NewLookup creates a LookupNonUnique vindex.

func NewLookupHash

func NewLookupHash(name string, m map[string]string) (Vindex, error)

NewLookupHash creates a LookupHash vindex.

func NewLookupHashUnique

func NewLookupHashUnique(name string, m map[string]string) (Vindex, error)

NewLookupHashUnique creates a LookupHashUnique vindex.

func NewLookupUnique

func NewLookupUnique(name string, m map[string]string) (Vindex, error)

NewLookupUnique creates a LookupHashUnique vindex.

func NewNumeric

func NewNumeric(name string, _ map[string]string) (Vindex, error)

NewNumeric creates a Numeric vindex.

func NewNumericStaticMap

func NewNumericStaticMap(name string, params map[string]string) (Vindex, error)

NewNumericStaticMap creates a NumericStaticMap vindex.

func NewUnicodeLooseMD5

func NewUnicodeLooseMD5(name string, _ map[string]string) (Vindex, error)

NewUnicodeLooseMD5 creates a new UnicodeLooseMD5.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL