Documentation ¶
Index ¶
- Constants
- Variables
- func CacheKey(v interface{}) uint64
- func DefaultSessionConfig() map[string]TypedValue
- func EvaluateCondition(ctx *Context, cond Expression, row Row) (bool, error)
- func HasAvailableMemory(r Reporter) bool
- func HasDefaultValue(s Session, key string) (bool, interface{})
- func IsArray(t Type) bool
- func IsChar(t Type) bool
- func IsDecimal(t Type) bool
- func IsInteger(t Type) bool
- func IsNull(ex Expression) bool
- func IsNumber(t Type) bool
- func IsSigned(t Type) bool
- func IsText(t Type) bool
- func IsTime(t Type) bool
- func IsTuple(t Type) bool
- func IsUnsigned(t Type) bool
- func IsVarChar(t Type) bool
- func MySQLTypeName(t Type) string
- func NumColumns(t Type) int
- func ValidateTime(t time.Time) interface{}
- type Aggregation
- type Alterable
- type AscendIndex
- type BaseSession
- func (s *BaseSession) Address() string
- func (s *BaseSession) ClearWarnings()
- func (s *BaseSession) Client() Client
- func (s *BaseSession) Get(key string) (Type, interface{})
- func (s *BaseSession) GetAll() map[string]TypedValue
- func (s *BaseSession) ID() uint32
- func (s *BaseSession) Set(key string, typ Type, value interface{})
- func (s *BaseSession) Warn(warn *Warning)
- func (s *BaseSession) WarningCount() uint16
- func (s *BaseSession) Warnings() []*Warning
- type Catalog
- func (c *Catalog) AddDatabase(db Database)
- func (c *Catalog) AllDatabases() Databases
- func (c *Catalog) CurrentDatabase() string
- func (c *Catalog) Database(db string) (Database, error)
- func (c *Catalog) LockTable(id uint32, table string)
- func (c *Catalog) SetCurrentDatabase(db string)
- func (c *Catalog) Table(db, table string) (Table, error)
- func (c *Catalog) UnlockTables(ctx *Context, id uint32) error
- type Checksumable
- type Client
- type Column
- type Context
- func (c *Context) Error(code int, msg string, args ...interface{})
- func (c *Context) Pid() uint64
- func (c *Context) Query() string
- func (c *Context) Span(opName string, opts ...opentracing.StartSpanOption) (opentracing.Span, *Context)
- func (c *Context) Warn(code int, msg string, args ...interface{})
- func (c *Context) WithContext(ctx context.Context) *Context
- type ContextOption
- type Database
- type Databaser
- type Databases
- type Deleter
- type DescendIndex
- type Disposable
- type DisposeFunc
- type Expression
- type Expressioner
- type FilteredTable
- type Freeable
- type Function
- type Function0
- type Function1
- type Function2
- type Function3
- type Function4
- type Function5
- type Function6
- type Function7
- type FunctionN
- type FunctionRegistry
- type Generator
- type Index
- type IndexDriver
- type IndexKeyValueIter
- type IndexLookup
- type IndexRegistry
- func (r *IndexRegistry) AddIndex(idx Index) (created chan<- struct{}, ready <-chan struct{}, err error)
- func (r *IndexRegistry) CanRemoveIndex(idx Index) bool
- func (r *IndexRegistry) CanUseIndex(idx Index) bool
- func (r *IndexRegistry) DefaultIndexDriver() IndexDriver
- func (r *IndexRegistry) DeleteIndex(db, id string, force bool) (<-chan struct{}, error)
- func (r *IndexRegistry) ExpressionsWithIndexes(db string, exprs ...Expression) [][]Expression
- func (r *IndexRegistry) Index(db, id string) Index
- func (r *IndexRegistry) IndexByExpression(db string, expr ...Expression) Index
- func (r *IndexRegistry) IndexDriver(id string) IndexDriver
- func (r *IndexRegistry) IndexesByTable(db, table string) []Index
- func (r *IndexRegistry) LoadIndexes(dbs Databases) error
- func (r *IndexRegistry) MarkOutdated(idx Index)
- func (r *IndexRegistry) RegisterIndexDriver(driver IndexDriver)
- func (r *IndexRegistry) ReleaseIndex(idx Index)
- type IndexStatus
- type IndexValueIter
- type IndexableTable
- type Inserter
- type KeyValueCache
- type Lockable
- type MemoryManager
- type Mergeable
- type Nameable
- type NegateIndex
- type Node
- type OpaqueNode
- type Partition
- type PartitionCounter
- type PartitionIndexKeyValueIter
- type PartitionIter
- type Process
- type ProcessList
- func (pl *ProcessList) AddProcess(ctx *Context, typ ProcessType, query string) (*Context, error)
- func (pl *ProcessList) AddProgressItem(pid uint64, name string, total int64)
- func (pl *ProcessList) Done(pid uint64)
- func (pl *ProcessList) Kill(connID uint32)
- func (pl *ProcessList) KillOnlyQueries(connID uint32)
- func (pl *ProcessList) Processes() []Process
- func (pl *ProcessList) UpdateProgress(pid uint64, name string, delta int64)
- type ProcessType
- type Progress
- type ProjectedTable
- type Replacer
- type Reporter
- type Resolvable
- type Row
- type RowIter
- type RowsCache
- type Schema
- type Session
- type SetOperations
- type Table
- type TableWrapper
- type Tableable
- type TransformExprFunc
- type TransformNodeFunc
- type TreePrinter
- type Type
- type TypedValue
- type UnresolvedDatabase
- type Warning
Constants ¶
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" )
const ChecksumKey = "checksum"
ChecksumKey is the key in an index config to store the checksum.
const DateLayout = "2006-01-02"
DateLayout is the layout of the MySQL date format in the representation Go understands.
const DatetimeLayout = "2006-01-02 15:04:05"
DatetimeLayout is the layout of the MySQL date format in the representation Go understands.
const IndexBatchSize = uint64(10000)
IndexBatchSize is the number of rows to save at a time when creating indexes.
const ( // QueryKey to access query in the context. QueryKey key = iota )
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 ¶
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") // ErrInvalidChildrenNumber is returned when the WithChildren method of a // node or expression is called with an invalid number of arguments. ErrInvalidChildrenNumber = errors.NewKind("%T: invalid children number, got %d, expected %d") // ErrDeleteRowNotFound ErrDeleteRowNotFound = errors.NewKind("row was not found when attempting to delete").New() )
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") )
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") )
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") // ErrCharTruncation is thrown when a Char value is textually longer than the destination capacity ErrCharTruncation = errors.NewKind("string value of %q is longer than destination capacity %d") // ErrVarCharTruncation is thrown when a VarChar value is textually longer than the destination capacity ErrVarCharTruncation = errors.NewKind("string value of %q is longer than destination capacity %d") // ErrValueNotNil is thrown when a value that was expected to be nil, is not ErrValueNotNil = errors.NewKind("value not nil: %#v") // ErrNotTuple is returned 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") )
var ( // Null represents the null type. Null nullT // Int8 is an integer of 8 bits Int8 = numberT{/* contains filtered or unexported fields */} // Uint8 is an unsigned integer of 8 bits Uint8 = numberT{/* contains filtered or unexported fields */} // Int16 is an integer of 16 bits Int16 = numberT{/* contains filtered or unexported fields */} // Uint16 is an unsigned integer of 16 bits Uint16 = numberT{/* contains filtered or unexported fields */} // Int32 is an integer of 32 bits. Int32 = numberT{/* contains filtered or unexported fields */} // Uint32 is an unsigned integer of 32 bits. Uint32 = numberT{/* contains filtered or unexported fields */} // Int64 is an integer of 64 bytes. Int64 = numberT{/* contains filtered or unexported fields */} // Uint64 is an unsigned integer of 64 bits. Uint64 = numberT{/* contains filtered or unexported fields */} // Float32 is a floating point number of 32 bits. Float32 = numberT{/* contains filtered or unexported fields */} // Float64 is a floating point number of 64 bits. 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 // Datetime is a date and a time Datetime datetimeT // 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 )
var ErrDatabaseNotFound = errors.NewKind("database not found: %s")
ErrDatabaseNotFound is thrown when a database is not found
var ErrFunctionAlreadyRegistered = errors.NewKind("function '%s' is already registered")
ErrFunctionAlreadyRegistered is thrown when a function is already registered
var ErrFunctionNotFound = errors.NewKind("function: '%s' not found")
ErrFunctionNotFound is thrown when a function is not found
var ErrInvalidArgumentNumber = errors.NewKind("function '%s' expected %v arguments, %v received")
ErrInvalidArgumentNumber is returned when the number of arguments to call a function is different from the function arity.
var ErrKeyNotFound = errors.NewKind("memory: key %d not found in cache")
ErrKeyNotFound is returned when the key could not be found in the cache.
var ErrNoMemoryAvailable = errors.NewKind("no memory available")
ErrNoMemoryAvailable is returned when there is no more available memory.
var ErrNotGenerator = errors.NewKind("cannot convert value of type %T to a generator")
ErrNotGenerator is returned when the value cannot be converted to a generator.
var ErrPidAlreadyUsed = errors.NewKind("pid %d is already in use")
ErrPidAlreadyUsed is returned when the pid is already registered.
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 CacheKey ¶
func CacheKey(v interface{}) uint64
CacheKey returns a hash of the given value to be used as key in a cache.
func DefaultSessionConfig ¶
func DefaultSessionConfig() map[string]TypedValue
DefaultSessionConfig returns default values for session variables
func EvaluateCondition ¶
func EvaluateCondition(ctx *Context, cond Expression, row Row) (bool, error)
EvaluateCondition evaluates a condition, which is an expression whose value will be coerced to boolean.
func HasAvailableMemory ¶
HasAvailableMemory reports whether more memory is available to the program if it hasn't reached the max memory limit.
func HasDefaultValue ¶
HasDefaultValue checks if session variable value is the default one.
func IsNull ¶
func IsNull(ex Expression) bool
IsNull returns true if expression is nil or is Null Type, otherwise false.
func IsTuple ¶
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 MySQLTypeName ¶
MySQLTypeName returns the MySQL display name for the given type.
func NumColumns ¶
NumColumns returns the number of columns in a type. This is one for all types, except tuples.
func ValidateTime ¶
ValidateTime receives a time and returns either that time or nil if it's not a valid time.
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 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 ¶
func (s *BaseSession) ClearWarnings()
ClearWarnings cleans up session warnings
func (*BaseSession) Client ¶
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 ¶
func (s *BaseSession) GetAll() map[string]TypedValue
GetAll returns a copy of session configuration
func (*BaseSession) Set ¶
func (s *BaseSession) Set(key string, typ Type, value interface{})
Set implements the Session interface.
func (*BaseSession) Warn ¶
func (s *BaseSession) Warn(warn *Warning)
Warn stores the warning in the session.
func (*BaseSession) WarningCount ¶
func (s *BaseSession) WarningCount() uint16
WarningCount returns a number of session warnings
func (*BaseSession) Warnings ¶
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 *MemoryManager // contains filtered or unexported fields }
Catalog holds databases, tables and functions.
func (*Catalog) AddDatabase ¶
AddDatabase adds a new database to the catalog.
func (*Catalog) AllDatabases ¶
AllDatabases returns all databases in the catalog.
func (*Catalog) CurrentDatabase ¶
CurrentDatabase returns the current database.
func (*Catalog) LockTable ¶
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 ¶
SetCurrentDatabase changes the current database.
type Checksumable ¶
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 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.
type Context ¶
type Context struct { context.Context Session Memory *MemoryManager // 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, a noop tracer and a memory manager using the process reporter.
func NewEmptyContext ¶
func NewEmptyContext() *Context
NewEmptyContext returns a default context with default values.
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.
type ContextOption ¶
type ContextOption func(*Context)
ContextOption is a function to configure the context.
func WithMemoryManager ¶
func WithMemoryManager(m *MemoryManager) ContextOption
WithMemoryManager adds the given memory manager to the context.
func WithQuery ¶
func WithQuery(q string) ContextOption
WithQuery adds 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 ¶
NewInformationSchemaDatabase creates a new INFORMATION_SCHEMA Database.
type Databaser ¶
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.
type Deleter ¶
type Deleter interface { // Delete the given row. Returns ErrDeleteRowNotFound if the row was not found. Delete(*Context, Row) error }
Deleter allow rows to be deleted from tables.
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 Disposable ¶
type Disposable interface {
// Dispose the contents.
Dispose()
}
Disposable objects can erase all their content when they're no longer in use. They should not be used again after they've been disposed.
type DisposeFunc ¶
type DisposeFunc func()
DisposeFunc is a function to completely erase a cache and remove it from the manager.
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) // Children returns the children expressions of this expression. Children() []Expression // WithChildren returns a copy of the expression with children replaced. // It will return an error if the number of children is different than // the current number of children. They must be given in the same order // as they are returned by Children. WithChildren(...Expression) (Expression, error) }
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 // WithExpressions returns a copy of the node with expressions replaced. // It will return an error if the number of expressions is different than // the current number of expressions. They must be given in the same order // as they are returned by Expressions. WithExpressions(...Expression) (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 Freeable ¶
type Freeable interface {
// Free the memory.
Free()
}
Freeable objects can free their memory.
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 ¶
type Function0 struct { Name string Fn func() Expression }
Function0 is a function with 0 arguments.
func (Function0) Call ¶
func (fn Function0) Call(args ...Expression) (Expression, error)
Call implements the Function interface.
type Function1 ¶
type Function1 struct { Name string Fn 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 struct { Name string Fn 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 struct { Name string Fn 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 struct { Name string Fn 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 struct { Name string Fn 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 struct { Name string Fn 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 struct { Name string Fn 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 struct { Name string Fn 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 ¶
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) MustRegister ¶
func (r FunctionRegistry) MustRegister(fn ...Function)
MustRegister registers functions. If function with that name is already registered, it will panic!
func (FunctionRegistry) Register ¶
func (r FunctionRegistry) Register(fn ...Function) error
Register registers functions. If function with that name is already registered, the ErrFunctionAlreadyRegistered will be returned
type Generator ¶
type Generator interface { // Next value in the generator. Next() (interface{}, error) // Close the generator and dispose resources. Close() error }
Generator will generate a set of values for a given row.
func NewArrayGenerator ¶
func NewArrayGenerator(array []interface{}) Generator
NewArrayGenerator creates a generator for a given array.
func ToGenerator ¶
ToGenerator converts a value to a generator if possible.
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 ¶
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) MarkOutdated ¶
func (r *IndexRegistry) MarkOutdated(idx Index)
MarkOutdated sets the index status as outdated. This method is not thread safe and should not be used directly except for testing.
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 KeyValueCache ¶
type KeyValueCache interface { // Put a new value in the cache. Put(uint64, interface{}) error // Get the value with the given key. Get(uint64) (interface{}, error) }
KeyValueCache is a cache of key value pairs.
type Lockable ¶
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 MemoryManager ¶
type MemoryManager struct {
// contains filtered or unexported fields
}
MemoryManager is in charge of keeping track and managing all the components that operate in memory. There should only be one instance of a memory manager running at the same time in each process.
func NewMemoryManager ¶
func NewMemoryManager(r Reporter) *MemoryManager
NewMemoryManager creates a new manager with the given memory reporter. If nil is given, then the Process reporter will be used by default.
func (*MemoryManager) HasAvailable ¶
func (m *MemoryManager) HasAvailable() bool
HasAvailable reports whether the memory manager has any available memory.
func (*MemoryManager) NewHistoryCache ¶
func (m *MemoryManager) NewHistoryCache() (KeyValueCache, DisposeFunc)
NewHistoryCache returns an empty history cache and a function to dispose it when it's no longer needed.
func (*MemoryManager) NewLRUCache ¶
func (m *MemoryManager) NewLRUCache(size uint) (KeyValueCache, DisposeFunc)
NewLRUCache returns an empty LRU cache and a function to dispose it when it's no longer needed.
func (*MemoryManager) NewRowsCache ¶
func (m *MemoryManager) NewRowsCache() (RowsCache, DisposeFunc)
NewRowsCache returns an empty rows cache and a function to dispose it when it's no longer needed.
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 fmt.Stringer // Schema of the node. Schema() Schema // Children nodes. Children() []Node // RowIter produces a row iterator from this node. RowIter(*Context) (RowIter, error) // WithChildren returns a copy of the node with children replaced. // It will return an error if the number of children is different than // the current number of children. They must be given in the same order // as they are returned by Children. WithChildren(...Node) (Node, error) }
Node is a node in the execution plan tree.
type OpaqueNode ¶
type OpaqueNode interface { Node // Opaque reports whether the node is opaque or not. Opaque() bool }
OpaqueNode is a node that doesn't allow transformations to its children and acts a a black box.
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 ¶
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.
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 (*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(connID uint32)
Kill terminates all queries for a given connection id.
func (*ProcessList) KillOnlyQueries ¶
func (pl *ProcessList) KillOnlyQueries(connID uint32)
KillOnlyQueries kills all queries, but not index creation queries, for a given connection id.
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 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 Reporter ¶
type Reporter interface { // MaxMemory returns the maximum number of memory allowed in bytes. MaxMemory() uint64 // UsedMemory returns the memory in use in bytes. UsedMemory() uint64 }
Reporter is a component that gives information about the memory usage.
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 NodeToRows ¶
NodeToRows converts a node to a slice of rows.
func RowIterToRows ¶
RowIterToRows converts a row iterator to a slice of rows.
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 ¶
RowsToRowIter creates a RowIter that iterates over the given rows.
type RowsCache ¶
type RowsCache interface { // Add a new row to the cache. If there is no memory available, it will try to // free some memory. If after that there is still no memory available, it // will return an error and erase all the content of the cache. Add(Row) error // Get all rows. Get() []Row }
RowsCache is a cache of rows.
type Schema ¶
type Schema []*Column
Schema is the definition of a table.
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 NewSession ¶
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 ¶
TransformNodeFunc is a function that given a node will return that node as is or transformed along with an error, if any.
type TreePrinter ¶
type TreePrinter struct {
// contains filtered or unexported fields
}
TreePrinter is a printer for tree nodes.
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, error) fmt.Stringer }
Type represent a SQL type.
func MysqlTypeToType ¶
MysqlTypeToType gets the column type using the mysql type
func UnderlyingType ¶
UnderlyingType returns the underlying type of an array if the type is an array, or the type itself in any other case.
type TypedValue ¶
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.