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

hint: fix panic when query block not found in prepare statement (#46818) #46842

Merged
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: 5 additions & 0 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func TestPreparedStmtWithHint(t *testing.T) {
go dom.ExpensiveQueryHandle().SetSessionManager(sv).Run()
tk.MustExec("prepare stmt from \"select /*+ max_execution_time(100) */ sleep(10)\"")
tk.MustQuery("execute stmt").Check(testkit.Rows("1"))

// see https://github.com/pingcap/tidb/issues/46817
tk.MustExec("use test")
tk.MustExec("create table if not exists t (i int)")
tk.MustExec("prepare stmt from 'with a as (select /*+ qb_name(qb1) */ * from t) select /*+ leading(@qb1)*/ * from a;'")
}

func TestPreparedNullParam(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions util/hint/hint_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,10 @@ func (p *BlockHintProcessor) GetCurrentStmtHints(hints []*ast.TableOptimizerHint
}
offset := p.GetHintOffset(hint.QBName, currentOffset)
if offset < 0 || !p.checkTableQBName(hint.Tables) {
hintStr := RestoreTableOptimizerHint(hint)
p.Ctx.GetSessionVars().StmtCtx.AppendWarning(fmt.Errorf("Hint %s is ignored due to unknown query block name", hintStr))
if p.Ctx != nil {
hintStr := RestoreTableOptimizerHint(hint)
p.Ctx.GetSessionVars().StmtCtx.AppendWarning(fmt.Errorf("Hint %s is ignored due to unknown query block name", hintStr))
}
continue
}
p.QbHints[offset] = append(p.QbHints[offset], hint)
Expand Down