Skip to content

[Bug]: Successful DROP/TRUNCATE of indexed tables emits false missing-parent ERRORs #31307

Open

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Related but different: #14387 (an older frontend error-propagation report), #24008 (restore/FK cleanup actually aborting), and #29392 (ISCP timeout causes reported before timeout). None documents the ordinary secondary-index DROP/TRUNCATE reproduction below.

Branch Name

Reproduced with the v4.2.1-based hotfix candidate described below. The relevant parent-resolution/error-suppression path also remains in inspected main and 4.2-dev; those tips were source-reviewed, not executed in this experiment.

Commit ID

  • Executed test binary: 9ebefa5bc1bc0daa9fce761c39f099cc2204a077, version v4.2.1-cte-account-hotfix-20261025-candidate. Direct go version -m inspection reports that exact vcs.revision and vcs.modified=false.
  • Executable SHA-256: d46cf00361b1919c30d263a23f560408e92734df8b13cf06150c397d514a43e7; it also matches the pre-existing build receipt. Relevant resolver, index-construction and DDL source files are byte-identical to the reviewed baseline. This is not a claim of binary identity with deployed production.
  • Reviewed v4.2.1 baseline: d2393868a7aaa6343518d80849fe4696aa3577e9.
  • Relevant source also compared against hotfix 47e644f2d704c02baf90461de8f164e1d39c344e.
  • Inspected main: ccfca4f7fdc75f1c8e6cb14730f4759dc6efce66.
  • Inspected 4.2-dev: 86a45d39df3d1f23490fcdd7328b46c5520efada.

Other Environment Information

  • Linux/amd64; a fresh, isolated CN/TN/LogService instance, local disk FileService, loopback SQL endpoint, private test data and socket.
  • GOMAXPROCS=4; normal partition-service default enabled; the SQL tables themselves are not partitioned.
  • One-row minimal case and a separate two-row/six-index case. No fault injection, direct catalog modification, fabricated stale metadata, or production SQL was used.
  • Both test instances were stopped after collecting evidence. No existing service or production data was changed.

Actual Behavior

Successful TRUNCATE TABLE and DROP TABLE on a table with an ordinary secondary index emit a false missing-parent ERROR:

disttae/engine.go:585
error: internal error: can not find table by id <parent-id>: accountId: 0. Deleted in txn

The SQL operations return Query OK. The truncated table is empty and writable afterward; the dropped table disappears from the catalog. A no-secondary-index DROP control does not produce this diagnostic. Thus this report is about misleading ERROR telemetry on a successful cleanup path, not demonstrated wrong results, failed DDL, or unexpected data loss.

Minimal experiment, repeated with two independently created indexed tables:

Operation SQL/result oracle Matching ERROR count
DROP, primary key only/no secondary index Success; table absent afterward 0
TRUNCATE, one ordinary secondary index Success; row count 0; new parent ID; subsequent insert succeeds 1
DROP, one ordinary secondary index Success; table absent afterward 1
Repeat TRUNCATE/DROP on another indexed table Same checks pass 2 total

A separate six-secondary-index experiment produced six errors during TRUNCATE's internal DROP and six during explicit DROP, while the SQL/result checks passed. This establishes diagnostic amplification with hidden-index count in the tested cases; it is not a throughput or memory benchmark.

Expected Behavior

An expected, explicitly tolerated missing-parent lookup during successful same-transaction index cleanup must not be reported as an unhandled internal ERROR. Genuine unexpected lookup/cleanup failures must remain observable and must still propagate according to the operation's contract.

Steps to Reproduce

Run only in a disposable test instance, using a fresh database name:

CREATE DATABASE tableid_minimal_probe;
USE tableid_minimal_probe;

-- Counterfactual: no secondary index; no matching ERROR in this window.
CREATE TABLE no_index(id INT PRIMARY KEY, a INT);
INSERT INTO no_index VALUES (1, 10);
SELECT 'NO_INDEX_DROP_BEFORE', UTC_TIMESTAMP(6);
DROP TABLE no_index;
SELECT 'NO_INDEX_DROP_AFTER', UTC_TIMESTAMP(6);

CREATE TABLE with_index(id INT PRIMARY KEY, a INT, INDEX ia(a));
INSERT INTO with_index VALUES (1, 10);
SELECT 'TRUNCATE_BEFORE', UTC_TIMESTAMP(6), rel_id
FROM mo_catalog.mo_tables
WHERE account_id = 0 AND reldatabase = 'tableid_minimal_probe'
  AND relname = 'with_index';

