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

feat: add "HISTOGRAM" option in "ALTER TABLE... UPDATE/DROP..." #925

Merged
merged 2 commits into from
Sep 2, 2020
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
39 changes: 39 additions & 0 deletions ast/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type AnalyzeTableStmt struct {
// IndexFlag is true when we only analyze indices for a table.
IndexFlag bool
Incremental bool
// HistogramOperation is set in "ANALYZE TABLE ... UPDATE/DROP HISTOGRAM ..." statement.
HistogramOperation HistogramOperationType
ColumnNames []*ColumnName
}

// AnalyzeOptType is the type for analyze options.
Expand All @@ -60,6 +63,28 @@ var AnalyzeOptionString = map[AnalyzeOptionType]string{
AnalyzeOptNumSamples: "SAMPLES",
}

// HistogramOperationType is the type for histogram operation.
type HistogramOperationType int

// Histogram operation types.
const (
// HistogramOperationNop shows no operation in histogram. Default value.
HistogramOperationNop HistogramOperationType = iota
HistogramOperationUpdate
HistogramOperationDrop
)

// String implements fmt.Stringer for HistogramOperationType.
func (hot HistogramOperationType) String() string {
switch hot {
case HistogramOperationUpdate:
return "UPDATE HISTOGRAM"
case HistogramOperationDrop:
return "DROP HISTOGRAM"
}
return ""
}

// AnalyzeOpt stores the analyze option type and value.
type AnalyzeOpt struct {
Type AnalyzeOptionType
Expand Down Expand Up @@ -90,6 +115,20 @@ func (n *AnalyzeTableStmt) Restore(ctx *format.RestoreCtx) error {
}
ctx.WriteName(partition.O)
}
if n.HistogramOperation != HistogramOperationNop {
ctx.WritePlain(" ")
ctx.WriteKeyWord(n.HistogramOperation.String())
ctx.WritePlain(" ")
}
if len(n.ColumnNames) > 0 {
ctx.WriteKeyWord("ON ")
for i, columnName := range n.ColumnNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(columnName.Name.O)
}
}
if n.IndexFlag {
ctx.WriteKeyWord(" INDEX")
}
Expand Down
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ var tokenMap = map[string]int{
"HAVING": having,
"HIGH_PRIORITY": highPriority,
"HISTORY": history,
"HISTOGRAM": histogram,
"HOSTS": hosts,
"HOUR_MICROSECOND": hourMicrosecond,
"HOUR_MINUTE": hourMinute,
Expand Down
Loading