Skip to content

[Bug]: indexed ON DELETE SET NULL panics in ColumnExpressionExecutor #27539

Closed

Description

@Ariznawlll

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-service through the MySQL endpoint on port 6001
  • 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 on main@ba8954d.
  • Control without key idx_parent(parent_id, note): completes 3/3; all statements return normally.
  • Separate prepared ON UPDATE CASCADE control: completes 3/3. The failing operation is specifically the ON DELETE SET NULL path 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

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

Activity

  1. added this to the MO-202608 milestone on Aug 24, 2026
  2. added
    kind/bug
    on Aug 24, 2026
  3. added theissue type on Aug 24, 2026
  4. added
    ai-easy
    on Sep 1, 2026
  5. Ariznawlll commented on Sep 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • MatrixOne main@33af6ae3c0c23e4f277137460577ea64678f7ecf
    • 1 Log / 1 TN / 2 CN / Proxy,2026-09-01

    原问题验证

    带 (parent_id,note) 二级索引的子表执行 ON DELETE SET NULL,未再出现 ColumnExpressionExecutor panic;3 条子记录的 parent_id 均正确变为 NULL,note 保持不变。

    Happy Path 覆盖

    • 一个父行对应多条子行的 indexed FK action。
    • prepared DML 重复执行,结果一致。

    Unhappy Path 覆盖

    • 不存在父键的写入按外键约束拒绝,未产生残留修改。
    • action 完成后查询索引列与非索引列,未出现部分更新。

    白盒验证

    不适用。原 panic 可由公开 DDL/DML 稳定触发,黑盒结果足以验收。

    回归测试

    测试证据

    • MOTR 重复 3/3 轮通过;完整套件中该用例通过。
    • 本批单轮 191/191 SQL、重复 3 轮 573/573 SQL 通过。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions