model

package
v3.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FlagIgnoreTruncate indicates if truncate error should be ignored.
	// Read-only statements should ignore truncate error, write statements should not ignore truncate error.
	FlagIgnoreTruncate uint64 = 1
	// FlagTruncateAsWarning indicates if truncate error should be returned as warning.
	// This flag only matters if FlagIgnoreTruncate is not set, in strict sql mode, truncate error should
	// be returned as error, in non-strict sql mode, truncate error should be saved as warning.
	FlagTruncateAsWarning = 1 << 1
	// FlagPadCharToFullLength indicates if sql_mode 'PAD_CHAR_TO_FULL_LENGTH' is set.
	FlagPadCharToFullLength = 1 << 2
	// FlagInInsertStmt indicates if this is a INSERT statement.
	FlagInInsertStmt = 1 << 3
	// FlagInUpdateOrDeleteStmt indicates if this is a UPDATE statement or a DELETE statement.
	FlagInUpdateOrDeleteStmt = 1 << 4
	// FlagInSelectStmt indicates if this is a SELECT statement.
	FlagInSelectStmt = 1 << 5
	// FlagOverflowAsWarning indicates if overflow error should be returned as warning.
	// In strict sql mode, overflow error should be returned as error,
	// in non-strict sql mode, overflow error should be saved as warning.
	FlagOverflowAsWarning = 1 << 6
	// FlagIgnoreZeroInDate indicates if ZeroInDate error should be ignored.
	// Read-only statements should ignore ZeroInDate error.
	// Write statements should not ignore ZeroInDate error in strict sql mode.
	FlagIgnoreZeroInDate = 1 << 7
	// FlagDividedByZeroAsWarning indicates if DividedByZero should be returned as warning.
	FlagDividedByZeroAsWarning = 1 << 8
)

Flags are used by tipb.SelectRequest.Flags to handle execution mode, like how to handle truncate error.

View Source
const AddIndexStr = "add index"

AddIndexStr is a string related to the operation of "add index".

View Source
const ExtraHandleID = -1

ExtraHandleID is the column ID of column which we need to append to schema to occupy the handle's position for use of execution phase.

Variables

View Source
var ExtraHandleName = NewCIStr("_tidb_rowid")

ExtraHandleName is the name of ExtraHandle Column.

Functions

func ColumnToProto

func ColumnToProto(c *ColumnInfo) *tipb.ColumnInfo

ColumnToProto converts model.ColumnInfo to tipb.ColumnInfo.

func ColumnsToProto

func ColumnsToProto(columns []*ColumnInfo, pkIsHandle bool) []*tipb.ColumnInfo

ColumnsToProto converts a slice of model.ColumnInfo to a slice of tipb.ColumnInfo.

func IndexToProto

func IndexToProto(t *TableInfo, idx *IndexInfo) *tipb.IndexInfo

IndexToProto converts a model.IndexInfo to a tipb.IndexInfo.

func TSConvert2Time

func TSConvert2Time(ts uint64) time.Time

TSConvert2Time converts timestamp to time.

Types

type ActionType

type ActionType byte

ActionType is the type for DDL action.

const (
	ActionNone                         ActionType = 0
	ActionCreateSchema                 ActionType = 1
	ActionDropSchema                   ActionType = 2
	ActionCreateTable                  ActionType = 3
	ActionDropTable                    ActionType = 4
	ActionAddColumn                    ActionType = 5
	ActionDropColumn                   ActionType = 6
	ActionAddIndex                     ActionType = 7
	ActionDropIndex                    ActionType = 8
	ActionAddForeignKey                ActionType = 9
	ActionDropForeignKey               ActionType = 10
	ActionTruncateTable                ActionType = 11
	ActionModifyColumn                 ActionType = 12
	ActionRebaseAutoID                 ActionType = 13
	ActionRenameTable                  ActionType = 14
	ActionSetDefaultValue              ActionType = 15
	ActionShardRowID                   ActionType = 16
	ActionModifyTableComment           ActionType = 17
	ActionRenameIndex                  ActionType = 18
	ActionAddTablePartition            ActionType = 19
	ActionDropTablePartition           ActionType = 20
	ActionCreateView                   ActionType = 21
	ActionModifyTableCharsetAndCollate ActionType = 22
	ActionTruncateTablePartition       ActionType = 23
	ActionDropView                     ActionType = 24
	ActionRestoreTable                 ActionType = 25
)

