Skip to content

fix: handle missing child table in DropTable FK cleanup - #24132

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix-drop-table-fk-child-cleanup
Apr 14, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix-drop-table-fk-child-cleanup

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24133

What this PR does / why we need it:

When a table has stale RefChildTbls entries pointing to non-existent child tables (due to previous operations like CDC, snapshot restore, or prior bugs), the FkChildTblsReferToMe cleanup loop in dropTableSingle fails with:

internal error: can not find table by id <N>: accountId: <M>

This blocks DROP TABLE and DROP ACCOUNT operations.

Related issue: #24008 / PR #24009 (fixed the same error in removeFkeysRelationships for DropDatabase path, but missed the DropTable path).

What is changed?

pkg/sql/compile/ddl.go (dropTableSingle):

  1. FkChildTblsReferToMe loop (line 2957) — Added isMissingTableForFkCleanup error tolerance when looking up child tables. If a child table no longer exists, log a warning and continue instead of returning a fatal error. This is the same pattern already applied by PR fix: tolerate same-txn missing tables during FK cleanup #24009 to removeFkeysRelationships.

  2. ForeignTbl loop (line 2929) — Upgraded the existing error check from raw strings.Contains(err.Error(), "can not find table by id") to the more robust isMissingTableForFkCleanup() helper (which also catches ErrNoSuchTable).

When a table has stale RefChildTbls entries pointing to non-existent
child tables, the FkChildTblsReferToMe cleanup loop in dropTableSingle
would fail with 'can not find table by id' error, blocking DROP TABLE
and DROP ACCOUNT operations.

This adds the same isMissingTableForFkCleanup error tolerance that
PR matrixorigin#24009 added to removeFkeysRelationships (DropDatabase path), but
for the DropTable path's child table lookup.

Also upgrades the existing ForeignTbl loop error check from a raw
strings.Contains to the more robust isMissingTableForFkCleanup helper.

Approved by: jiangxinmeng1

Co-authored-by: Copilot <[email protected]>
Cover all branches of the helper function to satisfy PR coverage CI
(was 33%, needs ≥75%).

Co-authored-by: Copilot <[email protected]>
@mergify

mergify Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-04-14 08:14 UTC · Rule: main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-04-14 09:12 UTC · at a6340efa3f2636049f0b2a113b80130dadbafc80

This pull request spent 57 minutes 58 seconds in the queue, including 57 minutes 40 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 36241ff into matrixorigin:main Apr 14, 2026
24 of 25 checks passed
@mergify mergify Bot removed the queued label Apr 14, 2026
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
…#24132)

When a table has stale `RefChildTbls` entries pointing to non-existent child tables (due to previous operations like CDC, snapshot restore, or prior bugs), the `FkChildTblsReferToMe` cleanup loop in `dropTableSingle` fails with:

```
internal error: can not find table by id <N>: accountId: <M>
```

This blocks `DROP TABLE` and `DROP ACCOUNT` operations.

Related issue: matrixorigin#24008 / PR matrixorigin#24009 (fixed the same error in `removeFkeysRelationships` for DropDatabase path, but missed the DropTable path).

Approved by: @aunjgr

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/enhancement size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants