sql

package
Version: v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: Apache-2.0 Imports: 20 Imported by: 26

Documentation

Index

Constants

View Source
const (
	// InformationSchemaDatabaseName is the name of the information schema database.
	InformationSchemaDatabaseName = "information_schema"
	// FilesTableName is the name of the files table.
	FilesTableName = "files"
	// ColumnStatisticsTableName is the name of the column statistics table.
	ColumnStatisticsTableName = "column_statistics"
	// TablesTableName is the name of tables table.
	TablesTableName = "tables"
	// ColumnsTableName is the name of columns table.
	ColumnsTableName = "columns"
	// SchemataTableName is the name of the schemata table.
	SchemataTableName = "schemata"
)
View Source
const ChecksumKey = "checksum"

ChecksumKey is the key in an index config to store the checksum.

View Source
const DateLayout = "2006-01-02"

DateLayout is the layout of the MySQL date format in the representation Go understands.

View Source
const IndexBatchSize = uint64(10000)

IndexBatchSize is the number of rows to save at a time when creating indexes.

View Source
const (
	// QueryKey to access query in the context.
	QueryKey key = iota
)
View Source
const TimestampLayout = "2006-01-02 15:04:05"

TimestampLayout is the formatting string with the layout of the timestamp using the format of Go "time" package.

Variables

View Source
var (
	// ErrInvalidType is thrown when there is an unexpected type at some part of
	// the execution tree.
	ErrInvalidType = errors.NewKind("invalid type: %s")

	// ErrTableAlreadyExists is thrown when someone tries to create a
	// table with a name of an existing one
	ErrTableAlreadyExists = errors.NewKind("table with name %s already exists")

	// ErrTableNotFound is returned when the table is not available from the
	// current scope.
	ErrTableNotFound = errors.NewKind("table not found: %s")

	//ErrUnexpectedRowLength is thrown when the obtained row has more columns than the schema
	ErrUnexpectedRowLength = errors.NewKind("expected %d values, got %d")
)
View Source
var (
	// ErrIndexIDAlreadyRegistered is the error returned when there is already
	// an index with the same ID.
	ErrIndexIDAlreadyRegistered = errors.NewKind("an index with id %q has already been registered")

	// ErrIndexExpressionAlreadyRegistered is the error returned when there is
	// already an index with the same expression.
	ErrIndexExpressionAlreadyRegistered = errors.NewKind("there is already an index registered for the expressions: %s")

	// ErrIndexNotFound is returned when the index could not be found.
	ErrIndexNotFound = errors.NewKind("index %q	was not found")

	// ErrIndexDeleteInvalidStatus is returned when the index trying to delete
	// does not have a ready or outdated state.
	ErrIndexDeleteInvalidStatus = errors.NewKind("can't delete index %q because it's not ready for removal")
)
View Source
var (
	// ErrNodeNotWritten is returned when the children are printed before the node.
	ErrNodeNotWritten = errors.New("treeprinter: a child was written before the node")
	// ErrNodeAlreadyWritten is returned when the node has already been written.
	ErrNodeAlreadyWritten = errors.New("treeprinter: node already written")
	// ErrChildrenAlreadyWritten is returned when the children have already been written.
	ErrChildrenAlreadyWritten = errors.New("treeprinter: children already written")
)
View Source
var (
	// ErrTypeNotSupported is thrown when a specific type is not supported
	ErrTypeNotSupported = errors.NewKind("Type not supported: %s")

	// ErrUnexpectedType is thrown when a received type is not the expected
	ErrUnexpectedType = errors.NewKind("value at %d has unexpected type: %s")

	// ErrConvertingToTime is thrown when a value cannot be converted to a Time
	ErrConvertingToTime = errors.NewKind("value %q can't be converted to time.Time")

	// ErrValueNotNil is thrown when a value that was expected to be nil, is not
	ErrValueNotNil = errors.NewKind("value not nil: %#v")

	// ErrNotTuple is retuned when the value is not a tuple.
	ErrNotTuple = errors.NewKind("value of type %T is not a tuple")

	// ErrInvalidColumnNumber is returned when a tuple has an invalid number of
	// arguments.
	ErrInvalidColumnNumber = errors.NewKind("tuple should contain %d column(s), but has %d")

	// ErrNotArray is returned when the value is not an array.
	ErrNotArray = errors.NewKind("value of type %T is not an array")

	// ErrConvertToSQL is returned when Convert failed.
	// It makes an error less verbose comparingto what spf13/cast returns.
	ErrConvertToSQL = errors.NewKind("incompatible conversion to SQL type: %s")
)
View Source
var (
	// Null represents the null type.
	Null nullT

	// Int32 is an integer of 32 bits.
	Int32 = numberT{/* contains filtered or unexported fields */}
	// Int64 is an integer of 64 bytes.
	Int64 = numberT{/* contains filtered or unexported fields */}
	// Uint32 is an unsigned integer of 32 bytes.
	Uint32 = numberT{/* contains filtered or unexported fields */}
	// Uint64 is an unsigned integer of 64 bytes.
	Uint64 = numberT{/* contains filtered or unexported fields */}
	// Float32 is a floating point number of 32 bytes.
	Float32 = numberT{/* contains filtered or unexported fields */}
	// Float64 is a floating point number of 64 bytes.
	Float64 = numberT{/* contains filtered or unexported fields */}

	// Timestamp is an UNIX timestamp.
	Timestamp timestampT
	// Date is a date with day, month and year.
	Date dateT
	// Text is a string type.
	Text textT
	// Boolean is a boolean type.
	Boolean booleanT
	// JSON is a type that holds any valid JSON object.
	JSON jsonT
	// Blob is a type that holds a chunk of binary data.
	Blob blobT
)
View Source
var ErrDatabaseNotFound = errors.NewKind("database not found: %s")

ErrDatabaseNotFound is thrown when a database is not found

View Source
var ErrFunctionNotFound = errors.NewKind("function not found: %s")

ErrFunctionNotFound is thrown when a function is not found

View Source
var ErrInvalidArgumentNumber = errors.NewKind("%s: expecting %v arguments for calling this function, %d received")

ErrInvalidArgumentNumber is returned when the number of arguments to call a function is different from the function arity.

View Source
var ErrPidAlreadyUsed = errors.NewKind("pid %d is already in use")

ErrPidAlreadyUsed is returned when the pid is already registered.

View Source
var TimestampLayouts = []string{
	"2006-01-02",
	time.RFC3339,
	"20060102150405",
	"20060102",
}

TimestampLayouts hold extra timestamps allowed for parsing. It does not have all the layouts supported by mysql. Missing are two digit year versions of common cases and dates that use non common separators.

https://github.com/MariaDB/server/blob/mysql-5.5.36/sql-common/my_time.c#L124

Functions

func DefaultSessionConfig added in v0.2.0

func DefaultSessionConfig() map[string]TypedValue

DefaultSessionConfig returns default values for session variables

func HasDefaultValue added in v0.2.0

func HasDefaultValue(s Session, key string) (bool, interface{})

HasDefaultValue checks if session variable value is the default one.

func IsArray

func IsArray(t Type) bool

IsArray returns whether the given type is an array.

func IsDecimal

func IsDecimal(t Type) bool

IsDecimal checks if t is decimal type.

func IsInteger

func IsInteger(t Type) bool

IsInteger check if t is a (U)Int32/64 type

func IsNull added in v0.3.0

func IsNull(ex Expression) bool

IsNull returns true if expression is nil or is Null Type, otherwise false.

func IsNumber

func IsNumber(t Type) bool

IsNumber checks if t is a number type

func IsSigned

func IsSigned(t Type) bool

IsSigned checks if t is a signed type.

func IsText

func IsText(t Type) bool

IsText checks if t is a text type.

func IsTuple

func IsTuple(t Type) bool

IsTuple checks if t is a tuple type. Note that tupleT instances with just 1 value are not considered as a tuple, but a parenthesized value.

func IsUnsigned

func IsUnsigned(t Type) bool

IsUnsigned checks if t is an unsigned type.

func MustConvert

func MustConvert(t Type, v interface{}) interface{}

MustConvert calls the Convert function from a given Type, it err panics.

func NumColumns

func NumColumns(t Type) int

NumColumns returns the number of columns in a type. This is one for all types, except tuples.

Types

type Aggregation

type Aggregation interface {
	Expression
	// NewBuffer creates a new aggregation buffer and returns it as a Row.
	NewBuffer() Row
	// Update updates the given buffer with the given row.
	Update(ctx *Context, buffer, row Row) error
	// Merge merges a partial buffer into a global one.
	Merge(ctx *Context, buffer, partial Row) error
}

Aggregation implements an aggregation expression, where an aggregation buffer is created for each grouping (NewBuffer) and rows in the grouping are fed to the buffer (Update). Multiple buffers can be merged (Merge), making partial aggregations possible. Note that Eval must be called with the final aggregation buffer in order to get the final result.

type Alterable

type Alterable interface {
	Create(name string, schema Schema) error
}

Alterable should be implemented by databases that can handle DDL statements

type AscendIndex

type AscendIndex interface {
	// AscendGreaterOrEqual returns an IndexLookup for keys that are greater
	// or equal to the given keys.
	AscendGreaterOrEqual(keys ...interface{}) (IndexLookup, error)
	// AscendLessThan returns an IndexLookup for keys that are less than the
	// given keys.
	AscendLessThan(keys ...interface{}) (IndexLookup, error)
	// AscendRange returns an IndexLookup for keys that are within the given
	// range.
	AscendRange(greaterOrEqual, lessThan []interface{}) (IndexLookup, error)
}

AscendIndex is an index that is sorted in ascending order.

type BaseSession

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

BaseSession is the basic session type.

func (*BaseSession) Address

func (s *BaseSession) Address() string

Address returns the server address.

func (*BaseSession) ClearWarnings added in v0.2.0

func (s *BaseSession) ClearWarnings()

ClearWarnings cleans up session warnings

func (*BaseSession) Client added in v0.2.0

func (s *BaseSession) Client() Client

Client returns session's client information.

func (*BaseSession) Get

func (s *BaseSession) Get(key string) (Type, interface{})

Get implements the Session interface.

func (*BaseSession) GetAll added in v0.2.0

func (s *BaseSession) GetAll() map[string]TypedValue

GetAll returns a copy of session configuration

func (*BaseSession) ID

func (s *BaseSession) ID() uint32

ID implements the Session interface.

func (*BaseSession) Set

func (s *BaseSession) Set(key string, typ Type, value interface{})

Set implements the Session interface.

func (*BaseSession) Warn added in v0.2.0

func (s *BaseSession) Warn(warn *Warning)

Warn stores the warning in the session.

func (*BaseSession) WarningCount added in v0.2.0

func (s *BaseSession) WarningCount() uint16

WarningCount returns a number of session warnings

func (*BaseSession) Warnings added in v0.2.0

func (s *BaseSession) Warnings() []*Warning

Warnings returns a copy of session warnings (from the most recent - the last one) The function implements sql.Session interface

type Catalog

type Catalog struct {
	FunctionRegistry
	*IndexRegistry
	*ProcessList
	// contains filtered or unexported fields
}

Catalog holds databases, tables and functions.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog returns a new empty Catalog.

func (*Catalog) AddDatabase added in v0.2.0

func (c *Catalog) AddDatabase(db Database)

AddDatabase adds a new database to the catalog.

func (*Catalog) AllDatabases added in v0.2.0

func (c *Catalog) AllDatabases() Databases

AllDatabases returns all databases in the catalog.

func (*Catalog) CurrentDatabase added in v0.2.0

func (c *Catalog) CurrentDatabase() string

CurrentDatabase returns the current database.

func (*Catalog) Database added in v0.2.0

func (c *Catalog) Database(db string) (Database, error)

Database returns the database with the given name.

func (*Catalog) LockTable added in v0.2.0

func (c *Catalog) LockTable(id uint32, table string)

LockTable adds a lock for the given table and session client. It is assumed the database is the current database in use.

func (*Catalog) SetCurrentDatabase added in v0.2.0

func (c *Catalog) SetCurrentDatabase(db string)

SetCurrentDatabase changes the current database.

func (*Catalog) Table added in v0.2.0

func (c *Catalog) Table(db, table string) (Table, error)

Table returns the table in the given database with the given name.

func (*Catalog) UnlockTables added in v0.2.0

func (c *Catalog) UnlockTables(ctx *Context, id uint32) error

UnlockTables unlocks all tables for which the given session client has a lock.

type Checksumable added in v0.4.0

type Checksumable interface {
	// Checksum returns a checksum and an error if there was any problem
	// computing or obtaining the checksum.
	Checksum() (string, error)
}

Checksumable provides the checksum of some data.

type Client added in v0.2.0

type Client struct {
	// User of the session.
	User string
	// Address of the client.
	Address string
}

Client holds session user information.

type Column

type Column struct {
	// Name is the name of the column.
	Name string
	// Type is the data type of the column.
	Type Type
	// Default contains the default value of the column or nil if it is NULL.
	Default interface{}
	// Nullable is true if the column can contain NULL values, or false
	// otherwise.
	Nullable bool
	// Source is the name of the table this column came from.
	Source string
}

Column is the definition of a table column. As SQL:2016 puts it:

A column is a named component of a table. It has a data type, a default,
and a nullability characteristic.

func (*Column) Check

func (c *Column) Check(v interface{}) bool

Check ensures the value is correct for this column.

func (*Column) Equals

func (c *Column) Equals(c2 *Column) bool

Equals checks whether two columns are equal.

type Context

type Context struct {
	context.Context
	Session
	// contains filtered or unexported fields
}

Context of the query execution.

func NewContext

func NewContext(
	ctx context.Context,
	opts ...ContextOption,
) *Context

NewContext creates a new query context. Options can be passed to configure the context. If some aspect of the context is not configure, the default value will be used. By default, the context will have an empty base session and a noop tracer.

func NewEmptyContext

func NewEmptyContext() *Context

NewEmptyContext returns a default context with default values.

func (*Context) Error added in v0.2.0

func (c *Context) Error(code int, msg string, args ...interface{})

Error adds an error as warning to the session.

func (*Context) Pid

func (c *Context) Pid() uint64

Pid returns the process id associated with this context.

func (*Context) Query added in v0.2.0

func (c *Context) Query() string

Query returns the query string associated with this context.

func (*Context) Span

func (c *Context) Span(
	opName string,
	opts ...opentracing.StartSpanOption,
) (opentracing.Span, *Context)

Span creates a new tracing span with the given context. It will return the span and a new context that should be passed to all childrens of this span.

func (*Context) Warn added in v0.2.0

func (c *Context) Warn(code int, msg string, args ...interface{})

Warn adds a warning to the session.

func (*Context) WithContext

func (c *Context) WithContext(ctx context.Context) *Context

WithContext returns a new context with the given underlying context.

type ContextOption

type ContextOption func(*Context)

ContextOption is a function to configure the context.

func WithPid

func WithPid(pid uint64) ContextOption

WithPid adds the given pid to the context.

func WithQuery added in v0.2.0

func WithQuery(q string) ContextOption

WithQuery add the given query to the context.

func WithSession

func WithSession(s Session) ContextOption

WithSession adds the given session to the context.

func WithTracer

func WithTracer(t opentracing.Tracer) ContextOption

WithTracer adds the given tracer to the context.

type Database

type Database interface {
	Nameable
	// Tables returns the information of all tables.
	Tables() map[string]Table
}

Database represents the database.

func NewInformationSchemaDatabase added in v0.2.0

func NewInformationSchemaDatabase(cat *Catalog) Database

NewInformationSchemaDatabase creates a new INFORMATION_SCHEMA Database.

type Databaser added in v0.4.0

type Databaser interface {
	// Database the current database.
	Database() Database
	// WithDatabase returns a new node instance with the database replaced with
	// the one given as parameter.
	WithDatabase(Database) (Node, error)
}

Databaser is a node that contains a reference to a database.

type Databases

type Databases []Database

Databases is a collection of Database.

func (*Databases) Add added in v0.2.0

func (d *Databases) Add(db Database)

Add adds a new database.

func (Databases) Database

func (d Databases) Database(name string) (Database, error)

Database returns the Database with the given name if it exists.

func (Databases) Table

func (d Databases) Table(dbName string, tableName string) (Table, error)

Table returns the Table with the given name if it exists.

type DescendIndex

type DescendIndex interface {
	// DescendGreater returns an IndexLookup for keys that are greater
	// than the given keys.
	DescendGreater(keys ...interface{}) (IndexLookup, error)
	// DescendLessOrEqual returns an IndexLookup for keys that are less than or
	// equal to the given keys.
	DescendLessOrEqual(keys ...interface{}) (IndexLookup, error)
	// DescendRange returns an IndexLookup for keys that are within the given
	// range.
	DescendRange(lessOrEqual, greaterThan []interface{}) (IndexLookup, error)
}

DescendIndex is an index that is sorted in descending order.

type Expression

type Expression interface {
	Resolvable
	fmt.Stringer
	// Type returns the expression type.
	Type() Type
	// IsNullable returns whether the expression can be null.
	IsNullable() bool
	// Eval evaluates the given row and returns a result.
	Eval(*Context, Row) (interface{}, error)
	// TransformUp transforms the expression and all its children with the
	// given transform function.
	TransformUp(TransformExprFunc) (Expression, error)
	// Children returns the children expressions of this expression.
	Children() []Expression
}

Expression is a combination of one or more SQL expressions.

type Expressioner

type Expressioner interface {
	// Expressions returns the list of expressions contained by the node.
	Expressions() []Expression
	// TransformExpressions applies for each expression in this node
	// the expression's TransformUp method with the given function, and
	// return a new node with the transformed expressions.
	TransformExpressions(TransformExprFunc) (Node, error)
}

Expressioner is a node that contains expressions.

type FilteredTable

type FilteredTable interface {
	Table
	HandledFilters(filters []Expression) []Expression
	WithFilters(filters []Expression) Table
	Filters() []Expression
}

FilteredTable is a table that can produce a specific RowIter that's more optimized given the filters.

type Function

type Function interface {
	// Call invokes the function.
	Call(...Expression) (Expression, error)
	// contains filtered or unexported methods
}

Function is a function defined by the user that can be applied in a SQL query.

type Function0 added in v0.2.0

type Function0 func() Expression

Function0 is a function with 0 arguments.

func (Function0) Call added in v0.2.0

func (fn Function0) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function1

type Function1 func(e Expression) Expression

Function1 is a function with 1 argument.

func (Function1) Call

func (fn Function1) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function2

type Function2 func(e1, e2 Expression) Expression

Function2 is a function with 2 arguments.

func (Function2) Call

func (fn Function2) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function3

type Function3 func(e1, e2, e3 Expression) Expression

Function3 is a function with 3 arguments.

func (Function3) Call

func (fn Function3) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function4

type Function4 func(e1, e2, e3, e4 Expression) Expression

Function4 is a function with 4 arguments.

func (Function4) Call

func (fn Function4) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function5

type Function5 func(e1, e2, e3, e4, e5 Expression) Expression

Function5 is a function with 5 arguments.

func (Function5) Call

func (fn Function5) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function6

type Function6 func(e1, e2, e3, e4, e5, e6 Expression) Expression

Function6 is a function with 6 arguments.

func (Function6) Call

func (fn Function6) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function7

type Function7 func(e1, e2, e3, e4, e5, e6, e7 Expression) Expression

Function7 is a function with 7 arguments.

func (Function7) Call

func (fn Function7) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type FunctionN

