Repository navigation
Description
Existing issue check
Searched for CASCADE + empty/matching + ColumnExpressionExecutor/panic. Related closed issues #27539 (indexed ON DELETE SET NULL with matching child rows) and #26875 (REPLACE planner panic) do not describe this current-head DELETE/CASCADE empty-match case.
Environment
- Branch: main
- Commit: dd38098
- Freshly compiled binary; SELECT version(), git_version(): 8.0.30-MatrixOne-v; dd38098.
- Local isolated LOG/TN/CN instance, PyMySQL 1.2.3.
- MySQL control: official mysql:8.4 image.
- Observed through OpenAI Agents SDK 0.23.1 SQLAlchemySession.clear_session after making its String session_id declarations MySQL-compatible (VARCHAR(255)).
Minimal reproduction
Use a new database/table namespace:
CREATE TABLE p(id VARCHAR(255) PRIMARY KEY);
CREATE TABLE c(
id INT PRIMARY KEY,
pid VARCHAR(255),
KEY idx_pid(pid),
FOREIGN KEY(pid) REFERENCES p(id) ON DELETE CASCADE
);
INSERT INTO p VALUES('s'),('other');
INSERT INTO c VALUES(2,'other');
-- Target 's' has no child rows, while the child table is nonempty.
DELETE FROM p WHERE id='s';Actual behavior
The DELETE returns a recovered internal executor panic:
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:1955
github.com/matrixorigin/matrixone/pkg/sql/colexec/projection.(*Projection).Call
pkg/sql/colexec/projection/projection.go:108
...
github.com/matrixorigin/matrixone/pkg/sql/colexec/deletion.(*Deletion).normalDelete
The server continues responding to SELECT 1; this report claims a recovered statement panic, not a process crash.
Expected behavior
Delete parent 's' with no error. Parent 'other' and its child should remain unchanged. MySQL 8.4 succeeds with the identical fixture.
Repeated controls and scope
Each combination used fresh tables and was repeated three times:
- Explicit single-column child index + no matching child rows: panic 3/3.
- Explicit composite child index on (pid,note) + no matching child rows: panic 3/3.
- Insert target child, DELETE it first in the same transaction, then DELETE parent while an unrelated child remains: panic 3/3 for each index shape.
- No explicit child secondary index: succeeds for empty-match, delete-child-first and matching-child CASCADE.
- Matching target children with either index shape: CASCADE succeeds.
- Indexed RESTRICT: succeeds when there are no target children, correctly rejects when matching children exist.
- Indexed child table without FK: ordinary DELETE succeeds.
- MySQL 8.4 controls: all CASCADE combinations succeed; RESTRICT correctly rejects matching children.
A 90-case matrix covers two backends, five FK/index variants, three child-match modes and three repeats.
Failure atomicity checks
After rollback:
- Initially empty target: both parent rows and the unrelated child remain (parent count 2, child count 1).
- Delete-child-first transaction: rollback restores target child too (parent count 2, child count 2).
SELECT 1 succeeds after every attempt.
Application impact and verified workaround
OpenAI Agents SQLAlchemySession clears the target's messages before deleting its parent session row, leaving other sessions' message rows in the child table. Its explicit (session_id,created_at) index exposes this path.
A scoped schema adapter omitting only the explicit child secondary index, while retaining the foreign key and ON DELETE CASCADE, passed the SDK add/read, reconstructed-session readback, cross-session isolation and clear tests on MatrixOne and MySQL. This workaround can slow history lookup and is not a database fix.
Suspected area and regression request
The observed differentiator is an indexed FK delete-action projection with zero matching child rows but a nonempty child scan. Root cause before ColumnExpressionExecutor.Eval is not established.
Add literal and bound-parameter DELETE regressions for simple/composite child indexes, empty target matches with unrelated child rows, child-delete-first transactions, matching CASCADE, and rollback atomicity. Keep no-index and RESTRICT controls.
Activity
fix(plan): handle empty indexed FK cascades and cover self-FK ALTER (#…
Ariznawlll commentedon Oct 15, 2026
测试版本
main8795f3699b40504376343fa1acda8b4619f0c76e(已核实修复 PR fix(plan): handle empty indexed FK cascades and cover self-FK ALTER #29994 的 merge commit5d971d07a7c5a52a71f2c10390b109cebf5c0825是其祖先)原问题验证
对照 issue 原始 SQL:父表有
s、other两行,子表仅有引用other的行;对子表分别建立单列KEY(pid)与复合KEY(pid,note)。在目标s没有匹配子行但子表非空时执行DELETE FROM p WHERE id='s'。两种索引均 3/3 成功,无原来的执行器 panic;s被删除,other及其子行各保留 1 行。无显式子索引的对照路径也 3/3 成功。每轮结束服务仍可执行SELECT 1。Happy Path 覆盖
Unhappy Path 覆盖
ROLLBACK;3/3 均恢复父表 2 行、子表 2 行,包括目标子行,无部分提交。ON DELETE RESTRICT:无匹配子行的父行可删除;有匹配子行的父行删除被外键约束拒绝(本版本返回 20101),拒绝后该父行和子行仍各 1 行,3/3。白盒验证
本轮为公开 SQL 的黑盒验收,没有新增或运行 Go UT /
-race;PR #29994 已包含 planner 与分布式 SQL 回归,但其 PR 内测试结果不冒充本轮执行结果。回归测试
suites/14_issue_regression/t/issue_29954_indexed_empty_cascade.test及对应.result,已并入今天唯一的汇总 motr PR #237(head9cd26d702865a3ccd29ed6c85f89ca39961c195e)。原独立 PR insert empty values results in index out of range error #245 已注明迁移并关闭。用例精确断言原始空匹配、单列/复合索引、匹配级联、事务回滚、RESTRICT 拒绝后的行状态。--repeat 3:本用例 3/3 通过;与当天另外两个已通过用例合并复核时共 9/9 次、228/228 条语句通过。14_issue_regressionsuite 和集成 CI 尚未验证,后续继续跟踪。该缺口不是本次产品原问题复测的通过证明。测试证据
total=9 success=9 failed=0 skipped=0 | stmts=228 ok=228 fail=0。/private/tmp/mo-28041-main-WBgvoq/matrixone/.local-validation/issue_29954.go,逐轮执行两种显式索引及无索引对照、匹配级联、回滚与 RESTRICT 状态断言;3 轮无断言失败。测试结论
测试通过。