matrixorigin / matrixorigin/matrixone

[Compatibility]: COPY ALTER cannot combine ADD COLUMN and ADD INDEX in one statement

Open
#28,052 4 comments 0 reactions 1 assignee Claimed by @aptend View on GitHub
area/compatibility kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## 差异

MySQL 支持在一条 ALTER TABLE 中同时新增 STORED generated column 和引用它的普通索引。MatrixOne 在 copy mode 中拒绝该组合;必须拆成两条 DDL。

## MatrixOne 复现

main @ 95d04586eb80864499d0fde27aeb912b463ae4cd

create table docs (id int primary key, doc json);
insert into docs values (1, '{"kind":"alpha"}'), (2, '{"kind":"beta"}');

alter table docs
add column kind varchar(20) generated always as (doc ->> '$.kind') stored,
add index idx_kind(kind);

返回:

ERROR 20301 (HY000): invalid input: unsupported alter option in copy mode: add index idx_kind (kind)

连续执行 3 次,结果一致。失败后 kind 列不存在,DDL 没有留下部分 schema 变更。

该限制不依赖 JSON:将表达式替换为 g int generated always as (a + 1) stored 后,同一组合 ALTER 也返回相同错误。

## MySQL 对照

MySQL 8 成功执行完全相同的 JSON 版本;已有行回填 kind,随后通过 idx_kind 查询 alpha 行正常返回。

## 当前可用绕过

拆分为两条语句可工作:先 ADD COLUMN,再 CREATE INDEX。JSON 历史回填、后续 JSON 更新和索引查询均正确。

## 期望

兼容 MySQL 的单条 ALTER TABLE 组合,允许新增 STORED generated column 的同时创建其索引;或明确将其作为受支持的原子 ALTER 组合实现。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.