diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 2dd2e4aa038e5..d1682145ab56f 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -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. diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 7c1cc87c32cd1..853c85e98c317 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -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)