Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ type IndexOption struct {
Visibility IndexVisibility
PrimaryKeyTp model.PrimaryKeyType
Global bool
Condition ExprNode `json:"-"` // Condition contains expr nodes, which cannot marshal for DDL job arguments. It's used for partial index.
}

// IsEmpty is true if only default options are given
Expand All @@ -746,7 +747,8 @@ func (n *IndexOption) IsEmpty() bool {
len(n.ParserName.O) > 0 ||
n.Comment != "" ||
n.Global ||
n.Visibility != IndexVisibilityDefault {
n.Visibility != IndexVisibilityDefault ||
n.Condition != nil {
return false
}
return true
Expand Down Expand Up @@ -819,7 +821,19 @@ func (n *IndexOption) Restore(ctx *format.RestoreCtx) error {
case IndexVisibilityInvisible:
ctx.WriteKeyWord("INVISIBLE")
}
hasPrevOption = true
}

if n.Condition != nil {
if hasPrevOption {
ctx.WritePlain(" ")
}
ctx.WriteKeyWord("WHERE ")
if err := n.Condition.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing IndexOption Condition")
}
}

return nil
}

Expand Down
Loading