type FunctionN func(...Expression) (Expression, error)

FunctionN is a function with variable number of arguments. This function is expected to return ErrInvalidArgumentNumber if the arity does not match, since the check has to be done in the implementation.

func (FunctionN) Call

func (fn FunctionN) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type FunctionRegistry

type FunctionRegistry map[string]Function

FunctionRegistry is used to register functions. It is used both for builtin and User-Defined Functions.

func NewFunctionRegistry

func NewFunctionRegistry() FunctionRegistry

NewFunctionRegistry creates a new FunctionRegistry.

func (FunctionRegistry) Function

func (r FunctionRegistry) Function(name string) (Function, error)

Function returns a function with the given name.

func (FunctionRegistry) RegisterFunction

func (r FunctionRegistry) RegisterFunction(name string, f Function)

RegisterFunction registers a function with the given name.

func (FunctionRegistry) RegisterFunctions

func (r FunctionRegistry) RegisterFunctions(funcs Functions)

RegisterFunctions registers a map of functions.

type Functions

type Functions map[string]Function

Functions is a map of functions identified by their name.

type Index

type Index interface {
	// Get returns an IndexLookup for the given key in the index.
	Get(key ...interface{}) (IndexLookup, error)
	// Has checks if the given key is present in the index.
	Has(partition Partition, key ...interface{}) (bool, error)
	// ID returns the identifier of the index.
	ID() string
	// Database returns the database name this index belongs to.
	Database() string
	// Table returns the table name this index belongs to.
	Table() string
	// Expressions returns the indexed expressions. If the result is more than
	// one expression, it means the index has multiple columns indexed. If it's
	// just one, it means it may be an expression or a column.
	Expressions() []string
	// Driver ID of the index.
	Driver() string
}

Index is the basic representation of an index. It can be extended with more functionality by implementing more specific interfaces.

type IndexDriver

type IndexDriver interface {
	// ID returns the unique name of the driver.
	ID() string
	// Create a new index. If exprs is more than one expression, it means the
	// index has multiple columns indexed. If it's just one, it means it may
	// be an expression or a column.
	Create(db, table, id string, expressions []Expression, config map[string]string) (Index, error)
	// LoadAll loads all indexes for given db and table.
	LoadAll(db, table string) ([]Index, error)
	// Save the given index for all partitions.
	Save(*Context, Index, PartitionIndexKeyValueIter) error
	// Delete the given index for all partitions in the iterator.
	Delete(Index, PartitionIter) error
}

IndexDriver manages the coordination between the indexes and their representation on disk.

type IndexKeyValueIter

type IndexKeyValueIter interface {
	// Next returns the next tuple of index key values. The length of the
	// returned slice will be the same as the number of columns used to
	// create this iterator. The second returned parameter is a repo's location.
	Next() ([]interface{}, []byte, error)
	io.Closer
}

IndexKeyValueIter is an iterator of index key values, that is, a tuple of the values that will be index keys.

type IndexLookup

type IndexLookup interface {
	// Values returns the values in the subset of the index.
	Values(Partition) (IndexValueIter, error)

	// Indexes returns the IDs of all indexes involved in this lookup.
	Indexes() []string
}

IndexLookup is a subset of an index. More specific interfaces can be implemented to grant more capabilities to the index lookup.

type IndexRegistry

type IndexRegistry struct {
	// Root path where all the data of the indexes is stored on disk.
	Root string
	// contains filtered or unexported fields
}

IndexRegistry keeps track of all indexes in the engine.

func NewIndexRegistry

func NewIndexRegistry() *IndexRegistry

NewIndexRegistry returns a new Index Registry.

func (*IndexRegistry) AddIndex

func (r *IndexRegistry) AddIndex(
	idx Index,
) (created chan<- struct{}, ready <-chan struct{}, err error)

AddIndex adds the given index to the registry. The added index will be marked as creating, so nobody can't register two indexes with the same expression or id while the other is still being created. When something is sent through the returned channel, it means the index has finished it's creation and will be marked as ready. Another channel is returned to notify the user when the index is ready.

func (*IndexRegistry) CanRemoveIndex added in v0.4.0

func (r *IndexRegistry) CanRemoveIndex(idx Index) bool

CanRemoveIndex returns whether the given index is ready to be removed.

func (*IndexRegistry) CanUseIndex

func (r *IndexRegistry) CanUseIndex(idx Index) bool

CanUseIndex returns whether the given index is ready to use or not.

func (*IndexRegistry) DefaultIndexDriver

func (r *IndexRegistry) DefaultIndexDriver() IndexDriver

DefaultIndexDriver returns the default index driver, which is the only driver when there is 1 driver in the registry. If there are more than 1 drivers in the registry, this will return the empty string, as there is no clear default driver.

func (*IndexRegistry) DeleteIndex

func (r *IndexRegistry) DeleteIndex(db, id string, force bool) (<-chan struct{}, error)

