github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/sqlparse/tidbparser/ast/stats.go (about)

     1  // Copyright 2017 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package ast
    15  
    16  import "github.com/bingoohuang/gg/pkg/sqlparse/tidbparser/dependency/model"
    17  
    18  var (
    19  	_ StmtNode = &AnalyzeTableStmt{}
    20  	_ StmtNode = &DropStatsStmt{}
    21  	_ StmtNode = &LoadStatsStmt{}
    22  )
    23  
    24  // AnalyzeTableStmt is used to create table statistics.
    25  type AnalyzeTableStmt struct {
    26  	stmtNode
    27  
    28  	TableNames []*TableName
    29  	IndexNames []model.CIStr
    30  
    31  	// IndexFlag is true when we only analyze indices for a table.
    32  	IndexFlag bool
    33  }
    34  
    35  // Accept implements Node Accept interface.
    36  func (n *AnalyzeTableStmt) Accept(v Visitor) (Node, bool) {
    37  	newNode, skipChildren := v.Enter(n)
    38  	if skipChildren {
    39  		return v.Leave(newNode)
    40  	}
    41  	n = newNode.(*AnalyzeTableStmt)
    42  	for i, val := range n.TableNames {
    43  		node, ok := val.Accept(v)
    44  		if !ok {
    45  			return n, false
    46  		}
    47  		n.TableNames[i] = node.(*TableName)
    48  	}
    49  	return v.Leave(n)
    50  }
    51  
    52  // DropStatsStmt is used to drop table statistics.
    53  type DropStatsStmt struct {
    54  	stmtNode
    55  
    56  	Table *TableName
    57  }
    58  
    59  // Accept implements Node Accept interface.
    60  func (n *DropStatsStmt) Accept(v Visitor) (Node, bool) {
    61  	newNode, skipChildren := v.Enter(n)
    62  	if skipChildren {
    63  		return v.Leave(newNode)
    64  	}
    65  	n = newNode.(*DropStatsStmt)
    66  	node, ok := n.Table.Accept(v)
    67  	if !ok {
    68  		return n, false
    69  	}
    70  	n.Table = node.(*TableName)
    71  	return v.Leave(n)
    72  }
    73  
    74  // LoadStatsStmt is the statement node for loading statistic.
    75  type LoadStatsStmt struct {
    76  	stmtNode
    77  
    78  	Path string
    79  }
    80  
    81  // Accept implements Node Accept interface.
    82  func (n *LoadStatsStmt) Accept(v Visitor) (Node, bool) {
    83  	newNode, skipChildren := v.Enter(n)
    84  	if skipChildren {
    85  		return v.Leave(newNode)
    86  	}
    87  	n = newNode.(*LoadStatsStmt)
    88  	return v.Leave(n)
    89  }