Repository navigation
TiDB:runtime error: invalid memory address or nil pointer dereference #65867
Description
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
This table always being ‘inset’and 'delete' , and suddenly the following error popped up:
mysql> select * from ACT_RU_VARIABLE where task_id_='1997872469436538880';
ERROR 1105 (HY000): runtime error: invalid memory address or nil pointer dereference
It recovers after doing the steps below, but the issue keeps coming back frequently.
DROP INDEX ACT_IDX_VARIABLE_TASK_ID ON ACT_RU_VARIABLE;
CREATE INDEX ACT_IDX_VARIABLE_TASK_ID ON ACT_RU_VARIABLE(TASK_ID_);
table info and field :
CREATE TABLE `ACT_RU_VARIABLE` (
`ID_` varchar(64) NOT NULL,
`REV_` int DEFAULT NULL,
`TYPE_` varchar(255) NOT NULL,
`NAME_` varchar(255) NOT NULL,
`EXECUTION_ID_` varchar(64) DEFAULT NULL,
`PROC_INST_ID_` varchar(64) DEFAULT NULL,
`TASK_ID_` varchar(64) DEFAULT NULL,
`SCOPE_ID_` varchar(255) DEFAULT NULL,
`SUB_SCOPE_ID_` varchar(255) DEFAULT NULL,
`SCOPE_TYPE_` varchar(255) DEFAULT NULL,
`BYTEARRAY_ID_` varchar(64) DEFAULT NULL,
`DOUBLE_` double DEFAULT NULL,
`LONG_` bigint DEFAULT NULL,
`TEXT_` varchar(4000) DEFAULT NULL,
`TEXT2_` varchar(4000) DEFAULT NULL,
`META_INFO_` varchar(4000) DEFAULT NULL,
PRIMARY KEY (`ID_`) /*T![clustered_index] CLUSTERED */,
KEY `ACT_IDX_RU_VAR_SCOPE_ID_TYPE` (`SCOPE_ID_`,`SCOPE_TYPE_`),
KEY `ACT_IDX_RU_VAR_SUB_ID_TYPE` (`SUB_SCOPE_ID_`,`SCOPE_TYPE_`),
KEY `ACT_IDX_VARIABLE_TASK_ID` (`TASK_ID_`),
KEY `ACT_FK_VAR_BYTEARRAY` (`BYTEARRAY_ID_`),
KEY `ACT_FK_VAR_BYTEARRAY` (`BYTEARRAY_ID_`),
KEY `ACT_FK_VAR_EXE` (`EXECUTION_ID_`),
KEY `ACT_FK_VAR_PROCINST` (`PROC_INST_ID_`),
CONSTRAINT `ACT_FK_VAR_BYTEARRAY` FOREIGN KEY (`BYTEARRAY_ID_`) REFERENCES `ACT_GE_BYTEARRAY` (`ID_`),
CONSTRAINT `ACT_FK_VAR_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`),
CONSTRAINT `ACT_FK_VAR_PROCINST` FOREIGN KEY (`PROC_INST_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
mysql> SELECT COUNT(*) FROM ACT_RU_VARIABLE WHERE TASK_ID_ IS NULL;
+----------+
| COUNT(*) |
+----------+
| 1747363 |
+----------+
1 row in set (0.56 sec)
mysql> SELECT COUNT(*) FROM ACT_RU_VARIABLE WHERE TASK_ID_ IS NOT NULL;
+----------+
| COUNT(*) |
+----------+
| 6 |
+----------+
1 row in set (0.61 sec)
2. What did you expect to see? (Required)
2026-01-28 13:45:48 (UTC+08:00)TiDB 10.170.15.90:4000[conn.go:1042] ["connection running loop panic"] [conn=4258500600] [session_alias=] [lastSQL="select * from ACT_RU_VARIABLE where task_id_='1997872469436538880'"] [err="runtime error: invalid memory address or nil pointer dereference"] [stack="github.com/pingcap/tidb/pkg/server.(*clientConn).Run.func1 /workspace/source/tidb/pkg/server/conn.go:1045\nruntime.gopanic /usr/local/go/src/runtime/panic.go:791\ngithub.com/pingcap/tidb/pkg/executor.(*Compiler).Compile.func1 /workspace/source/tidb/pkg/executor/compiler.go:59\nruntime.gopanic /usr/local/go/src/runtime/panic.go:791\nruntime.panicmem /usr/local/go/src/runtime/panic.go:262\nruntime.sigpanic /usr/local/go/src/runtime/signal_unix.go:917\ngithub.com/pingcap/tidb/pkg/planner/cardinality.estimateRowCountWithUniformDistribution /workspace/source/tidb/pkg/planner/cardinality/row_count_index.go:422\ngithub.com/pingcap/tidb/pkg/planner/cardinality.equalRowCountOnIndex /workspace/source/tidb/pkg/planner/cardinality/row_count_index.go:512\ngithub.com/pingcap/tidb/pkg/planner/cardinality.getIndexRowCountForStatsV2 /workspace/source/tidb/pkg/planner/cardinality/row_count_index.go:267\ngithub.com/pingcap/tidb/pkg/planner/cardinality.GetRowCountByIndexRanges /workspace/source/tidb/pkg/planner/cardinality/row_count_index.go:85\ngithub.com/pingcap/tidb/pkg/planner/core.detachCondAndBuildRangeForPath /workspace/source/tidb/pkg/planner/core/stats.go:411\ngithub.com/pingcap/tidb/pkg/planner/core.fillIndexPath /workspace/source/tidb/pkg/planner/core/stats.go:202\ngithub.com/pingcap/tidb/pkg/planner/core.deriveStats4DataSource /workspace/source/tidb/pkg/planner/core/stats.go:142\ngithub.com/pingcap/tidb/pkg/planner/core/operator/logicalop.(*DataSource).DeriveStats /workspace/source/tidb/pkg/planner/core/operator/logicalop/logical_datasource.go:364\ngithub.com/pingcap/tidb/pkg/planner/core/operator/logicalop.(*BaseLogicalPlan).RecursiveDeriveStats /workspace/source/tidb/pkg/planner/core/operator/logicalop/base_logical_plan.go:211\ngithub.com/pingcap/tidb/pkg/planner/core/operator/logicalop.(*BaseLogicalPlan).RecursiveDeriveStats /workspace/source/tidb/pkg/planner/core/operator/logicalop/base_logical_plan.go:204\ngithub.com/pingcap/tidb/pkg/planner/core.physicalOptimize /workspace/source/tidb/pkg/planner/core/optimizer.go:1027\ngithub.com/pingcap/tidb/pkg/planner/core.doOptimize /workspace/source/tidb/pkg/planner/core/optimizer.go:271\ngithub.com/pingcap/tidb/pkg/planner/core.DoOptimize /workspace/source/tidb/pkg/planner/core/optimizer.go:321\ngithub.com/pingcap/tidb/pkg/planner.optimize /workspace/source/tidb/pkg/planner/optimize.go:530\ngithub.com/pingcap/tidb/pkg/planner.Optimize /workspace/source/tidb/pkg/planner/optimize.go:361\ngithub.com/pingcap/tidb/pkg/executor.(*Compiler).Compile /workspace/source/tidb/pkg/executor/compiler.go:102\ngithub.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt /workspace/source/tidb/pkg/session/session.go:2112\ngithub.com/pingcap/tidb/pkg/server.(*TiDBContext).ExecuteStmt /workspace/source/tidb/pkg/server/driver_tidb.go:291\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleStmt /workspace/source/tidb/pkg/server/conn.go:2033\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleQuery /workspace/source/tidb/pkg/server/conn.go:1780\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).dispatch /workspace/source/tidb/pkg/server/conn.go:1379\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).Run /workspace/source/tidb/pkg/server/conn.go:1148\ngithub.com/pingcap/tidb/pkg/server.(*Server).onConn /workspace/source/tidb/pkg/server/server.go:741"]
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
tidb version is V8.5.4
Activity
ti-chi-bot commentedon Jan 28, 2026
Welcome @caiyifeng-1994! It looks like this is your first issue to pingcap/tidb 🎉
8 remaining items
planner: fix a nil pointer bug caused by nil TopN (#66251)
qw4990 commentedon Feb 25, 2026
Fixed by #66251
caiyifeng-1994 commentedon Mar 12, 2026
It seems that this issue is caused by the database index "ACT_IDX_VARIABLE_TASK_ID". Is there any temporary solution to avoid this error?
planner: fix a nil pointer bug caused by nil TopN (#67106)
qw4990 commentedon Apr 16, 2026
Reproduce this:
planner: fix a nil pointer bug caused by nil TopN (pingcap#67106)
planner: fix a nil pointer bug caused by nil TopN (#67840)
terry1purcell commentedon Jun 19, 2026
Using @qw4990's instructions above may not be enough. Here are the additional steps to reproduce and fix the issue:
I added another index:
Then I repeated the following SQL until I hit 700,000 rows:
Then I inserted a final dummy row where topic_id is not null:
Next:
I then ran this update (which is intended to target user tables with modifyCount == 0 and sampling (which kicks in at 100,000 rows):
Then you should be able to reproduce the panic using this version of the SQL:
To reload stats_meta and fix the panic.
qw4990 commentedon Jun 20, 2026
Setting modify_cnt to 1 should be able to keep the optimizer out from the panic logic:
qw4990 commentedon Jun 20, 2026
Another case that can reproduce this panic:
planner: fix a nil pointer bug caused by nil TopN (#66251) (#69570)
planner: fix a nil pointer bug caused by nil TopN (#66251) (#69750)