DeleteIndex deletes an index from the registry by its id. First, it marks the index for deletion but does not remove it, so queries that are using it may still do so. The returned channel will send a message when the index can be deleted from disk. If force is true, it will delete the index even if it's not ready for usage. Only use that parameter if you know what you're doing.

func (*IndexRegistry) ExpressionsWithIndexes

func (r *IndexRegistry) ExpressionsWithIndexes(
	db string,
	exprs ...Expression,
) [][]Expression

ExpressionsWithIndexes finds all the combinations of expressions with matching indexes. This only matches multi-column indexes.

func (*IndexRegistry) Index

func (r *IndexRegistry) Index(db, id string) Index

Index returns the index with the given id. It may return nil if the index is not found.

func (*IndexRegistry) IndexByExpression

func (r *IndexRegistry) IndexByExpression(db string, expr ...Expression) Index

IndexByExpression returns an index by the given expression. It will return nil it the index is not found. If more than one expression is given, all of them must match for the index to be matched.

func (*IndexRegistry) IndexDriver

func (r *IndexRegistry) IndexDriver(id string) IndexDriver

IndexDriver returns the IndexDriver with the given ID.

func (*IndexRegistry) IndexesByTable

func (r *IndexRegistry) IndexesByTable(db, table string) []Index

IndexesByTable returns a slice of all the indexes existing on the given table.

func (*IndexRegistry) LoadIndexes

func (r *IndexRegistry) LoadIndexes(dbs Databases) error

LoadIndexes loads all indexes for all dbs, tables and drivers.

func (*IndexRegistry) RegisterIndexDriver

func (r *IndexRegistry) RegisterIndexDriver(driver IndexDriver)

RegisterIndexDriver registers a new index driver.

func (*IndexRegistry) ReleaseIndex

func (r *IndexRegistry) ReleaseIndex(idx Index)

ReleaseIndex releases an index after it's been used.

type IndexStatus

type IndexStatus byte

IndexStatus represents the current status in which the index is.

const (
	// IndexNotReady means the index is not ready to be used.
	IndexNotReady IndexStatus = iota
	// IndexReady means the index can be used.
	IndexReady
	// IndexOutdated means the index is loaded but will not be used because the
	// contents in it are outdated.
	IndexOutdated
)

func (IndexStatus) IsUsable

func (s IndexStatus) IsUsable() bool

IsUsable returns whether the index can be used or not based on the status.

func (IndexStatus) String

func (s IndexStatus) String() string

type IndexValueIter

type IndexValueIter interface {
	// Next returns the next value (repo's location) - see IndexKeyValueIter.
	Next() ([]byte, error)
	io.Closer
}

IndexValueIter is an iterator of index values.

type IndexableTable

type IndexableTable interface {
	Table
	WithIndexLookup(IndexLookup) Table
	IndexLookup() IndexLookup
	IndexKeyValues(*Context, []string) (PartitionIndexKeyValueIter, error)
}

IndexableTable represents a table that supports being indexed and receiving indexes to be able to speed up its execution.

type Inserter

type Inserter interface {
	// Insert the given row.
	Insert(*Context, Row) error
}

Inserter allow rows to be inserted in them.

type Lockable added in v0.2.0

type Lockable interface {
	Nameable
	// Lock locks the table either for reads or writes. Any session clients can
	// read while the table is locked for read, but not write.
	// When the table is locked for write, nobody can write except for the
	// session client that requested the lock.
	Lock(ctx *Context, write bool) error
	// Unlock releases the lock for the current session client. It blocks until
	// all reads or writes started during the lock are finished.
	// Context may be nil if the unlock it's because the connection was closed.
	// The id will always be provided, since in some cases context is not
	// available.
	Unlock(ctx *Context, id uint32) error
}

Lockable should be implemented by tables that can be locked and unlocked.

type Mergeable

type Mergeable interface {
	// IsMergeable checks whether the current IndexLookup can be merged with
	// the given one.
	IsMergeable(IndexLookup) bool
}

Mergeable is a specialization of IndexLookup to check if an IndexLookup can be merged with another one.

type Nameable

type Nameable interface {
	// Name returns the name.
	Name() string
}

Nameable is something that has a name.

type NegateIndex

type NegateIndex interface {
	// Not returns an IndexLookup for keys that are not equal
	// to the given keys.
	Not(keys ...interface{}) (IndexLookup, error)
}

NegateIndex is an index that supports retrieving negated values.

type Node

type Node interface {
	Resolvable
	Transformable
	fmt.Stringer
	// Schema of the node.
	Schema() Schema
	// Children nodes.
	Children() []Node
	// RowIter produces a row iterator from this node.
	RowIter(*Context) (RowIter, error)
}

Node is a node in the execution plan tree.

type Partition

type Partition interface {
	Key() []byte
}

Partition represents a partition from a SQL table.

type PartitionCounter

type PartitionCounter interface {
	// PartitionCount returns the number of partitions.
	PartitionCount(*Context) (int64, error)
}

PartitionCounter can return the number of partitions.

type PartitionIndexKeyValueIter