List DDL actions.

func (ActionType) String

func (action ActionType) String() string

String return current ddl action in string

type CIStr

type CIStr struct {
	O string `json:"O"` // Original string.
	L string `json:"L"` // Lower case string.
}

CIStr is case insensitive string.

func NewCIStr

func NewCIStr(s string) (cs CIStr)

NewCIStr creates a new CIStr.

func (CIStr) String

func (cis CIStr) String() string

String implements fmt.Stringer interface.

func (*CIStr) UnmarshalJSON

func (cis *CIStr) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the user defined unmarshal method. CIStr can be unmarshaled from a single string, so PartitionDefinition.Name in this change https://github.com/pingcap/tidb/pull/6460/files would be compatible during TiDB upgrading.

type ColumnInfo

type ColumnInfo struct {
	ID                  int64               `json:"id"`
	Name                CIStr               `json:"name"`
	Offset              int                 `json:"offset"`
	OriginDefaultValue  interface{}         `json:"origin_default"`
	DefaultValue        interface{}         `json:"default"`
	DefaultValueBit     []byte              `json:"default_bit"`
	GeneratedExprString string              `json:"generated_expr_string"`
	GeneratedStored     bool                `json:"generated_stored"`
	Dependences         map[string]struct{} `json:"dependences"`
	types.FieldType     `json:"type"`
	State               SchemaState `json:"state"`
	Comment             string      `json:"comment"`
}

ColumnInfo provides meta data describing of a table column.

func FindColumnInfo

func FindColumnInfo(cols []*ColumnInfo, name string) *ColumnInfo

FindColumnInfo finds ColumnInfo in cols by name.

func NewExtraHandleColInfo

func NewExtraHandleColInfo() *ColumnInfo

NewExtraHandleColInfo mocks a column info for extra handle column.

func (*ColumnInfo) Clone

func (c *ColumnInfo) Clone() *ColumnInfo

Clone clones ColumnInfo.

func (*ColumnInfo) GetDefaultValue

func (c *ColumnInfo) GetDefaultValue() interface{}

GetDefaultValue gets the default value of the column. Default value use to stored in DefaultValue field, but now, bit type default value will store in DefaultValueBit for fix bit default value decode/encode bug.

func (*ColumnInfo) IsGenerated

func (c *ColumnInfo) IsGenerated() bool

IsGenerated returns true if the column is generated column.

func (*ColumnInfo) SetDefaultValue

func (c *ColumnInfo) SetDefaultValue(value interface{}) error

SetDefaultValue sets the default value.

type DBInfo

type DBInfo struct {
	ID      int64        `json:"id"`      // Database ID
	Name    CIStr        `json:"db_name"` // DB name.
	Charset string       `json:"charset"`
	Collate string       `json:"collate"`
	Tables  []*TableInfo `json:"-"` // Tables in the DB.
	State   SchemaState  `json:"state"`
}

DBInfo provides meta data describing a DB.

func (*DBInfo) Clone

func (db *DBInfo) Clone() *DBInfo

Clone clones DBInfo.

func (*DBInfo) Copy

func (db *DBInfo) Copy() *DBInfo

Copy shallow copies DBInfo.

type DDLReorgMeta

type DDLReorgMeta struct {
	// EndHandle is the last handle of the adding indices table.
	// We should only backfill indices in the range [startHandle, EndHandle].
	EndHandle int64 `json:"end_handle"`
}

DDLReorgMeta is meta info of DDL reorganization.

func NewDDLReorgMeta

func NewDDLReorgMeta() *DDLReorgMeta

NewDDLReorgMeta new a DDLReorgMeta.

type FKInfo

