Skip to content

Commit

Permalink
planner: fix potential panic when generating hints in statement summa…
Browse files Browse the repository at this point in the history
…ry (#46312) (#46393)

close #46311
  • Loading branch information
ti-chi-bot authored Aug 24, 2023
1 parent b19b65c commit a52c366
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ func (b *PlanBuilder) buildResultSetNode(ctx context.Context, node ast.ResultSet
}
}
// `TableName` is not a select block, so we do not need to handle it.
if !isTableName && b.ctx.GetSessionVars().PlannerSelectBlockAsName.Load() != nil {
plannerSelectBlockAsName := *(b.ctx.GetSessionVars().PlannerSelectBlockAsName.Load())
if plannerSelectBlockAsName := *(b.ctx.GetSessionVars().PlannerSelectBlockAsName.Load()); len(plannerSelectBlockAsName) > 0 && !isTableName {
plannerSelectBlockAsName[p.SelectBlockOffset()] = ast.HintTable{DBName: p.OutputNames()[0].DBName, TableName: p.OutputNames()[0].TblName}
}
// Duplicate column name in one table is not allowed.
Expand Down
2 changes: 1 addition & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func NewPlanBuilder(opts ...PlanBuilderOpt) *PlanBuilder {
func (b *PlanBuilder) Init(sctx sessionctx.Context, is infoschema.InfoSchema, processor *hint.BlockHintProcessor) (*PlanBuilder, []ast.HintTable) {
savedBlockNames := sctx.GetSessionVars().PlannerSelectBlockAsName.Load()
if processor == nil {
sctx.GetSessionVars().PlannerSelectBlockAsName.Store(nil)
sctx.GetSessionVars().PlannerSelectBlockAsName.Store(&[]ast.HintTable{})
} else {
newPlannerSelectBlockAsName := make([]ast.HintTable, processor.MaxSelectStmtOffset()+1)
sctx.GetSessionVars().PlannerSelectBlockAsName.Store(&newPlannerSelectBlockAsName)
Expand Down

0 comments on commit a52c366

Please sign in to comment.