Repository navigation
Description
Description
Deleting a parent row with ON DELETE SET NULL panics when the referencing child table has an explicit secondary index containing the foreign-key column. The recovered SQL error is ERROR 20101, with an index out of range [0] with length 0 panic in ColumnExpressionExecutor.Eval.
Environment
- Branch:
main - Commit:
ba8954d543af0bdfb1948a8b89f77f5235ac9259 - Deployment: local
mo-servicethrough the MySQL endpoint on port6001 - Date:
2026-08-24
The same symptom was also observed in the TKE main-nightly job at MatrixOne commit dc403fbac6a09c77ac93bb023fe83056308a038b.
Steps to reproduce
drop database if exists fk_setnull_panic;
create database fk_setnull_panic;
use fk_setnull_panic;
create table parent_setnull (
id int primary key,
code varchar(20) unique
);
create table child_setnull (
child_id int primary key,
parent_id int,
note varchar(30),
key idx_parent(parent_id, note),
constraint fk_setnull foreign key(parent_id)
references parent_setnull(id) on delete set null
);
insert into parent_setnull values (100, 'p100'), (200, 'p200');
insert into child_setnull values
(1,100,'s100-a'), (2,200,'s200-a'), (3,200,'s200-b');
delete from parent_setnull where id = 100;Actual behavior
The literal DELETE returns:
ERROR 20101: internal error: panic runtime error: index out of range [0] with length 0
github.com/matrixorigin/matrixone/pkg/sql/colexec.(*ColumnExpressionExecutor).Eval
pkg/sql/colexec/evalExpression.go:1565
This is not limited to SQL PREPARE; the literal statement above reproduces it.
Expected behavior
The parent row should be deleted and the matching child row's parent_id should become NULL, without a panic.
Stability and controls
- Reproducer (literal
DELETE, explicit child secondary index): panic 3/3 onmain@ba8954d. - Control without
key idx_parent(parent_id, note): completes 3/3; all statements return normally. - Separate prepared
ON UPDATE CASCADEcontrol: completes 3/3. The failing operation is specifically theON DELETE SET NULLpath with the explicit child index, not generic prepared DML. - The server later stopped accepting new local connections after the repeated panic tests; failure atomicity could not be checked in that instance and is not claimed here.
Evidence
- TKE nightly failure: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/32647429404/job/97318513379
- Existing MOTR reproducer:
suites/14_issue_regression/t/issue_25419_prepared_fk_actions.test
Code analysis
Confirmed panic location: pkg/sql/colexec/evalExpression.go:1565 in ColumnExpressionExecutor.Eval.
The cause before this executor is not yet confirmed. The explicit child index is the observed differentiator and should be traced through the parent-delete FK-action plan construction and projection input shape.
Regression coverage
After the product fix, extend issue_25419_prepared_fk_actions (or add focused BVT coverage) with literal and prepared parent DELETE using ON DELETE SET NULL plus an explicit child secondary index. Assert child values become NULL, no recovered panic occurs, and a no-index control remains valid.
Related
- Regression after the feature path covered by [Bug]: Prepared DML hangs on second execute when foreign-key actions are triggered #25419 (closed): prepared foreign-key actions previously hung on repeated execution.
- Related but not duplicate: [Bug]: REPLACE panics with indexed CASCADE/SET NULL child foreign key #26875 was a
REPLACEplanner panic in a related indexed-FK path; this issue reproduces with a plain parentDELETEand reachesColumnExpressionExecutor.Eval.
Activity
fix: maintain secondary index for delete set null (#27622)
Ariznawlll commentedon Sep 1, 2026
测试版本
main@33af6ae3c0c23e4f277137460577ea64678f7ecf原问题验证
带
(parent_id,note)二级索引的子表执行ON DELETE SET NULL,未再出现ColumnExpressionExecutorpanic;3 条子记录的parent_id均正确变为NULL,note保持不变。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
不适用。原 panic 可由公开 DDL/DML 稳定触发,黑盒结果足以验收。
回归测试
issue_25419_prepared_fk_actions.test/.result覆盖;本次在 motr#136 补充 [Bug]: indexed ON DELETE SET NULL panics in ColumnExpressionExecutor #27539 映射,避免复制相同用例。测试证据
191/191SQL、重复 3 轮573/573SQL 通过。测试结论
测试通过。
fix: maintain secondary index for delete set null (matrixorigin#27622)
fix: maintain secondary index for delete set null (matrixorigin#27622)
fix: maintain secondary index for delete set null (matrixorigin#27622)