type FKInfo struct {
	ID       int64       `json:"id"`
	Name     CIStr       `json:"fk_name"`
	RefTable CIStr       `json:"ref_table"`
	RefCols  []CIStr     `json:"ref_cols"`
	Cols     []CIStr     `json:"cols"`
	OnDelete int         `json:"on_delete"`
	OnUpdate int         `json:"on_update"`
	State    SchemaState `json:"state"`
}

FKInfo provides meta data describing a foreign key constraint.

func (*FKInfo) Clone

func (fk *FKInfo) Clone() *FKInfo

Clone clones FKInfo.

type HistoryInfo

type HistoryInfo struct {
	SchemaVersion int64
	DBInfo        *DBInfo
	TableInfo     *TableInfo
	FinishedTS    uint64
}

HistoryInfo is used for binlog.

func (*HistoryInfo) AddDBInfo

func (h *HistoryInfo) AddDBInfo(schemaVer int64, dbInfo *DBInfo)

AddDBInfo adds schema version and schema information that are used for binlog. dbInfo is added in the following operations: create database, drop database.

func (*HistoryInfo) AddTableInfo

func (h *HistoryInfo) AddTableInfo(schemaVer int64, tblInfo *TableInfo)

AddTableInfo adds schema version and table information that are used for binlog. tblInfo is added except for the following operations: create database, drop database.

func (*HistoryInfo) Clean

func (h *HistoryInfo) Clean()

Clean cleans history information.

type IndexColumn

type IndexColumn struct {
	Name   CIStr `json:"name"`   // Index name
	Offset int   `json:"offset"` // Index offset
	// Length of prefix when using column prefix
	// for indexing;
	// UnspecifedLength if not using prefix indexing
	Length int `json:"length"`
}

IndexColumn provides index column info.

func (*IndexColumn) Clone

func (i *IndexColumn) Clone() *IndexColumn

Clone clones IndexColumn.

type IndexInfo

type IndexInfo struct {
	ID      int64          `json:"id"`
	Name    CIStr          `json:"idx_name"`   // Index name.
	Table   CIStr          `json:"tbl_name"`   // Table name.
	Columns []*IndexColumn `json:"idx_cols"`   // Index columns.
	Unique  bool           `json:"is_unique"`  // Whether the index is unique.
	Primary bool           `json:"is_primary"` // Whether the index is primary key.
	State   SchemaState    `json:"state"`
	Comment string         `json:"comment"`    // Comment
	Tp      IndexType      `json:"index_type"` // Index type: Btree or Hash
}

IndexInfo provides meta data describing a DB index. It corresponds to the statement `CREATE INDEX Name ON Table (Column);` See https://dev.mysql.com/doc/refman/5.7/en/create-index.html

func (*IndexInfo) Clone

func (index *IndexInfo) Clone() *IndexInfo

Clone clones IndexInfo.

func (*IndexInfo) HasPrefixIndex

func (index *IndexInfo) HasPrefixIndex() bool

HasPrefixIndex returns whether any columns of this index uses prefix length.

type IndexType

type IndexType int

IndexType is the type of index

const (
	IndexTypeInvalid IndexType = iota
	IndexTypeBtree
	IndexTypeHash
)

IndexTypes

func (IndexType) String

func (t IndexType) String() string

String implements Stringer interface.

type Job

type Job struct {
	ID       int64         `json:"id"`
	Type     ActionType    `json:"type"`
	SchemaID int64         `json:"schema_id"`
	TableID  int64         `json:"table_id"`
	State    JobState      `json:"state"`
	Error    *terror.Error `json:"err"`
	// ErrorCount will be increased, every time we meet an error when running job.
	ErrorCount int64 `json:"err_count"`
	// RowCount means the number of rows that are processed.
	RowCount int64         `json:"row_count"`
	Mu       sync.Mutex    `json:"-"`
	Args     []interface{} `json:"-"`
	// RawArgs : We must use json raw message to delay parsing special args.
	RawArgs     json.RawMessage `json:"raw_args"`
	SchemaState SchemaState     `json:"schema_state"`
	// SnapshotVer means snapshot version for this job.
	SnapshotVer uint64 `json:"snapshot_ver"`
	// StartTS uses timestamp allocated by TSO.
	// Now it's the TS when we put the job to TiKV queue.
	StartTS uint64 `json:"start_ts"`
	// DependencyID is the job's ID that the current job depends on.
	DependencyID int64 `json:"dependency_id"`
	// Query string of the ddl job.
	Query      string       `json:"query"`
	BinlogInfo *HistoryInfo `json:"binlog"`

	// Version indicates the DDL job version. For old jobs, it will be 0.
	Version int64 `json:"version"`

	// ReorgMeta is meta info of ddl reorganization.
	// This field is depreciated.
	ReorgMeta *DDLReorgMeta `json:"reorg_meta"`

	// Priority is only used to set the operation priority of adding indices.
	Priority int `json:"priority"`
}

