Skip to content

Commit

Permalink
parser: analyze predicate/user-specified columns and show column_stat…
Browse files Browse the repository at this point in the history
…s_usage (#28846)
  • Loading branch information
xuyifangreeneyes authored Oct 18, 2021
1 parent 39d5f8e commit fce1a03
Show file tree
Hide file tree
Showing 6 changed files with 9,366 additions and 9,240 deletions.
6 changes: 6 additions & 0 deletions parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,7 @@ const (
ShowStatsTopN
ShowStatsBuckets
ShowStatsHealthy
ShowColumnStatsUsage
ShowPlugins
ShowProfile
ShowProfiles
Expand Down Expand Up @@ -2765,6 +2766,11 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
if err := restoreShowLikeOrWhereOpt(); err != nil {
return err
}
case ShowColumnStatsUsage:
ctx.WriteKeyWord("COLUMN_STATS_USAGE")
if err := restoreShowLikeOrWhereOpt(); err != nil {
return err
}
case ShowProfiles:
ctx.WriteKeyWord("PROFILES")
case ShowProfile:
Expand Down
21 changes: 17 additions & 4 deletions parser/ast/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ type AnalyzeTableStmt struct {
Incremental bool
// HistogramOperation is set in "ANALYZE TABLE ... UPDATE/DROP HISTOGRAM ..." statement.
HistogramOperation HistogramOperationType
ColumnNames []*ColumnName
// 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
}

// AnalyzeOptType is the type for analyze options.
Expand Down Expand Up @@ -119,15 +122,25 @@ func (n *AnalyzeTableStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WritePlain(" ")
ctx.WriteKeyWord(n.HistogramOperation.String())
ctx.WritePlain(" ")
}
if len(n.ColumnNames) > 0 {
ctx.WriteKeyWord("ON ")
if len(n.ColumnNames) > 0 {
ctx.WriteKeyWord("ON ")
for i, columnName := range n.ColumnNames {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WriteName(columnName.Name.O)
}
}
} else if len(n.ColumnNames) > 0 {
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
2 changes: 2 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ var tokenMap = map[string]int{
"COLLATE": collate,
"COLLATION": collation,
"COLUMN_FORMAT": columnFormat,
"COLUMN_STATS_USAGE": columnStatsUsage,
"COLUMN": column,
"COLUMNS": columns,
"COMMENT": comment,
Expand Down Expand Up @@ -537,6 +538,7 @@ var tokenMap = map[string]int{
"POSITION": position,
"PRE_SPLIT_REGIONS": preSplitRegions,
"PRECEDING": preceding,
"PREDICATE": predicate,
"PRECISION": precisionType,
"PREPARE": prepare,
"PRESERVE": preserve,
Expand Down
Loading

0 comments on commit fce1a03

Please sign in to comment.