type PartitionIndexKeyValueIter interface {
	// Next returns the next partition and the IndexKeyValueIter for that
	// partition.
	Next() (Partition, IndexKeyValueIter, error)
	io.Closer
}

PartitionIndexKeyValueIter is an iterator of partitions that will return the partition and the IndexKeyValueIter of that partition.

type PartitionIter

type PartitionIter interface {
	io.Closer
	Next() (Partition, error)
}

PartitionIter is an iterator that retrieves partitions.

type Process

type Process struct {
	Pid        uint64
	Connection uint32
	User       string
	Type       ProcessType
	Query      string
	Progress   map[string]Progress
	StartedAt  time.Time
	Kill       context.CancelFunc
}

Process represents a process in the SQL server.

func (*Process) Done

func (p *Process) Done()

Done needs to be called when this process has finished.

func (*Process) Seconds

func (p *Process) Seconds() uint64

Seconds returns the number of seconds this process has been running.

type ProcessList

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

ProcessList is a structure that keeps track of all the processes and their status.

func NewProcessList

func NewProcessList() *ProcessList

NewProcessList creates a new process list.

func (*ProcessList) AddProcess

func (pl *ProcessList) AddProcess(
	ctx *Context,
	typ ProcessType,
	query string,
) (*Context, error)

AddProcess adds a new process to the list given a process type and a query. Steps is a map between the name of the items that need to be completed and the total amount in these items. -1 means unknown. It returns a new context that should be passed around from now on. That context will be cancelled if the process is killed.

func (*ProcessList) AddProgressItem

func (pl *ProcessList) AddProgressItem(pid uint64, name string, total int64)

AddProgressItem adds a new item to track progress from to the process with the given pid. If the pid does not exist, it will do nothing.

func (*ProcessList) Done

func (pl *ProcessList) Done(pid uint64)

Done removes the finished process with the given pid from the process list. If the process does not exist, it will do nothing.

func (*ProcessList) Kill

func (pl *ProcessList) Kill(pid uint64)

Kill terminates a process if it exists.

func (*ProcessList) KillConnection

func (pl *ProcessList) KillConnection(conn uint32)

KillConnection kills all processes from the given connection.

func (*ProcessList) Processes

func (pl *ProcessList) Processes() []Process

Processes returns the list of current running processes.

func (*ProcessList) UpdateProgress

func (pl *ProcessList) UpdateProgress(pid uint64, name string, delta int64)

UpdateProgress updates the progress of the item with the given name for the process with the given pid.

type ProcessType

type ProcessType byte

ProcessType is the type of process.

const (
	// QueryProcess is a query process.
	QueryProcess ProcessType = iota
	// CreateIndexProcess is a process to create an index.
	CreateIndexProcess
)

func (ProcessType) String

func (p ProcessType) String() string

type Progress

type Progress struct {
	Done  int64
	Total int64
}

Progress between done items and total items.

func (Progress) String

func (p Progress) String() string

type ProjectedTable

type ProjectedTable interface {
	Table
	WithProjection(colNames []string) Table
	Projection() []string
}

ProjectedTable is a table that can produce a specific RowIter that's more optimized given the columns that are projected.

type Resolvable

type Resolvable interface {
	// Resolved returns whether the node is resolved.
	Resolved() bool
}

Resolvable is something that can be resolved or not.

type Row

type Row []interface{}

Row is a tuple of values.

func NewRow

func NewRow(values ...interface{}) Row

NewRow creates a row from the given values.

func NodeToRows

func NodeToRows(ctx *Context, n Node) ([]Row, error)

NodeToRows converts a node to a slice of rows.

func RowIterToRows

func RowIterToRows(i RowIter) ([]Row, error)

RowIterToRows converts a row iterator to a slice of rows.

func (Row) Copy

func (r Row) Copy() Row

Copy creates a new row with the same values as the current one.

func (Row) Equals

func (r Row) Equals(row Row, schema Schema) (bool, error)

Equals checks whether two rows are equal given a schema.

type RowIter

type RowIter interface {
	// Next retrieves the next row. It will return io.EOF if it's the last row.
	// After retrieving the last row, Close will be automatically closed.
	Next() (Row, error)
	// Close the iterator.
	Close() error
}

RowIter is an iterator that produces rows.

func NewSpanIter

func NewSpanIter(span opentracing.Span, iter RowIter) RowIter

NewSpanIter creates a RowIter executed in the given span.

func RowsToRowIter

func RowsToRowIter(rows ...Row) RowIter

RowsToRowIter creates a RowIter that iterates over the given rows.

type Schema

type Schema []*Column

Schema is the definition of a table.

func (Schema) CheckRow

func (s Schema) CheckRow(row Row) error

CheckRow checks the row conforms to the schema.

func (Schema) Contains

func (s Schema) Contains(column string, source string) bool

Contains returns whether the schema contains a column with the given name.

func (Schema) Equals

func (s Schema) Equals(s2 Schema) bool

Equals checks whether the given schema is equal to this one.

func (Schema) IndexOf

