Skip to content

Commit

Permalink
planner: fix early set of plan's statisticsTable (#30754)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysan committed Dec 16, 2021
1 parent af259fa commit 5d62c2a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
7 changes: 1 addition & 6 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4052,11 +4052,6 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
} else {
columns = tbl.Cols()
}
var statisticTable *statistics.Table
if _, ok := tbl.(table.PartitionedTable); !ok || b.ctx.GetSessionVars().UseDynamicPartitionPrune() {
statisticTable = getStatsTable(b.ctx, tbl.Meta(), tbl.Meta().ID)
}

// extract the IndexMergeHint
var indexMergeHints []indexHintInfo
if hints := b.TableHints(); hints != nil {
Expand Down Expand Up @@ -4101,7 +4096,7 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
TableAsName: asName,
table: tbl,
tableInfo: tableInfo,
statisticTable: statisticTable,
physicalTableID: tableInfo.ID,
astIndexHints: tn.IndexHints,
IndexHints: b.TableHints().indexHintList,
indexMergeHints: indexMergeHints,
Expand Down
3 changes: 0 additions & 3 deletions planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,6 @@ func (s *partitionProcessor) makeUnionAllChildren(ds *DataSource, pi *model.Part
// id as FromID. So we set the id of the newDataSource with the original one to
// avoid traversing the whole plan tree to update the references.
newDataSource.id = ds.id
if !ds.ctx.GetSessionVars().UseDynamicPartitionPrune() {
newDataSource.statisticTable = getStatsTable(ds.SCtx(), ds.table.Meta(), pi.Definitions[i].ID)
}
err := s.resolveOptimizeHint(&newDataSource, pi.Definitions[i].Name)
partitionNameSet.Insert(pi.Definitions[i].Name.L)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (ds *DataSource) initStats(colGroups [][]*expression.Column) {
return
}
if ds.statisticTable == nil {
ds.statisticTable = getStatsTable(ds.ctx, ds.tableInfo, ds.table.Meta().ID)
ds.statisticTable = getStatsTable(ds.ctx, ds.tableInfo, ds.physicalTableID)
}
tableStats := &property.StatsInfo{
RowCount: float64(ds.statisticTable.Count),
Expand Down

0 comments on commit 5d62c2a

Please sign in to comment.