vindexes

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeSequence  = "sequence"
	TypeReference = "reference"
)

The following constants represent table types.

Variables

View Source
var TabletTypeSuffix = map[topodatapb.TabletType]string{
	0: "@unknown",
	1: "@master",
	2: "@replica",
	3: "@rdonly",
	4: "@spare",
	5: "@experimental",
	6: "@backup",
	7: "@restore",
	8: "@drained",
}

TabletTypeSuffix maps the tablet type to its suffix string.

Functions

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"`
}

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

func (vind *Binary) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*Binary) IsUnique

func (vind *Binary) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*Binary) Map

func (vind *Binary) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*Binary) ReverseMap

func (*Binary) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, 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 []sqltypes.Value, 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) IsFunctional

func (vind *BinaryMD5) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*BinaryMD5) IsUnique

func (vind *BinaryMD5) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*BinaryMD5) Map

func (vind *BinaryMD5) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*BinaryMD5) String

func (vind *BinaryMD5) String() string

String returns the name of the vindex.

func (*BinaryMD5) Verify

func (vind *BinaryMD5) Verify(_ VCursor, ids []sqltypes.Value, 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 Column

type Column struct {
	Name sqlparser.ColIdent `json:"name"`
	Type querypb.Type       `json:"type"`
}

Column describes a column.

func (*Column) MarshalJSON

func (col *Column) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of Column.

type ColumnVindex

type ColumnVindex struct {
	Columns []sqlparser.ColIdent `json:"columns"`
	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.

func FindVindexForSharding added in v1.5.0

func FindVindexForSharding(tableName string, colVindexes []*ColumnVindex) (*ColumnVindex, error)

FindVindexForSharding searches through the given slice to find the lowest cost unique vindex primary vindex is always unique if two have the same cost, use the one that occurs earlier in the definition if the final result is too expensive, return nil

type ConsistentLookup added in v1.7.0

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

ConsistentLookup is a non-unique lookup vindex that can stay consistent with respect to its owner table.

func (*ConsistentLookup) Cost added in v1.7.0

func (lu *ConsistentLookup) Cost() int

Cost returns the cost of this vindex as 20.

func (ConsistentLookup) Create added in v1.7.0

func (lu ConsistentLookup) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (ConsistentLookup) Delete added in v1.7.0

func (lu ConsistentLookup) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (ConsistentLookup) IsFunctional added in v1.7.0

func (lu ConsistentLookup) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*ConsistentLookup) IsUnique added in v1.7.0

func (lu *ConsistentLookup) IsUnique() bool

IsUnique returns false since the Vindex is non unique.

func (*ConsistentLookup) Map added in v1.7.0

func (lu *ConsistentLookup) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (ConsistentLookup) MarshalJSON added in v1.7.0

func (lu ConsistentLookup) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of clCommon.

func (ConsistentLookup) SetOwnerInfo added in v1.7.0

func (lu ConsistentLookup) SetOwnerInfo(keyspace, table string, cols []sqlparser.ColIdent) error

func (ConsistentLookup) String added in v1.7.0

func (lu ConsistentLookup) String() string

String returns the name of the vindex.

func (ConsistentLookup) Update added in v1.7.0

func (lu ConsistentLookup) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (ConsistentLookup) Verify added in v1.7.0

func (lu ConsistentLookup) Verify(vcursor VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

type ConsistentLookupUnique added in v1.7.0

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

ConsistentLookupUnique 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 (*ConsistentLookupUnique) Cost added in v1.7.0

func (lu *ConsistentLookupUnique) Cost() int

Cost returns the cost of this vindex as 10.

func (ConsistentLookupUnique) Create added in v1.7.0

func (lu ConsistentLookupUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (ConsistentLookupUnique) Delete added in v1.7.0

func (lu ConsistentLookupUnique) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (ConsistentLookupUnique) IsFunctional added in v1.7.0

func (lu ConsistentLookupUnique) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*ConsistentLookupUnique) IsUnique added in v1.7.0

func (lu *ConsistentLookupUnique) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*ConsistentLookupUnique) Map added in v1.7.0

func (lu *ConsistentLookupUnique) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (ConsistentLookupUnique) MarshalJSON added in v1.7.0

func (lu ConsistentLookupUnique) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of clCommon.

func (ConsistentLookupUnique) SetOwnerInfo added in v1.7.0

func (lu ConsistentLookupUnique) SetOwnerInfo(keyspace, table string, cols []sqlparser.ColIdent) error

func (ConsistentLookupUnique) String added in v1.7.0

func (lu ConsistentLookupUnique) String() string

String returns the name of the vindex.

func (ConsistentLookupUnique) Update added in v1.7.0

func (lu ConsistentLookupUnique) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (ConsistentLookupUnique) Verify added in v1.7.0

func (lu ConsistentLookupUnique) Verify(vcursor VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

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

func (vind *Hash) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*Hash) IsUnique

func (vind *Hash) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*Hash) Map

func (vind *Hash) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*Hash) ReverseMap

func (vind *Hash) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, 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 []sqltypes.Value, 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
	Vindexes map[string]Vindex
	Error    error
}

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 creates an association between ids and ksids. If ignoreMode
	// is true, then the Create should ignore dup key errors.
	Create(vc VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

	Delete(vc VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

	// Update replaces the mapping of old values with new values for a keyspace id.
	Update(vc VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) 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. Warning: This Vindex is being depcreated in favor of Lookup

func (*LookupHash) Cost

func (lh *LookupHash) Cost() int

Cost returns the cost of this vindex as 20.

func (*LookupHash) Create

func (lh *LookupHash) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (*LookupHash) Delete

func (lh *LookupHash) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupHash) IsFunctional

func (lh *LookupHash) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*LookupHash) IsUnique

func (lh *LookupHash) IsUnique() bool

IsUnique returns false since the Vindex is not unique.

func (*LookupHash) Map

func (lh *LookupHash) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*LookupHash) MarshalJSON

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

MarshalJSON returns a JSON representation of LookupHash.

func (*LookupHash) String

func (lh *LookupHash) String() string

String returns the name of the vindex.

func (*LookupHash) Update

func (lh *LookupHash) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (*LookupHash) Verify

func (lh *LookupHash) Verify(vcursor VCursor, ids []sqltypes.Value, 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. Warning: This Vindex is being depcreated in favor of LookupUnique

func (*LookupHashUnique) Cost

func (lhu *LookupHashUnique) Cost() int

Cost returns the cost of this vindex as 10.

func (*LookupHashUnique) Create

func (lhu *LookupHashUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (*LookupHashUnique) Delete

func (lhu *LookupHashUnique) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupHashUnique) IsFunctional

func (lhu *LookupHashUnique) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*LookupHashUnique) IsUnique

func (lhu *LookupHashUnique) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*LookupHashUnique) Map

func (lhu *LookupHashUnique) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*LookupHashUnique) MarshalJSON

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

MarshalJSON returns a JSON representation of LookupHashUnique.

func (*LookupHashUnique) String

func (lhu *LookupHashUnique) String() string

String returns the name of the vindex.

func (*LookupHashUnique) Update

func (lhu *LookupHashUnique) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (*LookupHashUnique) Verify

func (lhu *LookupHashUnique) Verify(vcursor VCursor, ids []sqltypes.Value, 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 from ids and KeyspaceId. It's NonUnique and a Lookup.

func (*LookupNonUnique) Cost

func (ln *LookupNonUnique) Cost() int

Cost returns the cost of this vindex as 20.

func (*LookupNonUnique) Create

func (ln *LookupNonUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (*LookupNonUnique) Delete

func (ln *LookupNonUnique) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupNonUnique) IsFunctional

func (ln *LookupNonUnique) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*LookupNonUnique) IsUnique

func (ln *LookupNonUnique) IsUnique() bool

IsUnique returns false since the Vindex is non unique.

func (*LookupNonUnique) Map

func (ln *LookupNonUnique) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*LookupNonUnique) MarshalJSON

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

MarshalJSON returns a JSON representation of LookupHash.

func (*LookupNonUnique) String

func (ln *LookupNonUnique) String() string

String returns the name of the vindex.

func (*LookupNonUnique) Update

func (ln *LookupNonUnique) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (*LookupNonUnique) Verify

func (ln *LookupNonUnique) Verify(vcursor VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

type LookupUnicodeLooseMD5Hash added in v1.4.0

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

LookupUnicodeLooseMD5Hash 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 and stores the from value in a hashed form. Warning: This Vindex is being depcreated in favor of Lookup

func (*LookupUnicodeLooseMD5Hash) Cost added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) Cost() int

Cost returns the cost of this vindex as 20.

func (*LookupUnicodeLooseMD5Hash) Create added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (*LookupUnicodeLooseMD5Hash) Delete added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupUnicodeLooseMD5Hash) IsFunctional added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*LookupUnicodeLooseMD5Hash) IsUnique added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) IsUnique() bool

IsUnique returns false since the Vindex is not unique.

func (*LookupUnicodeLooseMD5Hash) Map added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*LookupUnicodeLooseMD5Hash) MarshalJSON added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of LookupHash.

func (*LookupUnicodeLooseMD5Hash) String added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) String() string

String returns the name of the vindex.

func (*LookupUnicodeLooseMD5Hash) Update added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (*LookupUnicodeLooseMD5Hash) Verify added in v1.4.0

func (lh *LookupUnicodeLooseMD5Hash) Verify(vcursor VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

type LookupUnicodeLooseMD5HashUnique added in v1.4.0

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

LookupUnicodeLooseMD5HashUnique 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 and will store the from value in a hashed format. Warning: This Vindex is being depcreated in favor of LookupUnique

func (*LookupUnicodeLooseMD5HashUnique) Cost added in v1.4.0

Cost returns the cost of this vindex as 10.

func (*LookupUnicodeLooseMD5HashUnique) Create added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (*LookupUnicodeLooseMD5HashUnique) Delete added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupUnicodeLooseMD5HashUnique) IsFunctional added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*LookupUnicodeLooseMD5HashUnique) IsUnique added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*LookupUnicodeLooseMD5HashUnique) Map added in v1.4.0

Map can map ids to key.Destination objects.

func (*LookupUnicodeLooseMD5HashUnique) MarshalJSON added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of LookupHashUnique.

func (*LookupUnicodeLooseMD5HashUnique) String added in v1.4.0

String returns the name of the vindex.

func (*LookupUnicodeLooseMD5HashUnique) Update added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (*LookupUnicodeLooseMD5HashUnique) Verify added in v1.4.0

func (lhu *LookupUnicodeLooseMD5HashUnique) Verify(vcursor VCursor, ids []sqltypes.Value, 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 (lu *LookupUnique) Cost() int

Cost returns the cost of this vindex as 10.

func (*LookupUnique) Create

func (lu *LookupUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error

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

func (*LookupUnique) Delete

func (lu *LookupUnique) Delete(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksid []byte) error

Delete deletes the entry from the vindex table.

func (*LookupUnique) IsFunctional

func (lu *LookupUnique) IsFunctional() bool

IsFunctional returns false since the Vindex is not functional.

func (*LookupUnique) IsUnique

func (lu *LookupUnique) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*LookupUnique) Map

func (lu *LookupUnique) Map(vcursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*LookupUnique) MarshalJSON

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

MarshalJSON returns a JSON representation of LookupUnique.

func (*LookupUnique) String

func (lu *LookupUnique) String() string

String returns the name of the vindex.

func (*LookupUnique) Update

func (lu *LookupUnique) Update(vcursor VCursor, oldValues []sqltypes.Value, ksid []byte, newValues []sqltypes.Value) error

Update updates the entry in the vindex table.

func (*LookupUnique) Verify

func (lu *LookupUnique) Verify(vcursor VCursor, ids []sqltypes.Value, 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 Null

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

Null defines a vindex that always return 0. It's Unique and Functional. This is useful for rows that always go into the first shard. This Vindex can be used for validating an unsharded->sharded transition. Unlike other vindexes, this one will work even for NULL input values. This will allow you to keep MySQL auto-inc columns unchanged.

func (*Null) Cost

func (vind *Null) Cost() int

Cost returns the cost of this index as 0.

func (*Null) IsFunctional

func (vind *Null) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*Null) IsUnique

func (vind *Null) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*Null) Map

func (vind *Null) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*Null) String

func (vind *Null) String() string

String returns the name of the vindex.

func (*Null) Verify

func (vind *Null) Verify(cursor VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

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

func (*Numeric) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*Numeric) IsUnique

func (*Numeric) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*Numeric) Map

func (*Numeric) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*Numeric) ReverseMap

func (*Numeric) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, 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 []sqltypes.Value, 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) IsFunctional

func (vind *NumericStaticMap) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*NumericStaticMap) IsUnique

func (vind *NumericStaticMap) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*NumericStaticMap) Map

func (vind *NumericStaticMap) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*NumericStaticMap) String

func (vind *NumericStaticMap) String() string

String returns the name of the vindex.

func (*NumericStaticMap) Verify

func (vind *NumericStaticMap) Verify(_ VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids and ksids match.

type ReverseBits

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

ReverseBits defines vindex that reverses the bits of a number. It's Unique, Reversible and Functional.

func (*ReverseBits) Cost

func (vind *ReverseBits) Cost() int

Cost returns the cost of this index as 1.

func (*ReverseBits) IsFunctional

func (vind *ReverseBits) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*ReverseBits) IsUnique

func (vind *ReverseBits) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*ReverseBits) Map

func (vind *ReverseBits) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map returns the corresponding KeyspaceId values for the given ids.

func (*ReverseBits) ReverseMap

func (vind *ReverseBits) ReverseMap(_ VCursor, ksids [][]byte) ([]sqltypes.Value, error)

ReverseMap returns the ids from ksids.

func (*ReverseBits) String

func (vind *ReverseBits) String() string

String returns the name of the vindex.

func (*ReverseBits) Verify

