Skip to content

[Bug]: mo-dump hangs forever (100% CPU in adjustViewOrder) when view DDL text false-matches another view's name — substring dependency graph builds fake cycles with no guard; truncated dump still replays DROP DATABASE #30672

Closed as not planned

Description

@Ariznawlll

Bug or Feature Request

Bug

Description

mo-dump hangs forever (0 bytes of table output after the USE db; line, 100% CPU busy-wait) when a database contains any view whose SHOW CREATE VIEW text false-matches another view's name via the tool's naive substring dependency analysis. Two independent false-positive shapes reproduce it 100%:

  1. View-name vs derived-column alias collision — the topological sort in adjustViewOrder (mo_dump repo, cmd/mo-dump/main.go ~line 357) builds the dependency graph with

    if strings.Count(createTable[i], tables[j].Name) > 0 {  // plain substring!
        viewCount[viewPos[tables[i].Name]]++
    }

    so any occurrence of another view's name in the DDL text (derived-column alias, string literal, comment, etc.) is counted as a real dependency and can synthesize a fake cycle. The subsequent loop

    for order < len(viewName) {   // no cycle guard!
        for i := 0; i < len(viewName); i++ {
            if viewCount[i] == 0 && !visit[i] { ... }
        }
    }

    has no cycle detection or max-iteration guard, so a fake cycle makes mo-dump spin forever inside adjustViewOrder — confirmed by sample(1): the process sits 100% at main.(*Options).dumpData → main.adjustViewOrder,

    4 main.main
      4 main.(*Options).dumpData
        4 main.adjustViewOrder     <-- 100 % of wall time, never returns
    
  2. String-literal collision — two views whose DDL text mutually contains the other view's name (e.g. a status-filter literal equal to another view's name) also manufactures a fake cycle, with no real dependency at all.

The wrong-ordering risk (false positive without a cycle → views emitted before their dependencies → broken dump) also exists, but the silent hang is the visible failure: any mo-dump <db> invocation never returns, producing a truncated dump whose only contents are

SET foreign_key_checks = 0;
DROP DATABASE IF EXISTS `db`;
CREATE DATABASE `db` ;
USE `db`;

— replaying this file still drops the target database before failing, the same "silent bad backup" blast radius as #30577.

Steps to Reproduce

MO v3.x (b24d1b3, 2026-10-16), macOS arm64; mo-dump at matrixorigin/mo_dump@324c33d (HEAD of main).

Repro 1 — view name collides with derived-column alias (fake cycle on top of real chain)

CREATE DATABASE vn;
CREATE TABLE vn.t (id INT PRIMARY KEY, v INT);
CREATE VIEW vn.v1 AS SELECT v*2 AS v2 FROM vn.t;          -- DDL text contains "v2"
CREATE VIEW vn.v2 AS SELECT COUNT(*) AS total FROM vn.v1; -- real dependency v2 → v1
$ ./mo-dump -h 127.0.0.1 -P 16001 -u root -p *** -db vn
# hangs forever; kill -9 required; output truncated to header only

strings.Count(createTable[v1], "v2") matches the AS v2 alias → spurious edge v1 → v2; real edge v2 → v1 + spurious edge = cycle → topological loop never terminates.

Repro 2 — string literal equals the other view's name (no real dependency at all)

CREATE DATABASE vt;
CREATE TABLE vt.t (id INT PRIMARY KEY, status VARCHAR(10));
CREATE VIEW vt.active_users  AS SELECT id FROM vt.t WHERE status = 'pending_queue';
CREATE VIEW vt.pending_queue AS SELECT id FROM vt.t WHERE status = 'active_users';

Each view's DDL contains the other's name inside a string literal → fake cycle → same infinite hang.

Controls (13-bisect matrix, all pass unless fake cycle exists)

Database layout Result
Table + single view (any expression) OK
Table + two independent views OK
View chain, v1 = SELECT * FROM t, v2 = count(*) FROM v1 (no name collision in text) OK
String literal contains other name in only one direction OK (one fake edge, no cycle)
Repro-1 pair embedded in a 5-object DB (plus JOIN view, agg chain) HANG

Expected behavior

Both dumps should complete in milliseconds (control experiments prove the data is trivially small); at minimum the tool must fail fast with a clear error instead of hanging.

Suggested fix

  1. Replace the substring heuristic with tokenized identifier matching (word boundaries / backtick-qualified refs), or read actual view dependencies from MO catalog metadata instead of parsing DDL text.
  2. Harden the topological loop with cycle detection (order unchanged after a full pass → bail out with a clear error) so no future regression can hang a whole backup.

Versions

Additional context

Impact: any user DB with views whose DDL text happens to contain another view's name as an alias or a string literal — common in reporting/ETL schemas. The hang blocks nightly backup pipelines; the truncated output remains a replayable DROP DATABASE file (data-loss multiplier on restore).

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. added this to the MO-202610 milestone on Oct 20, 2026
  3. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Tracking consolidated into #30555. The canonical issue includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed. The original reproduction and discussion remain preserved here.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions