Skip to content

Prepare statement panic when query block not found in hint #46817

@jackysp

Description

@jackysp

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (i int);
prepare stmt from 'with a as (select /*+ qb_name(qb1) */ * from t)  select /*+ leading(@qb1)*/ * from a;'

2. What did you expect to see? (Required)

No panic

3. What did you see instead (Required)

SQL panic

github.com/pingcap/tidb/server.(*clientConn).Run.func1
    /Users/yusp/work/tidb/server/conn.go:1090
runtime.gopanic
    /usr/local/go/src/runtime/panic.go:914
github.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1
    /Users/yusp/work/tidb/executor/adapter.go:453
runtime.gopanic
    /usr/local/go/src/runtime/panic.go:914
runtime.panicmem
    /usr/local/go/src/runtime/panic.go:261
runtime.sigpanic
    /usr/local/go/src/runtime/signal_unix.go:861
github.com/pingcap/tidb/util/hint.(*BlockHintProcessor).GetCurrentStmtHints
    /Users/yusp/work/tidb/util/hint/hint_processor.go:599
github.com/pingcap/tidb/planner/core.(*PlanBuilder).pushTableHints
    /Users/yusp/work/tidb/planner/core/logical_plan_builder.go:3578
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildSelect
    /Users/yusp/work/tidb/planner/core/logical_plan_builder.go:3823
github.com/pingcap/tidb/planner/core.(*PlanBuilder).Build
    /Users/yusp/work/tidb/planner/core/planbuilder.go:804
github.com/pingcap/tidb/planner/core.GeneratePlanCacheStmtWithAST
    /Users/yusp/work/tidb/planner/core/plan_cache_utils.go:141
github.com/pingcap/tidb/executor.(*PrepareExec).Next
    /Users/yusp/work/tidb/executor/prepared.go:120
github.com/pingcap/tidb/executor.Next
    /Users/yusp/work/tidb/executor/executor.go:328
github.com/pingcap/tidb/executor.(*ExecStmt).next
    /Users/yusp/work/tidb/executor/adapter.go:1154
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor
    /Users/yusp/work/tidb/executor/adapter.go:927
github.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelay
    /Users/yusp/work/tidb/executor/adapter.go:776
github.com/pingcap/tidb/executor.(*ExecStmt).Exec
    /Users/yusp/work/tidb/executor/adapter.go:571
github.com/pingcap/tidb/session.runStmt
    /Users/yusp/work/tidb/session/session.go:2373
github.com/pingcap/tidb/session.(*session).ExecuteStmt
    /Users/yusp/work/tidb/session/session.go:2237
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
    /Users/yusp/work/tidb/server/driver_tidb.go:252
github.com/pingcap/tidb/server.(*clientConn).handleStmt
    /Users/yusp/work/tidb/server/conn.go:2122
github.com/pingcap/tidb/server.(*clientConn).handleQuery
    /Users/yusp/work/tidb/server/conn.go:1972
github.com/pingcap/tidb/server.(*clientConn).dispatch
    /Users/yusp/work/tidb/server/conn.go:1403
github.com/pingcap/tidb/server.(*clientConn).Run
    /Users/yusp/work/tidb/server/conn.go:1152
github.com/pingcap/tidb/server.(*Server).onConn
    /Users/yusp/work/tidb/server/server.go:648

4. What is your TiDB version? (Required)

d3d30f5 and v6.5.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.found/gsfound by gsseverity/moderatesig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions