Skip to content

[Bug]: CREATE DATABASE CLONE silently omits stored procedures #27091

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

1d7b631

Other Environment Information

- Hardware parameters: Apple Silicon (arm64)\n- OS type: macOS\n- Others: freshly built local standalone instance; SQL endpoint 127.0.0.1:6001

Actual Behavior

CREATE DATABASE ... CLONE succeeds but produces a partial database: stored procedures in the source database are silently omitted. In all 3 independent runs, the ordinary table control was cloned with its row, while the target had no matching row in mo_catalog.mo_stored_procedure and CALL .p_answer() failed with ERROR 1122 (HY000): function p_answer doesn't exist.

Expected Behavior

A database clone should preserve database-scoped stored procedures. After cloning, the target should contain p_answer and CALL .p_answer() should return 42, just as it does in the source.

Steps to Reproduce

1. Start MatrixOne main at 1d7b6311ce91df0968da435bb405f3d68137c595.\n2. Run:\n\nDROP DATABASE IF EXISTS clone_proc_dst;\nDROP DATABASE IF EXISTS clone_proc_src;\nCREATE DATABASE clone_proc_src;\nCREATE TABLE clone_proc_src.control_t(id INT PRIMARY KEY);\nINSERT INTO clone_proc_src.control_t VALUES (1);\nCREATE PROCEDURE clone_proc_src.p_answer() 'begin select 42 as answer; end';\nCALL clone_proc_src.p_answer();\nCREATE DATABASE clone_proc_dst CLONE clone_proc_src;\nSELECT COUNT(*) FROM clone_proc_dst.control_t;\nSELECT db, name FROM mo_catalog.mo_stored_procedure\n  WHERE db = 'clone_proc_dst' AND name = 'p_answer';\nCALL clone_proc_dst.p_answer();

Additional information

Environment\n\n- Branch: main\n- Commit: 1d7b631\n- Deployment: freshly built local standalone MatrixOne on macOS arm64, SQL endpoint 127.0.0.1:6001.\n\n## Stability and controls\n\n- Reproducer: 3/3. For clone_proc_src_1..3, CREATE DATABASE ... CLONE succeeded, SELECT COUNT(*) FROM .control_t returned 1, and the target stored-procedure catalog count for p_answer was 0.\n- Positive control: each source contained p_answer and CALL .p_answer() returned 42.\n- Target observation: each CALL .p_answer() returned ERROR 1122 (HY000): function p_answer doesn't exist.\n- Atomicity: this is a successful-but-partial database clone, not a rejected statement; the target database remains created without its procedure.\n\n## Code analysis\n\nThe database clone source collector (pkg/frontend/clone_database_source.go:49) inventories tables through getTableInfos. The collector/clone path creates base tables then restores views, but does not read or recreate mo_catalog.mo_stored_procedure entries. Stored procedures live in that separate catalog table (pkg/frontend/predefined.go:197 and pkg/frontend/authenticate.go).\n\n## Regression coverage\n\nAdd a deterministic public-SQL regression under the existing clone/Data Branch suite. It should create a procedure and ordinary table in the source, clone the database, then assert that both the target table data and CALL against the target procedure succeed.\n\n## Related\n\nRelated but not duplicate: #27049 covers omitted sequences; this report covers stored-procedure catalog entries.

Activity

  1. added
    kind/bug
    on Aug 13, 2026
  2. Ariznawlll commented on Aug 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional scope verification on the same build (1d7b631): this is not limited to the CREATE DATABASE CLONE spelling or stored procedures.

    1. DATA BRANCH CREATE DATABASE also omits procedures: 3 independent source/destination pairs each retained a control table (COUNT(*) = 1) but had 0 matching rows in mo_catalog.mo_stored_procedure; CALL on every destination failed with ERROR 1122.

    2. SQL functions are also omitted by CREATE DATABASE CLONE: for three unique functions (each source function returned 42 for input 41), each destination retained its control table (COUNT(*) = 1) but had 0 matching function metadata rows. Calling each destination function failed with ERROR 20105 (not supported: function or operator ...).

    Both routes therefore appear to share the database-clone source collector's table-only metadata scope. External tables were separately checked 3/3 and correctly rejected atomically (no destination database left behind), so that behavior is unrelated.

  3. Ariznawlll commented on Aug 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional compatibility impact: a view that depends on a database SQL function makes the clone fail entirely.

    For three independent source/destination pairs, each source contained:

    CREATE FUNCTION f_for_clone_view_N() RETURNS INT LANGUAGE SQL AS '42';
    CREATE VIEW v AS SELECT f_for_clone_view_N() AS answer;

    SELECT * FROM source.v returned 42 for every run. Each CREATE DATABASE destination CLONE source then failed while restoring the view with:

    ERROR 20105 (HY000): not supported: function or operator 'f_for_clone_view_N'
    

    The destination database count was 0 after every failure, so rollback is atomic. This confirms that database routines need to be restored before dependent views; otherwise a source database that is internally valid cannot be cloned at all.

  4. added theissue type on Aug 13, 2026
  5. added this to the MO-202608 milestone on Aug 13, 2026
  6. added
    severity/s0
    ai-easy
    and removed on Aug 14, 2026
  7. gouhongshen commented on Aug 17, 2026

    @gouhongshen
    Contributor

    PR #27169 is trying to fix this issue.

  8. gouhongshen commented on Aug 21, 2026

    @gouhongshen
    Contributor

    PR #27169 has merged and is awaiting manual validation. The issue remains open.

  9. added and removed
    severity/s0
    on Aug 25, 2026
  10. Ariznawlll commented on Aug 25, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:22b91fe986b269d24a6b8816eafdd1fa6327c8e1
    • 部署方式:本地 1 Log + 1 TN + 1 CN,MySQL 协议连接。
    • 测试日期:2026-08-25

    原问题验证

    连续 3 轮执行含普通表和 p_answer() 的源库 clone;目标目录与调用结果均正确。

    Happy Path 覆盖

    1. 源/目标过程均返回 42,目标表行数为 1。
    2. 目标 mo_stored_procedure 的 p_answer 计数为 1。

    Unhappy Path 覆盖

    1. 已存在目标库返回 1007;sentinel 行保持 (9,'keep'),未产生源表。

    白盒验证

    pkg/frontend 的过程恢复与 clone routine 聚焦测试连续 3 次通过。

    回归测试

    已加入 motr PR #121:12_git4data.issue_27091_clone_stored_procedure,repeat 3 为 63/63 断言通过。

    测试证据

    修复提交 344d852ac 已包含在 main;以上黑盒、白盒与 MOTR 均在该版本完成。

    测试结论

    测试通过。

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