Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CREATE INDEX .. VISIBLE/INVISIBLE syntax #518

Merged
merged 6 commits into from
Aug 26, 2019
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