planbuilder

package
v0.0.0-...-2166858 Latest Latest
Warning

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

Go to latest
Published: May 28, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoPlan = PlanID(iota)
	SelectUnsharded
	SelectEqual
	SelectIN
	SelectScatter
	UpdateUnsharded
	UpdateEqual
	DeleteUnsharded
	DeleteEqual
	InsertUnsharded
	InsertSharded
	NumPlans
)

Variables

This section is empty.

Functions

func IsUnique

func IsUnique(v Vindex) bool

IsUnique returns true if the Vindex is Unique.

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 schema loading.

Types

type ByCost

type ByCost []*ColVindex

ByCost provides the interface needed for ColVindexes 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 ColVindex

type ColVindex struct {
	Col    string
	Type   string
	Name   string
	Owned  bool
	Vindex Vindex
}

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

type ColVindexFormal

type ColVindexFormal struct {
	Col  string
	Name string
}

ColVindexFormal is the info for each indexed column of a table as loaded from the source.

type Functional

type Functional interface {
	Create(cursor VCursor, id interface{}) error
	Delete(cursor VCursor, id interface{}, keyspace_id key.KeyspaceId) error
	Unique
}

A Functional vindex is an index that can compute the keyspace id from the id without a lookup. This means that the creation of a functional vindex entry does not take the keyspace id as input. In general, the main reason to support creation functions for functional indexes is for auto-generating ids. 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 FunctionalGenerator

type FunctionalGenerator interface {
	Functional
	Generate(cursor VCursor) (id interface{}, err error)
}

A FunctionalGenerator vindex is a Functional vindex that can generate new ids.

type Keyspace

type Keyspace struct {
	Name    string
	Sharded bool
}

Keyspace contains the keyspcae info for each Table.

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 Lookup

type Lookup interface {
	Create(cursor VCursor, id interface{}, keyspace_id key.KeyspaceId) error
	Delete(cursor VCursor, id interface{}, keyspace_id key.KeyspaceId) 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 LookupGenerator

type LookupGenerator interface {
	Lookup
	Generate(cursor VCursor, keyspace_id key.KeyspaceId) (id interface{}, err error)
}

A LookupGenerator vindex is a Lookup that can generate new ids.

type NewVindexFunc

type NewVindexFunc func(map[string]interface{}) (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{}) ([][]key.KeyspaceId, error)
}

NonUnique defines the interface for a non-unique vindex. This means that an id can map to multiple keyspace ids.

type Plan

type Plan struct {
	ID        PlanID
	Reason    string
	Table     *Table
	Original  string
	Rewritten string
	ColVindex *ColVindex
	Values    interface{}
}

func BuildPlan

func BuildPlan(query string, schema *Schema) *Plan

func (*Plan) IsMulti

func (pln *Plan) IsMulti() bool

IsMulti returns true if the SELECT query can potentially be sent to more than one shard.

func (*Plan) MarshalJSON

func (pln *Plan) MarshalJSON() ([]byte, error)

func (*Plan) Size

func (pln *Plan) Size() int

type PlanID

type PlanID int

func PlanByName

func PlanByName(s string) (id PlanID, ok bool)

func (PlanID) MarshalJSON

func (id PlanID) MarshalJSON() ([]byte, error)

func (PlanID) String

func (id PlanID) String() string

type Reversible

type Reversible interface {
	ReverseMap(cursor VCursor, ks key.KeyspaceId) (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 Schema

type Schema struct {
	Tables map[string]*Table
}

Schema represents the denormalized version of SchemaFormal, used for building routing plans.

func BuildSchema

func BuildSchema(source *SchemaFormal) (schema *Schema, err error)

BuildSchema builds a Schema from a SchemaFormal.

func LoadSchemaJSON

func LoadSchemaJSON(filename string) (schema *Schema, err error)

LoadSchemaJSON loads the formal representation of a schema from a JSON file and returns the more usable denormalized representaion (Schema) for it.

func (*Schema) FindTable

func (schema *Schema) FindTable(tablename string) (table *Table, reason string)

FindTable returns a pointer to the Table if found. Otherwise, it returns a reason, which is equivalent to an error.

func (*Schema) String

func (s *Schema) String() string

type SchemaFormal

type SchemaFormal struct {
	Keyspaces map[string]KeyspaceFormal
}

SchemaFormal is the formal representation of the schema as loaded from the source.

type Table

type Table struct {
	Name        string
	Keyspace    *Keyspace
	ColVindexes []*ColVindex
	Ordered     []*ColVindex
}

Table represnts a table in Schema.

type TableFormal

type TableFormal struct {
	ColVindexes []ColVindexFormal
}

TableFormal is the info for each table as loaded from the source.

type Unique

type Unique interface {
	Map(cursor VCursor, ids []interface{}) ([]key.KeyspaceId, 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 *tproto.BoundQuery) (*mproto.QueryResult, 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 Vindex

type Vindex interface {
	// 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 key.KeyspaceId) (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.

type VindexFormal

type VindexFormal struct {
	Type   string
	Params map[string]interface{}
	Owner  string
}

VindexFormal is the info for each index as loaded from the source.

Jump to

Keyboard shortcuts

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