Skip to content

Commit

Permalink
Fix CREATE INDEX .. VISIBLE/INVISIBLE syntax (pingcap#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz authored and leoppro committed Aug 26, 2019
1 parent 6514d93 commit ea6c3ad
Show file tree
Hide file tree
Showing 4 changed files with 7,235 additions and 7,153 deletions.
25 changes: 24 additions & 1 deletion ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,16 @@ func (n *ColumnOption) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// IndexVisibility is the option for index visibility.
type IndexVisibility int

// IndexVisibility options.
const (
IndexVisibilityDefault IndexVisibility = iota
IndexVisibilityVisible
IndexVisibilityInvisible
)

// IndexOption is the index options.
// KEY_BLOCK_SIZE [=] value
// | index_type
Expand All @@ -560,6 +570,7 @@ type IndexOption struct {
KeyBlockSize uint64
Tp model.IndexType
Comment string
Visibility IndexVisibility
}

// Restore implements Node interface.
Expand Down Expand Up @@ -587,6 +598,18 @@ func (n *IndexOption) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("COMMENT ")
ctx.WriteString(n.Comment)
}

if n.Visibility != IndexVisibilityDefault {
if hasPrevOption {
ctx.WritePlain(" ")
}
switch n.Visibility {
case IndexVisibilityVisible:
ctx.WriteKeyWord("VISIBLE")
case IndexVisibilityInvisible:
ctx.WriteKeyWord("INVISIBLE")
}
}
return nil
}

Expand Down Expand Up @@ -1312,7 +1335,7 @@ func (n *CreateIndexStmt) Restore(ctx *RestoreCtx) error {
}
ctx.WritePlain(")")

if n.IndexOption.Tp != model.IndexTypeInvalid || n.IndexOption.KeyBlockSize > 0 || n.IndexOption.Comment != "" {
if n.IndexOption.Tp != model.IndexTypeInvalid || n.IndexOption.KeyBlockSize > 0 || n.IndexOption.Comment != "" || n.IndexOption.Visibility != IndexVisibilityDefault {
ctx.WritePlain(" ")
if err := n.IndexOption.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore CreateIndexStmt.IndexOption")
Expand Down
2 changes: 2 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ var tokenMap = map[string]int{
"INTERVAL": interval,
"INTERNAL": internal,
"INTO": into,
"INVISIBLE": invisible,
"INVOKER": invoker,
"IS": is,
"ISSUER": issuer,
Expand Down Expand Up @@ -639,6 +640,7 @@ var tokenMap = map[string]int{
"VAR_SAMP": varSamp,
"VIEW": view,
"VIRTUAL": virtual,
"VISIBLE": visible,
"WARNINGS": warnings,
"ERRORS": identSQLErrors,
"WEEK": week,
Expand Down
Loading

0 comments on commit ea6c3ad

Please sign in to comment.