使用CTE递归查询出现[HY000][1105] runtime error: invalid memory address or nil pointer dereference

【 TiDB 使用环境】生产环境
【 TiDB 版本】6.1.1
遇到的问题:
使用 CTE递归查询出现[HY000][1105] runtime error: invalid memory address or nil pointer dereference错误

tidb错误日志:
[2025/01/07 16:34:58.478 +08:00] [ERROR] [conn.go:1056] [“connection running loop panic”] [conn=5015268358472348285] [lastSQL=“/* ApplicationName=DataGrip 2024.3.3 */ WITH RECURSIVE parent_dictionary(id, kv_key) AS\r\n (\r\n – 初始查询:找到根节点\r\n SELECT id, kv_key\r\n FROM hotel_kv\r\n WHERE id = 1 – 替换为你要查询的根节点ID\r\n UNION ALL\r\n – 递归查询:找到所有父节点\r\n SELECT d.id, d.kv_key\r\n FROM hotel_kv d\r\n INNER JOIN parent_dictionary pd ON d.kv_key = pd.kv_key\r\n )\r\n SELECT * FROM parent_dictionary”] [err=“runtime error: invalid memory address or nil pointer dereference”] [stack=“github.com/pingcap/tidb/server.(*clientConn).Run.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1059\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:838\nruntime.panicmem\n\t/usr/local/go/src/runtime/panic.go:220\nruntime.sigpanic\n\t/usr/local/go/src/runtime/signal_unix.go:818\ngithub.com/pingcap/tidb/executor.getDbFromResultNode\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:311\ngithub.com/pingcap/tidb/executor.getDbFromResultNode\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:305\ngithub.com/pingcap/tidb/executor.getDbFromResultNode\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:314\ngithub.com/pingcap/tidb/executor.getDbFromResultNode\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:308\ngithub.com/pingcap/tidb/executor.getStmtDbLabel\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:227\ngithub.com/pingcap/tidb/executor.CountStmtNode\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:187\ngithub.com/pingcap/tidb/executor.(*Compiler).Compile\n\t/home/jenkins/agen
t/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:90\ngithub.com/pingcap/tidb/session.(*session).ExecuteStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:1916\ngithub.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/driver_tidb.go:230\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2022\ngithub.com/pingcap/tidb/server.(*clientConn).handleQuery\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1876\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1371\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1121\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/server.go:559”]

这个错误提示表明在程序运行时发生了空指针引用或者访问了无效的内存地址
检查下否存在空值,重复值
SELECT * FROM hotel_kv WHERE id IS NULL;
SELECT * FROM hotel_kv WHERE kv_key IS NULL;
SELECT id, COUNT() FROM hotel_kv GROUP BY id HAVING COUNT() > 1;
SELECT kv_key, COUNT() FROM hotel_kv GROUP BY kv_key HAVING COUNT() > 1;

id和kv_key 没有空值,kv_key是有重复值,这是根据kv_key进行上下级关联的

升级后未出现问题

是通过升级已经解决了嘛?

我刚想说可能是低版本的bug。

是通过升级解决了

1 个赞

此话题已在最后回复的 7 天后被自动关闭。不再允许新回复。