From c4de3c06253dcb61e620582befde0b761d004219 Mon Sep 17 00:00:00 2001 From: hustjieke Date: Thu, 12 Nov 2020 12:11:49 +0800 Subject: [PATCH] sqlparser: move lock and algorithm option to ast_funcs.go #693 --- .../xelabs/go-mysqlstack/sqlparser/ast.go | 57 +----------------- .../go-mysqlstack/sqlparser/ast_funcs.go | 58 ++++++++++++++++++- .../go-mysqlstack/sqlparser/rewriter.go | 14 ----- 3 files changed, 58 insertions(+), 71 deletions(-) diff --git a/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go b/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go index b8cf639b..d69208c3 100644 --- a/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go +++ b/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go @@ -300,67 +300,12 @@ type IndexDefinition struct { Unique bool } +// IndexLockAndAlgorithm describes lock and algorithm type in index type IndexLockAndAlgorithm struct { LockOption LockOptionType AlgorithmOption AlgorithmOptionType } -// LockType is the type for create/drop/alter index TableSpec. -// See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html#alter-table-concurrency -type LockOptionType byte - -// Lock options. -const ( - LockOptionEmpty LockOptionType = iota + 1 - LockOptionNone - LockOptionDefault - LockOptionShared - LockOptionExclusive -) - -func (n LockOptionType) String() string { - switch n { - case LockOptionNone: - return "none" - case LockOptionDefault: - return "default" - case LockOptionShared: - return "shared" - case LockOptionExclusive: - return "exclusive" - default: - return "" - } -} - -// AlgorithmType is the algorithm for create/drop/alter index TableSpec. -// See https://dev.mysql.com/doc/refman/8.0/en/alter-table.html#alter-table-performance. -type AlgorithmOptionType byte - -// Algorithms options. -const ( - AlgorithmOptionEmpty AlgorithmOptionType = iota - AlgorithmOptionDefault - AlgorithmOptionCopy - AlgorithmOptionInplace - AlgorithmOptionInstant -) - -func (a AlgorithmOptionType) String() string { - switch a { - case AlgorithmOptionDefault: - return "default" - case AlgorithmOptionCopy: - return "copy" - case AlgorithmOptionInplace: - return "inplace" - case AlgorithmOptionInstant: - return "instant" - default: - return "" - } -} - // TableSpec describes the structure of a table from a CREATE TABLE statement type TableSpec struct { Columns []*ColumnDefinition diff --git a/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast_funcs.go b/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast_funcs.go index 90cadfbb..8b3b2ec3 100644 --- a/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast_funcs.go +++ b/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast_funcs.go @@ -327,7 +327,7 @@ type PartitionDefinition struct { type PartitionDefinitions []*PartitionDefinition type ( - // PartitionOption interface。 + // PartitionOption interface. PartitionOption interface { PartitionType() string } @@ -441,6 +441,62 @@ func NewIndexOptions(columns []*IndexColumn, idxOptList []*IndexOption) *IndexOp return idxOpts } +// LockType is the type for create/drop/alter index TableSpec. +// See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html#alter-table-concurrency +type LockOptionType byte + +// Lock options. +const ( + LockOptionEmpty LockOptionType = iota + 1 + LockOptionNone + LockOptionDefault + LockOptionShared + LockOptionExclusive +) + +func (n LockOptionType) String() string { + switch n { + case LockOptionNone: + return "none" + case LockOptionDefault: + return "default" + case LockOptionShared: + return "shared" + case LockOptionExclusive: + return "exclusive" + default: + return "" + } +} + +// AlgorithmType is the algorithm for create/drop/alter index TableSpec. +// See https://dev.mysql.com/doc/refman/8.0/en/alter-table.html#alter-table-performance. +type AlgorithmOptionType byte + +// Algorithms options. +const ( + AlgorithmOptionEmpty AlgorithmOptionType = iota + AlgorithmOptionDefault + AlgorithmOptionCopy + AlgorithmOptionInplace + AlgorithmOptionInstant +) + +func (a AlgorithmOptionType) String() string { + switch a { + case AlgorithmOptionDefault: + return "default" + case AlgorithmOptionCopy: + return "copy" + case AlgorithmOptionInplace: + return "inplace" + case AlgorithmOptionInstant: + return "instant" + default: + return "" + } +} + // AddColumn appends the given column to the list in the spec func (ts *TableSpec) AddColumn(cd *ColumnDefinition) { ts.Columns = append(ts.Columns, cd) diff --git a/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/rewriter.go b/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/rewriter.go index c7354ba2..4b2fb794 100644 --- a/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/rewriter.go +++ b/src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/rewriter.go @@ -286,14 +286,6 @@ func (r *replaceIndexHintsIndexes) inc() { *r++ } -func replaceIndexLockAndAlgorithmAlgorithmOption(newNode, parent SQLNode) { - parent.(*IndexLockAndAlgorithm).AlgorithmOption = newNode.(AlgorithmOptionType) -} - -func replaceIndexLockAndAlgorithmLockOption(newNode, parent SQLNode) { - parent.(*IndexLockAndAlgorithm).LockOption = newNode.(LockOptionType) -} - func replaceIndexOptionsBlockSize(newNode, parent SQLNode) { parent.(*IndexOptions).BlockSize = newNode.(*SQLVal) } @@ -709,8 +701,6 @@ func (a *application) apply(parent, node SQLNode, replacer replacerFunc) { // (the order of the cases is alphabetical) switch n := node.(type) { case nil: - case AlgorithmOptionType: - case *AliasedExpr: a.apply(node, n.As, replaceAliasedExprAs) a.apply(node, n.Expr, replaceAliasedExprExpr) @@ -857,8 +847,6 @@ func (a *application) apply(parent, node SQLNode, replacer replacerFunc) { } case *IndexLockAndAlgorithm: - a.apply(node, n.AlgorithmOption, replaceIndexLockAndAlgorithmAlgorithmOption) - a.apply(node, n.LockOption, replaceIndexLockAndAlgorithmLockOption) case *IndexOptions: a.apply(node, n.BlockSize, replaceIndexOptionsBlockSize) @@ -889,8 +877,6 @@ func (a *application) apply(parent, node SQLNode, replacer replacerFunc) { case ListArg: - case LockOptionType: - case *MatchExpr: a.apply(node, n.Columns, replaceMatchExprColumns) a.apply(node, n.Expr, replaceMatchExprExpr)