Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
1ca928aefd
Other Environment Information
- Reproduced on the latest
maincommit above. - Also reproduced on MatrixOne Cloud
8.0.30-MatrixOne-v4.1.4. - The failure is independent of table data and deployment environment.
Actual Behavior
CREATE DATABASE ... CLONE ... fails when the source database contains a foreign-key child table that has been altered after creation:
ERROR 20101 (HY000): internal error: can't find fkTable from fk clone_fk_dst.custom_operator.(source_file_id) {...}
A schema created directly in its final form clones successfully. The equivalent schema produced by creating the foreign key first and then running ALTER TABLE ... ADD COLUMN fails consistently.
Expected Behavior
Database clone should reconstruct the same schema and data regardless of whether the current schema was created directly or reached through valid ALTER TABLE operations.
Steps to Reproduce
DROP DATABASE IF EXISTS clone_fk_src;
DROP DATABASE IF EXISTS clone_fk_dst;
CREATE DATABASE clone_fk_src;
USE clone_fk_src;
CREATE TABLE file (
file_id VARCHAR(36) NOT NULL,
PRIMARY KEY (file_id)
);
CREATE TABLE custom_operator (
id BIGINT NOT NULL AUTO_INCREMENT,
source_file_id VARCHAR(36) DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT fk_custom_operator_source_file
FOREIGN KEY (source_file_id)
REFERENCES file (file_id)
);
ALTER TABLE custom_operator
ADD COLUMN kind VARCHAR(32) NOT NULL DEFAULT 'code';
CREATE DATABASE clone_fk_dst CLONE clone_fk_src;The last statement fails with can't find fkTable from fk clone_fk_dst.custom_operator.(source_file_id).
Control case: define kind in the original CREATE TABLE custom_operator statement and omit the ALTER TABLE; cloning succeeds.
Additional information
Verified observations
- The issue reproduces without inserting any rows.
- Cloning the already cloned/upgraded database fails in the same way.
- A real upgraded schema has
custom_operator.rel_version = 4and fails. - A freshly created equivalent schema has
custom_operator.rel_version = 0and succeeds. - The error is raised in
pkg/sql/plan/build_show_util.gowhenctx.ResolveById(fk.ForeignTbl, snapshot)returns no parent table definition while reconstructing the child table DDL.
Suggested repair direction
The clone path must resolve the child table definition, its ForeignTbl reference, and the referenced parent table from one consistent catalog snapshot/version.
Please avoid resolving the parent from the current catalog as a fallback, because that could silently combine schema versions. A clean fix should either:
- make snapshot-aware relation-ID resolution correctly handle altered table versions; or
- have database clone build and use a snapshot-scoped table-ID-to-definition map for all source tables when reconstructing foreign keys.
A regression test should cover:
- parent table + foreign-key child table;
ALTER TABLEon the child after FK creation;CREATE DATABASE ... CLONE ...;- cloned FK points to the cloned parent and remains enforceable.
Activity
gouhongshen commentedon Jul 28, 2026
Root cause is now confirmed and the fix is in draft PR #26330.
The earlier snapshot-resolution hypothesis was downstream of the actual metadata corruption:
ALTER TABLECOPY mode creates a replacement relation with a new physical table ID.mo_foreign_keysrows are removed when the source is dropped, and the copy table's rows were then deleted instead of renamed to the original table name.RefChildTableDefremoved the old child ID but did not add the replacement child ID.can't find fkTable from fk ....The PR preserves both metadata representations, handles the self-reference sentinel, and adds manually audited ALTER/clone regression coverage.