Job is for a DDL operation.

func (*Job) Decode

func (job *Job) Decode(b []byte) error

Decode decodes job from the json buffer, we must use DecodeArgs later to decode special args for this job.

func (*Job) DecodeArgs

func (job *Job) DecodeArgs(args ...interface{}) error

DecodeArgs decodes job args.

func (*Job) Encode

func (job *Job) Encode(updateRawArgs bool) ([]byte, error)

Encode encodes job with json format. updateRawArgs is used to determine whether to update the raw args.

func (*Job) FinishDBJob

func (job *Job) FinishDBJob(jobState JobState, schemaState SchemaState, ver int64, dbInfo *DBInfo)

FinishDBJob is called when a job is finished. It updates the job's state information and adds dbInfo the binlog.

func (*Job) FinishTableJob

func (job *Job) FinishTableJob(jobState JobState, schemaState SchemaState, ver int64, tblInfo *TableInfo)

FinishTableJob is called when a job is finished. It updates the job's state information and adds tblInfo to the binlog.

func (*Job) GetRowCount

func (job *Job) GetRowCount() int64

GetRowCount gets the number of rows. Make sure it can pass `make race`.

func (*Job) IsCancelled

func (job *Job) IsCancelled() bool

IsCancelled returns whether the job is cancelled or not.

func (*Job) IsCancelling

func (job *Job) IsCancelling() bool

IsCancelling returns whether the job is cancelling or not.

func (*Job) IsDependentOn

func (job *Job) IsDependentOn(other *Job) (bool, error)

IsDependentOn returns whether the job depends on "other". How to check the job depends on "other"? 1. The two jobs handle the same database when one of the two jobs is an ActionDropSchema or ActionCreateSchema type. 2. Or the two jobs handle the same table.

func (*Job) IsDone

func (job *Job) IsDone() bool

IsDone returns whether job is done.

func (*Job) IsFinished

func (job *Job) IsFinished() bool

IsFinished returns whether job is finished or not. If the job state is Done or Cancelled, it is finished.

func (*Job) IsRollbackDone

func (job *Job) IsRollbackDone() bool

IsRollbackDone returns whether the job is rolled back or not.

func (*Job) IsRollingback

func (job *Job) IsRollingback() bool

IsRollingback returns whether the job is rolling back or not.

func (*Job) IsRunning

func (job *Job) IsRunning() bool

IsRunning returns whether job is still running or not.

func (*Job) IsSynced

func (job *Job) IsSynced() bool

IsSynced returns whether the DDL modification is synced among all TiDB servers.

func (*Job) SetRowCount

func (job *Job) SetRowCount(count int64)

SetRowCount sets the number of rows. Make sure it can pass `make race`.

func (*Job) String

func (job *Job) String() string

String implements fmt.Stringer interface.

type JobState

type JobState byte

JobState is for job state.

const (
	JobStateNone    JobState = 0
	JobStateRunning JobState = 1
	// When DDL encountered an unrecoverable error at reorganization state,
	// some keys has been added already, we need to remove them.
	// JobStateRollingback is the state to do the rolling back job.
	JobStateRollingback  JobState = 2
	JobStateRollbackDone JobState = 3
	JobStateDone         JobState = 4
	JobStateCancelled    JobState = 5
	// JobStateSynced is used to mark the information about the completion of this job
	// has been synchronized to all servers.
	JobStateSynced JobState = 6
	// JobStateCancelling is used to mark the DDL job is cancelled by the client, but the DDL work hasn't handle it.
	JobStateCancelling JobState = 7
)

List job states.

func (JobState) String

func (s JobState) String() string

String implements fmt.Stringer interface.

type PartitionDefinition

type PartitionDefinition struct {
	ID       int64    `json:"id"`
	Name     CIStr    `json:"name"`
	LessThan []string `json:"less_than"`
	Comment  string   `json:"comment,omitempty"`
}

PartitionDefinition defines a single partition.

type PartitionInfo

type PartitionInfo struct {
	Type    PartitionType `json:"type"`
	Expr    string        `json:"expr"`
	Columns []CIStr       `json:"columns"`

	// User may already creates table with partition but table partition is not
	// yet supported back then. When Enable is true, write/read need use tid
	// rather than pid.
	Enable bool `json:"enable"`

	Definitions []PartitionDefinition `json:"definitions"`
	Num         uint64                `json:"num"`
}

PartitionInfo provides table partition info.

func (*PartitionInfo) GetNameByID

func (pi *PartitionInfo) GetNameByID(id int64) string

GetNameByID gets the partition name by ID.

type PartitionType

type PartitionType int

PartitionType is the type for PartitionInfo

const (
	PartitionTypeRange PartitionType = 1
	PartitionTypeHash  PartitionType = 2
	PartitionTypeList  PartitionType = 3
)

Partition types.

func (PartitionType) String

func (p PartitionType) String() string

type SchemaDiff

type SchemaDiff struct {
	Version  int64      `json:"version"`
	Type     ActionType `json:"type"`
	SchemaID int64      `json:"schema_id"`
	TableID  int64      `json:"table_id"`

	// OldTableID is the table ID before truncate, only used by truncate table DDL.
	OldTableID int64 `json:"old_table_id"`
	// OldSchemaID is the schema ID before rename table, only used by rename table DDL.
	OldSchemaID int64 `json:"old_schema_id"`
}

SchemaDiff contains the schema modification at a particular schema version. It is used to reduce schema reload cost.

type SchemaState

type SchemaState byte

SchemaState is the state for schema elements.

const (
	// StateNone means this schema element is absent and can't be used.
	StateNone SchemaState = iota
	// StateDeleteOnly means we can only delete items for this schema element.
	StateDeleteOnly
	// StateWriteOnly means we can use any write operation on this schema element,
	// but outer can't read the changed data.
	StateWriteOnly
	// StateWriteReorganization means we are re-organizing whole data after write only state.
	StateWriteReorganization
	// StateDeleteReorganization means we are re-organizing whole data after delete only state.
	StateDeleteReorganization
	// StatePublic means this schema element is ok for all write and read operations.
	StatePublic
)

func (SchemaState) String

func (s SchemaState) String() string

String implements fmt.Stringer interface.

type TableColumnID

type TableColumnID struct {
	TableID  int64
	ColumnID int64
}

TableColumnID is composed by table ID and column ID.

type TableInfo

type TableInfo struct {
	ID      int64  `json:"id"`
	Name    CIStr  `json:"name"`
	Charset string `json:"charset"`
	Collate string `json:"collate"`
	// Columns are listed in the order in which they appear in the schema.
	Columns     []*ColumnInfo `json:"cols"`
	Indices     []*IndexInfo  `json:"index_info"`
	ForeignKeys []*FKInfo     `json:"fk_info"`
	State       SchemaState   `json:"state"`
	PKIsHandle  bool          `json:"pk_is_handle"`
	Comment     string        `json:"comment"`
	AutoIncID   int64         `json:"auto_inc_id"`
	MaxColumnID int64         `json:"max_col_id"`
	MaxIndexID  int64         `json:"max_idx_id"`
	// UpdateTS is used to record the timestamp of updating the table's schema information.
	// These changing schema operations don't include 'truncate table' and 'rename table'.
	UpdateTS uint64 `json:"update_timestamp"`
	// OldSchemaID :
	// Because auto increment ID has schemaID as prefix,
	// We need to save original schemaID to keep autoID unchanged
	// while renaming a table from one database to another.
	// TODO: Remove it.
	// Now it only uses for compatibility with the old version that already uses this field.
	OldSchemaID int64 `json:"old_schema_id,omitempty"`

	// ShardRowIDBits specify if the implicit row ID is sharded.
	ShardRowIDBits uint64

	Partition *PartitionInfo `json:"partition"`

	Compression string `json:"compression"`

	View *ViewInfo `json:"view"`
}

