Skip to content

Commit

Permalink
parser : Add model & errcode & errname for supporting sequence. (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
AilinKid authored Dec 19, 2019
1 parent 2ff1335 commit a8449c9
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 28 deletions.
37 changes: 36 additions & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ type TableInfo struct {
Compression string `json:"compression"`

View *ViewInfo `json:"view"`

Sequence *SequenceInfo `json:"sequence"`

// Lock represent the table lock info.
Lock *TableLockInfo `json:"Lock"`

Expand Down Expand Up @@ -499,11 +502,16 @@ func (t *TableInfo) ColumnIsInIndex(c *ColumnInfo) bool {
return false
}

// IsView checks if tableinfo is a view
// IsView checks if TableInfo is a view.
func (t *TableInfo) IsView() bool {
return t.View != nil
}

// IsSequence checks if TableInfo is a sequence.
func (t *TableInfo) IsSequence() bool {
return t.Sequence != nil
}

// ViewAlgorithm is VIEW's SQL AlGORITHM characteristic.
// See https://dev.mysql.com/doc/refman/5.7/en/view-algorithms.html
type ViewAlgorithm int
Expand Down Expand Up @@ -577,6 +585,33 @@ type ViewInfo struct {
Cols []CIStr `json:"view_cols"`
}

const (
DefaultSequenceCacheBool = true
DefaultSequenceCycleBool = false
DefaultSequenceOrderBool = false
DefaultSequenceCacheValue = int64(1000)
DefaultSequenceIncrementValue = int64(1)
DefaultPositiveSequenceStartValue = int64(1)
DefaultNegativeSequenceStartValue = int64(-1)
DefaultPositiveSequenceMinValue = int64(1)
DefaultPositiveSequenceMaxValue = int64(9223372036854775806)
DefaultNegativeSequenceMaxValue = int64(-1)
DefaultNegativeSequenceMinValue = int64(-9223372036854775807)
)

// SequenceInfo provide meta data describing a DB sequence.
type SequenceInfo struct {
Start int64 `json:"sequence_start"`
Cache bool `json:"sequence_cache"`
Order bool `json:"sequence_order"`
Cycle bool `json:"sequence_cycle"`
MinValue int64 `json:"sequence_min_value"`
MaxValue int64 `json:"sequence_max_value"`
Increment int64 `json:"sequence_increment"`
CacheValue int64 `json:"sequence_cache_value"`
Comment string `json:"sequence_comment"`
}

// PartitionType is the type for PartitionInfo
type PartitionType int

Expand Down
13 changes: 13 additions & 0 deletions model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (*testModelSuite) TestModelBasic(c *C) {
Cols: []CIStr{NewCIStr("a")},
}

seq := &SequenceInfo{
Increment: 1,
MinValue: 1,
MaxValue: 100,
}

table := &TableInfo{
ID: 1,
Name: NewCIStr("t"),
Expand All @@ -81,6 +87,12 @@ func (*testModelSuite) TestModelBasic(c *C) {
PKIsHandle: true,
}

table2 := &TableInfo{
ID: 2,
Name: NewCIStr("s"),
Sequence: seq,
}

dbInfo := &DBInfo{
ID: 1,
Name: NewCIStr("test"),
Expand Down Expand Up @@ -109,6 +121,7 @@ func (*testModelSuite) TestModelBasic(c *C) {
c.Assert(has, Equals, true)
t := table.GetUpdateTime()
c.Assert(t, Equals, TSConvert2Time(table.UpdateTS))
c.Assert(table2.IsSequence(), Equals, true)

// Corner cases
column.Flag ^= mysql.PriKeyFlag
Expand Down
62 changes: 35 additions & 27 deletions mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,13 @@ const (
ErrOnlyOneDefaultPartionAllowed = 4030
ErrWrongPartitionTypeExpectedSystemTime = 4113
ErrSystemVersioningWrongPartitions = 4128
ErrSequenceRunOut = 4135
ErrSequenceInvalidData = 4136
ErrSequenceAccessFail = 4137
ErrNotSequence = 4138
ErrUnknownSequence = 4139
ErrWrongInsertIntoSequence = 4140
ErrSequenceInvalidTableStructure = 4141

// TiDB self-defined errors.
ErrMemExceedThreshold = 8001
Expand Down Expand Up @@ -1022,33 +1029,34 @@ const (
ErrInvalidType = 8057

// Error codes used by TiDB ddl package
ErrUnsupportedDDLOperation = 8200
ErrNotOwner = 8201
ErrCantDecodeIndex = 8202
ErrInvalidDDLWorker = 8203
ErrInvalidDDLJob = 8204
ErrInvalidDDLJobFlag = 8205
ErrWaitReorgTimeout = 8206
ErrInvalidStoreVersion = 8207
ErrUnknownTypeLength = 8208
ErrUnknownFractionLength = 8209
ErrInvalidDDLState = 8210
ErrReorgPanic = 8211
ErrInvalidSplitRegionRanges = 8212
ErrInvalidDDLJobVersion = 8213
ErrCancelledDDLJob = 8214
ErrRepairTable = 8215
ErrInvalidAutoRandom = 8216
ErrInvalidHashKeyFlag = 8217
ErrInvalidListIndex = 8218
ErrInvalidListMetaData = 8219
ErrWriteOnSnapshot = 8220
ErrInvalidKey = 8221
ErrInvalidIndexKey = 8222
ErrDataInConsistent = 8223
ErrDDLJobNotFound = 8224
ErrCancelFinishedDDLJob = 8225
ErrCannotCancelDDLJob = 8226
ErrUnsupportedDDLOperation = 8200
ErrNotOwner = 8201
ErrCantDecodeIndex = 8202
ErrInvalidDDLWorker = 8203
ErrInvalidDDLJob = 8204
ErrInvalidDDLJobFlag = 8205
ErrWaitReorgTimeout = 8206
ErrInvalidStoreVersion = 8207
ErrUnknownTypeLength = 8208
ErrUnknownFractionLength = 8209
ErrInvalidDDLState = 8210
ErrReorgPanic = 8211
ErrInvalidSplitRegionRanges = 8212
ErrInvalidDDLJobVersion = 8213
ErrCancelledDDLJob = 8214
ErrRepairTable = 8215
ErrInvalidAutoRandom = 8216
ErrInvalidHashKeyFlag = 8217
ErrInvalidListIndex = 8218
ErrInvalidListMetaData = 8219
ErrWriteOnSnapshot = 8220
ErrInvalidKey = 8221
ErrInvalidIndexKey = 8222
ErrDataInConsistent = 8223
ErrDDLJobNotFound = 8224
ErrCancelFinishedDDLJob = 8225
ErrCannotCancelDDLJob = 8226
ErrSequenceUnsupportedTableOption = 8227

// TiKV/PD errors.
ErrPDServerTimeout = 9001
Expand Down
8 changes: 8 additions & 0 deletions mysql/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,13 @@ var MySQLErrName = map[uint16]string{
ErrOnlyOneDefaultPartionAllowed: "Only one DEFAULT partition allowed",
ErrWrongPartitionTypeExpectedSystemTime: "Wrong partitioning type, expected type: `SYSTEM_TIME`",
ErrSystemVersioningWrongPartitions: "Wrong Partitions: must have at least one HISTORY and exactly one last CURRENT",
ErrSequenceRunOut: "Sequence '%-.64s.%-.64s' has run out",
ErrSequenceInvalidData: "Sequence '%-.64s.%-.64s' values are conflicting",
ErrSequenceAccessFail: "Sequence '%-.64s.%-.64s' access error",
ErrNotSequence: "'%-.64s.%-.64s' is not a SEQUENCE",
ErrUnknownSequence: "Unknown SEQUENCE: '%-.300s'",
ErrWrongInsertIntoSequence: "Wrong INSERT into a SEQUENCE. One can only do single table INSERT into a sequence object (like with mysqldump). If you want to change the SEQUENCE, use ALTER SEQUENCE instead.",
ErrSequenceInvalidTableStructure: "Sequence '%-.64s.%-.64s' table structure is invalid (%s)",

// TiDB errors.
ErrMemExceedThreshold: "%s holds %dB memory, exceeds threshold %dB.%s",
Expand Down Expand Up @@ -1029,6 +1036,7 @@ var MySQLErrName = map[uint16]string{
ErrCancelFinishedDDLJob: "This job:%v is finished, so can't be cancelled",
ErrCannotCancelDDLJob: "This job:%v is almost finished, can't be cancelled now",

ErrSequenceUnsupportedTableOption: "Unsupported sequence table-option %s",
ErrUnsupportedType: "Unsupported type %T",
ErrAnalyzeMissIndex: "Index '%s' in field list does not exist in table '%s'",
ErrCartesianProductUnsupported: "Cartesian product is unsupported",
Expand Down

0 comments on commit a8449c9

Please sign in to comment.