Skip to content

Commit

Permalink
feat: add "HISTOGRAM" option in "ALTER TABLE... UPDATE/DROP..." (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
wangggong authored Sep 2, 2020
1 parent b4c39b9 commit 969f72e
Show file tree
Hide file tree
Showing 5 changed files with 8,467 additions and 8,369 deletions.
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

0 comments on commit 969f72e

Please sign in to comment.