Skip to content

Commit

Permalink
planner: speed up PhysicalTopN#containVirtualColumn (#46812)
Browse files Browse the repository at this point in the history
close #46809
  • Loading branch information
tedyu authored Sep 11, 2023
1 parent d3d30f5 commit 262327f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,14 +1115,18 @@ func (p *PhysicalTopN) canExpressionConvertedToPB(storeTp kv.StoreType) bool {

// containVirtualColumn checks whether TopN.ByItems contains virtual generated columns.
func (p *PhysicalTopN) containVirtualColumn(tCols []*expression.Column) bool {
tColSet := make(map[int64]struct{}, len(tCols))
for _, tCol := range tCols {
if tCol.ID > 0 && tCol.VirtualExpr != nil {
tColSet[tCol.ID] = struct{}{}
}
}
for _, by := range p.ByItems {
cols := expression.ExtractColumns(by.Expr)
for _, col := range cols {
for _, tCol := range tCols {
if _, ok := tColSet[col.ID]; ok {
// A column with ID > 0 indicates that the column can be resolved by data source.
if tCol.ID > 0 && tCol.ID == col.ID && tCol.VirtualExpr != nil {
return true
}
return true
}
}
}
Expand Down

0 comments on commit 262327f

Please sign in to comment.