Skip to content

Commit 448b92a

Browse files
authoredJan 21, 2025··
planner: avoid slicesgrow in the buildDataSource (#58853)
close #58842
1 parent a6ab103 commit 448b92a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
 

‎pkg/planner/core/logical_plan_builder.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4594,6 +4594,7 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
45944594
}
45954595
}
45964596
}
4597+
countCnt := len(columns) + 1 // +1 for an extra handle column
45974598
ds := logicalop.DataSource{
45984599
DBName: dbName,
45994600
TableAsName: asName,
@@ -4604,16 +4605,16 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
46044605
IndexHints: b.TableHints().IndexHintList,
46054606
IndexMergeHints: indexMergeHints,
46064607
PossibleAccessPaths: possiblePaths,
4607-
Columns: make([]*model.ColumnInfo, 0, len(columns)),
4608+
Columns: make([]*model.ColumnInfo, 0, countCnt),
46084609
PartitionNames: tn.PartitionNames,
4609-
TblCols: make([]*expression.Column, 0, len(columns)),
4610+
TblCols: make([]*expression.Column, 0, countCnt),
46104611
PreferPartitions: make(map[int][]ast.CIStr),
46114612
IS: b.is,
46124613
IsForUpdateRead: b.isForUpdateRead,
46134614
}.Init(b.ctx, b.getSelectOffset())
46144615
var handleCols util.HandleCols
4615-
schema := expression.NewSchema(make([]*expression.Column, 0, len(columns))...)
4616-
names := make([]*types.FieldName, 0, len(columns))
4616+
schema := expression.NewSchema(make([]*expression.Column, 0, countCnt)...)
4617+
names := make([]*types.FieldName, 0, countCnt)
46174618
for i, col := range columns {
46184619
ds.Columns = append(ds.Columns, col.ToInfo())
46194620
names = append(names, &types.FieldName{

0 commit comments

Comments
 (0)
Please sign in to comment.