func (s Schema) IndexOf(column, source string) int

IndexOf returns the index of the given column in the schema or -1 if it's not present.

type Session

type Session interface {
	// Address of the server.
	Address() string
	// User of the session.
	Client() Client
	// Set session configuration.
	Set(key string, typ Type, value interface{})
	// Get session configuration.
	Get(key string) (Type, interface{})
	// GetAll returns a copy of session configuration
	GetAll() map[string]TypedValue
	// ID returns the unique ID of the connection.
	ID() uint32
	// Warn stores the warning in the session.
	Warn(warn *Warning)
	// Warnings returns a copy of session warnings (from the most recent).
	Warnings() []*Warning
	// ClearWarnings cleans up session warnings.
	ClearWarnings()
	// WarningCount returns a number of session warnings
	WarningCount() uint16
}

Session holds the session data.

func NewBaseSession

func NewBaseSession() Session

NewBaseSession creates a new empty session.

func NewSession

func NewSession(server, client, user string, id uint32) Session

NewSession creates a new session with data.

type SetOperations

type SetOperations interface {
	// Intersection returns a new index subset with the intersection of the
	// current IndexLookup and the ones given.
	Intersection(...IndexLookup) IndexLookup
	// Union returns a new index subset with the union of the current
	// IndexLookup and the ones given.
	Union(...IndexLookup) IndexLookup
	// Difference returns a new index subset with the difference between the
	// current IndexLookup and the ones given.
	Difference(...IndexLookup) IndexLookup
}

SetOperations is a specialization of IndexLookup that enables set operations between several IndexLookups.

type Table

type Table interface {
	Nameable
	String() string
	Schema() Schema
	Partitions(*Context) (PartitionIter, error)
	PartitionRows(*Context, Partition) (RowIter, error)
}

Table represents the backend of a SQL table.

type TableWrapper

type TableWrapper interface {
	// Underlying returns the underlying table.
	Underlying() Table
}

TableWrapper is a node that wraps the real table. This is needed because wrappers cannot implement some methods the table may implement.

type Tableable

type Tableable interface {
	// Table returns the table name.
	Table() string
}

Tableable is something that has a table.

type TransformExprFunc

type TransformExprFunc func(Expression) (Expression, error)

TransformExprFunc is a function that given an expression will return that expression as is or transformed along with an error, if any.

type TransformNodeFunc

type TransformNodeFunc func(Node) (Node, error)

TransformNodeFunc is a function that given a node will return that node as is or transformed along with an error, if any.

type Transformable

type Transformable interface {
	// TransformUp transforms all nodes and returns the result of this transformation.
	// Transformation is not propagated to subqueries.
	TransformUp(TransformNodeFunc) (Node, error)
	// TransformExpressionsUp transforms all expressions inside the node and all its
	// children and returns a node with the result of the transformations.
	// Transformation is not propagated to subqueries.
	TransformExpressionsUp(TransformExprFunc) (Node, error)
}

Transformable is a node which can be transformed.

type TreePrinter

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

TreePrinter is a printer for tree nodes.

func NewTreePrinter

func NewTreePrinter() *TreePrinter

NewTreePrinter creates a new tree printer.

func (*TreePrinter) String

func (p *TreePrinter) String() string

String returns the output of the printed tree.

func (*TreePrinter) WriteChildren

func (p *TreePrinter) WriteChildren(children ...string) error

WriteChildren writes a children of the tree.

func (*TreePrinter) WriteNode

func (p *TreePrinter) WriteNode(format string, args ...interface{}) error

WriteNode writes the main node.

type Type

type Type interface {
	// Type returns the query.Type for the given Type.
	Type() query.Type
	// Covert a value of a compatible type to a most accurate type.
	Convert(interface{}) (interface{}, error)
	// Compare returns an integer comparing two values.
	// The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
	Compare(interface{}, interface{}) (int, error)
	// SQL returns the sqltypes.Value for the given value.
	SQL(interface{}) sqltypes.Value
	fmt.Stringer
}

Type represent a SQL type.

func Array

func Array(underlying Type) Type

Array returns a new Array type of the given underlying type.

func MysqlTypeToType

func MysqlTypeToType(sql query.Type) (Type, error)

MysqlTypeToType gets the column type using the mysql type

func Tuple

func Tuple(types ...Type) Type

Tuple returns a new tuple type with the given element types.

type TypedValue added in v0.2.0

type TypedValue struct {
	Typ   Type
	Value interface{}
}

TypedValue is a value along with its type.

type UnresolvedDatabase

type UnresolvedDatabase string

UnresolvedDatabase is a database which has not been resolved yet.

func (UnresolvedDatabase) Name

func (d UnresolvedDatabase) Name() string

Name returns the database name.

func (UnresolvedDatabase) Tables

func (UnresolvedDatabase) Tables() map[string]Table

Tables returns the tables in the database.

type Warning added in v0.2.0

type Warning struct {
	Level   string
	Message string
	Code    int
}

Warning stands for mySQL warning record.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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