Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: quick fix the panic issue when restoring hints from a plan #48682

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion planner/core/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func getJoinHints(sctx sessionctx.Context, joinType string, parentOffset int, no
}
var dbName, tableName *model.CIStr
if blockOffset != parentOffset {
blockAsNames := *(sctx.GetSessionVars().PlannerSelectBlockAsName.Load())
var blockAsNames []ast.HintTable
if p := sctx.GetSessionVars().PlannerSelectBlockAsName.Load(); p != nil {
blockAsNames = *p
}
if blockOffset >= len(blockAsNames) {
continue
}
Expand Down
5 changes: 4 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ func extractTableAlias(p Plan, parentOffset int) *hintTableInfo {
}
}
blockOffset := p.SelectBlockOffset()
blockAsNames := *(p.SCtx().GetSessionVars().PlannerSelectBlockAsName.Load())
var blockAsNames []ast.HintTable
if p := p.SCtx().GetSessionVars().PlannerSelectBlockAsName.Load(); p != nil {
blockAsNames = *p
}
// For sub-queries like `(select * from t) t1`, t1 should belong to its surrounding select block.
if blockOffset != parentOffset && blockAsNames != nil && blockAsNames[blockOffset].TableName.L != "" {
blockOffset = parentOffset
Expand Down
5 changes: 4 additions & 1 deletion planner/core/rule_join_reorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ func (s *baseSingleGroupJoinOrderSolver) generateLeadingJoinGroup(curJoinGroup [
var leadingJoinGroup []LogicalPlan
leftJoinGroup := make([]LogicalPlan, len(curJoinGroup))
copy(leftJoinGroup, curJoinGroup)
queryBlockNames := *(s.ctx.GetSessionVars().PlannerSelectBlockAsName.Load())
var queryBlockNames []ast.HintTable
if p := s.ctx.GetSessionVars().PlannerSelectBlockAsName.Load(); p != nil {
queryBlockNames = *p
}
for _, hintTbl := range hintInfo.leadingJoinOrder {
match := false
for i, joinGroup := range leftJoinGroup {
Expand Down