Skip to content

Commit

Permalink
parser: add ANALYZE TABLE t ALL COLUMNS syntax (#29361)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyifangreeneyes authored Nov 10, 2021
1 parent 4cee7a3 commit 17edc57
Show file tree
Hide file tree
Showing 5 changed files with 5,675 additions and 5,651 deletions.
15 changes: 9 additions & 6 deletions parser/ast/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ type AnalyzeTableStmt struct {
// HistogramOperation is set in "ANALYZE TABLE ... UPDATE/DROP HISTOGRAM ..." statement.
HistogramOperation HistogramOperationType
// ColumnNames indicate the columns whose statistics need to be collected.
ColumnNames []*ColumnName
// PredicateColumns is true when we only collect statistics of predicate columns and indexed columns.
PredicateColumns bool
ColumnNames []*ColumnName
ColumnChoice model.ColumnChoice
}

// AnalyzeOptType is the type for analyze options.
Expand Down Expand Up @@ -133,16 +132,20 @@ func (n *AnalyzeTableStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteName(columnName.Name.O)
}
}
} else if len(n.ColumnNames) > 0 {
}
switch n.ColumnChoice {
case model.AllColumns:
ctx.WriteKeyWord(" ALL COLUMNS")
case model.PredicateColumns:
ctx.WriteKeyWord(" PREDICATE COLUMNS")
case model.ColumnList:
ctx.WriteKeyWord(" COLUMNS ")
for i, columnName := range n.ColumnNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(columnName.Name.O)
}
} else if n.PredicateColumns {
ctx.WriteKeyWord(" PREDICATE COLUMNS")
}
if n.IndexFlag {
ctx.WriteKeyWord(" INDEX")
Expand Down
5 changes: 3 additions & 2 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ type StatsOptions struct {
func NewStatsOptions() *StatsOptions {
return &StatsOptions{
AutoRecalc: true,
ColumnChoice: AllColumns,
ColumnChoice: DefaultChoice,
ColumnList: []CIStr{},
SampleNum: uint64(0),
SampleRate: 0.0,
Expand All @@ -1262,7 +1262,8 @@ func NewStatsOptions() *StatsOptions {
type ColumnChoice byte

const (
AllColumns ColumnChoice = iota
DefaultChoice ColumnChoice = iota
AllColumns
PredicateColumns
ColumnList
)
Expand Down
Loading

0 comments on commit 17edc57

Please sign in to comment.