TableInfo provides meta data describing a DB table.

func (*TableInfo) Clone

func (t *TableInfo) Clone() *TableInfo

Clone clones TableInfo.

func (*TableInfo) Cols

func (t *TableInfo) Cols() []*ColumnInfo

Cols returns the columns of the table in public state.

func (*TableInfo) ColumnIsInIndex

func (t *TableInfo) ColumnIsInIndex(c *ColumnInfo) bool

ColumnIsInIndex checks whether c is included in any indices of t.

func (*TableInfo) GetAutoIncrementColInfo

func (t *TableInfo) GetAutoIncrementColInfo() *ColumnInfo

func (*TableInfo) GetDBID

func (t *TableInfo) GetDBID(dbID int64) int64

GetDBID returns the schema ID that is used to create an allocator. TODO: Remove it after removing OldSchemaID.

func (*TableInfo) GetPartitionInfo

func (t *TableInfo) GetPartitionInfo() *PartitionInfo

GetPartitionInfo returns the partition information.

func (*TableInfo) GetPkColInfo

func (t *TableInfo) GetPkColInfo() *ColumnInfo

GetPkColInfo gets the ColumnInfo of pk if exists. Make sure PkIsHandle checked before call this method.

func (*TableInfo) GetPkName

func (t *TableInfo) GetPkName() CIStr

GetPkName will return the pk name if pk exists.

func (*TableInfo) GetUpdateTime

func (t *TableInfo) GetUpdateTime() time.Time

GetUpdateTime gets the table's updating time.

func (*TableInfo) IsAutoIncColUnsigned

func (t *TableInfo) IsAutoIncColUnsigned() bool

func (*TableInfo) IsView

func (t *TableInfo) IsView() bool

IsView checks if tableinfo is a view

type ViewAlgorithm

type ViewAlgorithm int

ViewAlgorithm is VIEW's SQL AlGORITHM characteristic. See https://dev.mysql.com/doc/refman/5.7/en/view-algorithms.html

const (
	AlgorithmUndefined ViewAlgorithm = iota
	AlgorithmMerge
	AlgorithmTemptable
)

func (*ViewAlgorithm) String

func (v *ViewAlgorithm) String() string

type ViewCheckOption

type ViewCheckOption int

ViewCheckOption is VIEW's WITH CHECK OPTION clause part. See https://dev.mysql.com/doc/refman/5.7/en/view-check-option.html

const (
	CheckOptionLocal ViewCheckOption = iota
	CheckOptionCascaded
)

func (*ViewCheckOption) String

func (v *ViewCheckOption) String() string

type ViewInfo

type ViewInfo struct {
	Algorithm   ViewAlgorithm      `json:"view_algorithm"`
	Definer     *auth.UserIdentity `json:"view_definer"`
	Security    ViewSecurity       `json:"view_security"`
	SelectStmt  string             `json:"view_select"`
	CheckOption ViewCheckOption    `json:"view_checkoption"`
	Cols        []CIStr            `json:"view_cols"`
}

ViewInfo provides meta data describing a DB view.

type ViewSecurity

type ViewSecurity int

ViewSecurity is VIEW's SQL SECURITY characteristic. See https://dev.mysql.com/doc/refman/5.7/en/create-view.html

const (
	SecurityDefiner ViewSecurity = iota
	SecurityInvoker
)

func (*ViewSecurity) String

func (v *ViewSecurity) String() string

Jump to

Keyboard shortcuts

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