TRUNCATE TABLE with_index;
SELECT 'TRUNCATE_AFTER', UTC_TIMESTAMP(6), COUNT(*) FROM with_index;
SELECT 'NEW_PARENT_ID', rel_id
FROM mo_catalog.mo_tables
WHERE account_id = 0 AND reldatabase = 'tableid_minimal_probe'
  AND relname = 'with_index';

INSERT INTO with_index VALUES (2, 20);
SELECT 'DROP_BEFORE', UTC_TIMESTAMP(6);
DROP TABLE with_index;
SELECT 'DROP_AFTER', UTC_TIMESTAMP(6), COUNT(*)
FROM mo_catalog.mo_tables
WHERE account_id = 0 AND reldatabase = 'tableid_minimal_probe'
  AND relname = 'with_index';

DROP DATABASE tableid_minimal_probe;

The catalog predicates above assume the disposable test's sys account (account_id=0). Run the SQL client without a continue-on-error option; inspect the server ERROR log within the marked windows. Numeric IDs vary between instances.

Observed timing evidence on 2026-10-26 (UTC; service log timestamps converted from UTC+8):

Window Result
15:49:09.093647–15:49:09.104192, no-index DROP Success; no matching missing-ID error
15:49:09.111658–15:49:09.118144, indexed TRUNCATE ERROR at 15:49:09.114018 for old parent ID 272553; SQL succeeds, count=0, new ID=272555
15:49:09.123461–15:49:09.128271, indexed DROP ERROR at 15:49:09.126106 for parent ID 272555; SQL succeeds, catalog count=0
Repeated indexed TRUNCATE/DROP Errors at 15:49:09.137946 and 15:49:09.150478 for IDs 272557 and 272559; both operations and postconditions pass

These are isolated test IDs, not production/customer IDs. All SQL commands completed with client exit code 0; both test databases were removed by their explicit teardown.

Additional information

Source-level cause of the reproduced diagnostic

The code path is:

  1. dropTableSingle deletes the main relation before deleting its hidden index relations.
  2. The subsequent index-cleanup loop first calls maybeDeleteAutoIncrement, which opens the hidden index relation by name. When it is not already cached, construction reaches newTxnTable.
  3. newTxnTable resolves ExtraInfo.ParentTableID whenever the partition service is enabled and the item is an index table, including ordinary non-partitioned indexes.
  4. GetRelationById detects that the parent was already deleted in this transaction and constructs the . Deleted in txn error.
  5. moerr.newError reports during construction through errutil; motrace.ReportError emits ERROR before the caller handles it.
  6. newTxnTable explicitly tolerates errors containing can not find table by id, sets a nil parent, and continues. This tolerance is too late to prevent the ERROR report.

TruncateTable reaches the same behavior through its DROP/CREATE implementation. This explains the real-operation timing, parent IDs and index-count controls. A full exported runtime stack was not obtained: the isolated system.error_info view remained empty during a bounded wait. This limitation does not change the observed SQL/log result, but no runtime full-stack capture is claimed.

Scope and production correlation boundary

This was found while investigating a production fixed-table-ID diagnostic. The production sample is from the resolver's other missing-ID branch and does not have . Deleted in txn. Its original caller stack/SQL/metadata are unavailable under the read-only/no-production-SQL investigation boundary. Therefore this reproduction does not establish that the production sample comes from DROP/TRUNCATE or the same parent lookup. It also does not establish customer metadata corruption, data loss, or an application bug. No customer identifiers or raw production logs are included here.

The inspected main and 4.2-dev tips retain parent lookup plus string-based suppression. Main changes the resolver's error type to NoSuchTable, but the reporting-at-construction mechanism still exists. This is source-review evidence, not a claim that these exact tips were runtime-tested. No fix for this specific reproduction was found in the reviewed related issues/PRs.

Fix/acceptance guidance

  • Handle expected missing-parent cleanup without an eager ERROR report, narrowly at the correct lookup/caller boundary. Do not disable error reporting globally or suppress arbitrary missing-table errors.
  • Preserve propagation/reporting of unrelated failures and validation of genuine partition-parent requirements.
  • Add a regression that checks BOTH successful public DDL/postconditions and absence of this false ERROR, not only SQL exit status.
  • Cover no-index control, one/multiple indexes, repeated TRUNCATE, DROP, and relevant partitioned-index/error-path controls.
  • Do not claim this fix resolves the production fixed-ID incident until its distinct lookup precondition is independently established.

No product fix or PR is included in this report.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions