Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Nov 8, 2024
1 parent 8cab56f commit 07869e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 18 additions & 0 deletions pkg/bindinfo/binding_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pingcap/tidb/pkg/bindinfo/norm"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/util/hint"
)
Expand Down Expand Up @@ -138,6 +139,7 @@ func CollectTableNames(in ast.Node) []*ast.TableName {
collector := tableNameCollectorPool.Get().(*tableNameCollector)
defer func() {
collector.tableNames = nil
collector.asName = nil
tableNameCollectorPool.Put(collector)
}()
in.Accept(collector)
Expand All @@ -152,20 +154,36 @@ var tableNameCollectorPool = sync.Pool{

type tableNameCollector struct {
tableNames []*ast.TableName
asName []model.CIStr
}

func newCollectTableName() *tableNameCollector {
return &tableNameCollector{
tableNames: make([]*ast.TableName, 0, 4),
asName: make([]model.CIStr, 0, 2),
}
}

// Enter implements Visitor interface.
func (c *tableNameCollector) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
if node, ok := in.(*ast.TableSource); ok {
if node.AsName.L != "" {
c.asName = append(c.asName, node.AsName)
}
return in, true
}
if node, ok := in.(*ast.TableName); ok {
if node.AsOf == nil && node.Schema.L == "" {
for _, asName := range c.asName {
if asName.L == node.Name.L {
//node.IsAlias = true
}
}
}
c.tableNames = append(c.tableNames, node)
return in, true
}

return in, false
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/parser/ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ type TableName struct {
PartitionNames []model.CIStr
TableSample *TableSample
// AS OF is used to see the data as it was at a specific point in time.
AsOf *AsOfClause
AsOf *AsOfClause
IsAlias bool
}

func (*TableName) resultSet() {}
Expand Down Expand Up @@ -330,7 +331,9 @@ func (n *TableName) restoreIndexHints(ctx *format.RestoreCtx) error {
}

func (n *TableName) Restore(ctx *format.RestoreCtx) error {
n.restoreName(ctx)
if !n.IsAlias {
n.restoreName(ctx)
}
n.restorePartitions(ctx)
if err := n.restoreIndexHints(ctx); err != nil {
return err
Expand Down

0 comments on commit 07869e3

Please sign in to comment.