func (vind *ReverseBits) Verify(_ VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

type Reversible

type Reversible interface {
	ReverseMap(cursor VCursor, ks [][]byte) ([]sqltypes.Value, 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 RoutingRule added in v1.7.0

type RoutingRule struct {
	Tables []*Table
	Error  error
}

RoutingRule represents one routing rule.

func (*RoutingRule) MarshalJSON added in v1.7.0

func (rr *RoutingRule) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of Column.

type Table

type Table struct {
	Type                    string               `json:"type,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"`
	Columns                 []Column             `json:"columns,omitempty"`
	Pinned                  []byte               `json:"pinned,omitempty"`
	ColumnListAuthoritative bool                 `json:"column_list_authoritative,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) IsFunctional

func (vind *UnicodeLooseMD5) IsFunctional() bool

IsFunctional returns true since the Vindex is functional.

func (*UnicodeLooseMD5) IsUnique

func (vind *UnicodeLooseMD5) IsUnique() bool

IsUnique returns true since the Vindex is unique.

func (*UnicodeLooseMD5) Map

func (vind *UnicodeLooseMD5) Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)

Map can map ids to key.Destination objects.

func (*UnicodeLooseMD5) String

func (vind *UnicodeLooseMD5) String() string

String returns the name of the vindex.

func (*UnicodeLooseMD5) Verify

func (vind *UnicodeLooseMD5) Verify(_ VCursor, ids []sqltypes.Value, ksids [][]byte) ([]bool, error)

Verify returns true if ids maps to ksids.

type VCursor

type VCursor interface {
	Execute(method string, query string, bindvars map[string]*querypb.BindVariable, isDML bool, co vtgatepb.CommitOrder) (*sqltypes.Result, error)
	ExecuteKeyspaceID(keyspace string, ksid []byte, query string, bindVars map[string]*querypb.BindVariable, isDML, autocommit bool) (*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 {
	RoutingRules map[string]*RoutingRule `json:"routing_rules"`

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

func (vschema *VSchema) FindTable(keyspace, tablename string) (*Table, error)

FindTable 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: FindTable 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. FindTable bypasses routing rules and returns at most one table.

func (*VSchema) FindTablesOrVindex added in v1.7.0

func (vschema *VSchema) FindTablesOrVindex(keyspace, name string, tabletType topodatapb.TabletType) ([]*Table, Vindex, error)

FindTablesOrVindex finds a table or a Vindex by name using Find and FindVindex.

func (*VSchema) FindVindex

func (vschema *VSchema) FindVindex(keyspace, name string) (Vindex, error)

FindVindex finds a vindex by name. If a keyspace is specified, only vindexes from that keyspace are searched. If no kesypace is specified, then a vindex is returned only if its name is unique across all keyspaces. The function returns an error only if the vindex name is ambiguous.

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

	// IsUnique returns true if the Vindex is unique.
	// Which means Map() maps to either a KeyRange or a single KeyspaceID.
	IsUnique() bool

	// IsFunctional returns true if the Vindex can compute
	// the keyspace id from the id without a lookup.
	// A Functional vindex is also required to be Unique.
	// Which means Map() maps to either a KeyRange or a single KeyspaceID.
	IsFunctional() bool

	// 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 []sqltypes.Value, ksids [][]byte) ([]bool, error)

	// Map can map ids to key.Destination objects.
	// If the Vindex is unique, each id would map to either
	// a KeyRange, or a single KeyspaceID.
	// If the Vindex is non-unique, each id would map to either
	// a KeyRange, or a list of KeyspaceID.
	// If the error returned if nil, then the array len of the
	// key.Destination array must match len(ids).
	Map(cursor VCursor, ids []sqltypes.Value) ([]key.Destination, error)
}

Vindex defines the interface required to register a vindex.

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 NewConsistentLookup added in v1.7.0

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

NewConsistentLookup creates a ConsistentLookup vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

func NewConsistentLookupUnique added in v1.7.0

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

NewConsistentLookupUnique creates a ConsistentLookupUnique vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

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. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

The following fields are optional:

autocommit: setting this to "true" will cause inserts to upsert and deletes to be ignored.
write_only: in this mode, Map functions return the full keyrange causing a full scatter.

func NewLookupHash

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

NewLookupHash creates a LookupHash vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

The following fields are optional:

autocommit: setting this to "true" will cause inserts to upsert and deletes to be ignored.
write_only: in this mode, Map functions return the full keyrange causing a full scatter.

func NewLookupHashUnique

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

NewLookupHashUnique creates a LookupHashUnique vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

The following fields are optional:

autocommit: setting this to "true" will cause deletes to be ignored.
write_only: in this mode, Map functions return the full keyrange causing a full scatter.

func NewLookupUnicodeLooseMD5Hash added in v1.4.0

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

NewLookupUnicodeLooseMD5Hash creates a LookupUnicodeLooseMD5Hash vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

The following fields are optional:

autocommit: setting this to "true" will cause inserts to upsert and deletes to be ignored.
write_only: in this mode, Map functions return the full keyrange causing a full scatter.

func NewLookupUnicodeLooseMD5HashUnique added in v1.4.0

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

NewLookupUnicodeLooseMD5HashUnique creates a LookupUnicodeLooseMD5HashUnique vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

The following fields are optional:

autocommit: setting this to "true" will cause deletes to be ignored.
write_only: in this mode, Map functions return the full keyrange causing a full scatter.

func NewLookupUnique

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

NewLookupUnique creates a LookupUnique vindex. The supplied map has the following required fields:

table: name of the backing table. It can be qualified by the keyspace.
from: list of columns in the table that have the 'from' values of the lookup vindex.
to: The 'to' column name of the table.

The following fields are optional:

autocommit: setting this to "true" will cause deletes to be ignored.
write_only: in this mode, Map functions return the full keyrange causing a full scatter.

func NewNull

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

NewNull creates a new Null.

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 NewReverseBits

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

NewReverseBits creates a new ReverseBits.

func NewUnicodeLooseMD5

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

NewUnicodeLooseMD5 creates a new UnicodeLooseMD5.

type WantOwnerInfo added in v1.7.0

type WantOwnerInfo interface {
	SetOwnerInfo(keyspace, table string, cols []sqlparser.ColIdent) error
}

WantOwnerInfo defines the interface that a vindex must satisfy to request info about the owner table. This information can be used to query the owner's table for the owning row's presence.

Jump to

Keyboard shortcuts

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