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

CTE query execute failed: type assertion for CTEStorageMap failed #46522

Closed
knull-cn opened this issue Aug 30, 2023 · 7 comments · Fixed by #49399
Closed

CTE query execute failed: type assertion for CTEStorageMap failed #46522

knull-cn opened this issue Aug 30, 2023 · 7 comments · Fixed by #49399
Labels
affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 found/gs found by gs report/customer Customers have encountered this bug. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/regression

Comments

@knull-cn
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

run cte-query

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

run success and no error

3. What did you see instead (Required)

run failed and stack info

4. What is your TiDB version? (Required)

v6.5.3

@knull-cn knull-cn added the type/bug The issue is confirmed as a bug. label Aug 30, 2023
@knull-cn
Copy link
Contributor Author

knull-cn commented Aug 30, 2023

here is the stack error information:

[err="type assertion for CTEStorageMap failed
github.com/pingcap/tidb/executor.(*executorBuilder).buildCTE
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:5140
github.com/pingcap/tidb/executor.(*executorBuilder).build
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:308
github.com/pingcap/tidb/executor.(*executorBuilder).buildIndexLookUpJoin
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:3059
github.com/pingcap/tidb/executor.(*executorBuilder).buildIndexNestedLoopHashJoin
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:3289
github.com/pingcap/tidb/executor.(*executorBuilder).build
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:262
github.com/pingcap/tidb/executor.(*executorBuilder).buildProjection
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:1686
github.com/pingcap/tidb/executor.(*executorBuilder).build
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:270
github.com/pingcap/tidb/executor.(*executorBuilder).buildInsert
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:867
github.com/pingcap/tidb/executor.(*executorBuilder).build
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:200
github.com/pingcap/tidb/executor.(*ExecStmt).buildExecutor
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:1110
github.com/pingcap/tidb/executor.(*ExecStmt).Exec
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:513
github.com/pingcap/tidb/session.(*session).retry
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:1286
github.com/pingcap/tidb/session.(*session).doCommitWithRetry
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:1008
github.com/pingcap/tidb/session.(*session).CommitTxn
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:1114
github.com/pingcap/tidb/session.autoCommitAfterStmt
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/tidb.go:282
github.com/pingcap/tidb/session.finishStmt
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/tidb.go:248
github.com/pingcap/tidb/session.runStmt
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:2392
github.com/pingcap/tidb/session.(*session).ExecuteStmt
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:2237
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/driver_tidb.go:252
github.com/pingcap/tidb/server.(*clientConn).handleStmt
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2122
github.com/pingcap/tidb/server.(*clientConn).handleQuery
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1972
github.com/pingcap/tidb/server.(*clientConn).dispatch
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1403
github.com/pingcap/tidb/server.(*clientConn).Run
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1152
github.com/pingcap/tidb/server.(*Server).onConn
    /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/server.go:648
runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1594"]

@ti-chi-bot ti-chi-bot bot added may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Aug 30, 2023
@tiancaiamao
Copy link
Contributor

What's the SQL and table schema? @knull-cn

@seiya-annie
Copy link

/found gs

@ti-chi-bot ti-chi-bot bot added the found/gs found by gs label Sep 20, 2023
@jebter
Copy link

jebter commented Sep 21, 2023

/label affects-6.5

@tiancaiamao
Copy link
Contributor

From @jackysp

diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go
index d5f19e8fe6..e0c167f08c 100644
--- a/sessionctx/stmtctx/stmtctx.go
+++ b/sessionctx/stmtctx/stmtctx.go
@@ -22,6 +22,7 @@ import (
        "sync/atomic"
        "time"
 
+       "github.com/pingcap/tidb/executor"
        "github.com/pingcap/tidb/parser"
        "github.com/pingcap/tidb/parser/ast"
        "github.com/pingcap/tidb/parser/model"
@@ -703,6 +704,7 @@ func (sc *StatementContext) resetMuForRetry() {
 // ResetForRetry resets the changed states during execution.
 func (sc *StatementContext) ResetForRetry() {
        sc.resetMuForRetry()
+       sc.CTEStorageMap = map[int]*executor.CTEStorages{}
        sc.MaxRowID = 0
        sc.BaseRowID = 0
        sc.TableIDs = sc.TableIDs[:0] 

@tiancaiamao
Copy link
Contributor

The root cause is that if the CTE run to commit and auto retry, it rebuild the executor, but the sctx.CTEStorageMap was reset already, so this time it assert fail.

@seiya-annie
Copy link

/found customer

@ti-chi-bot ti-chi-bot bot added the report/customer Customers have encountered this bug. label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 affects-7.1 affects-7.5 found/gs found by gs report/customer Customers have encountered this bug. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants