Skip to content

[Bug]: Secondary index loses most entries; UPDATE of indexed column silently succeeds without changing base row #25873

Closed

Description

@lxw665

Is there an existing issue for the same bug?

Branch Name

MatrixOne v4.1.2

Commit ID

ce99d32

Other Environment Information

  • MySQL-compatible version string: 8.0.30-MatrixOne-v4.1.2
  • The cluster was upgraded to this version on 2026-07-17.
  • Table and column names below are simplified. No customer data or credentials are included.

Actual Behavior

A task table has approximately 1.07 million base rows and these relevant indexes:

CREATE TABLE task_queue (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  source_system VARCHAR(32) NOT NULL DEFAULT '',
  status VARCHAR(16) NOT NULL DEFAULT 'PENDING',
  retry_count INT NOT NULL DEFAULT 0,
  worker_id VARCHAR(128) NOT NULL DEFAULT '',
  KEY idx_status_id (status, id),
  KEY idx_source (source_system, status)
);

The base table and both hidden index tables have the same catalog creation time,
but their row counts are inconsistent:

base table:           1,069,515
idx_status_id hidden:     2,978
idx_source hidden:    1,069,515

As a result, indexed reads and forced base-table scans return radically different
results:

SELECT COUNT(*) FROM task_queue WHERE status = 'FAILED';
-- 5

SELECT COUNT(*) FROM task_queue WHERE HEX(status) = '4641494C4544';
-- 202,865

More importantly, updating the indexed status column on an affected historical
row returns success but does not change the base row:

START TRANSACTION;

UPDATE task_queue
SET status = 'RUNNING'
WHERE id = 10001;

SELECT id, status FROM task_queue WHERE id = 10001;
-- 10001, FAILED

ROLLBACK;

Updating a non-indexed column on the same row works:

START TRANSACTION;
UPDATE task_queue SET worker_id = 'probe' WHERE id = 10001;
SELECT id, worker_id FROM task_queue WHERE id = 10001;
-- 10001, probe
ROLLBACK;

EXPLAIN UPDATE ... SET status=... WHERE id=10001 shows a Multi Update plan
that inner-joins the base row with both hidden secondary-index tables. Because the
idx_status_id entry is missing, the inner join removes the base row and the
statement becomes a silent no-op.

The plan for updating worker_id scans only the base table and succeeds.

Additional Evidence

The following controlled tests were performed in transactions or disposable
scratch tables:

  1. A fresh table with no secondary indexes updates correctly.
  2. A fresh table with idx_status_id updates correctly.
  3. A fresh table with both secondary indexes updates correctly.
  4. A fresh row inserted into the affected production table updates correctly.
  5. A fresh 10,000-row INSERT ... SELECT into an equivalent scratch table creates
    10,000 visible index rows and updates correctly.
  6. Historical rows missing from idx_status_id silently fail to update status.
  7. Rewriting one of those rows through INSERT ... ON DUPLICATE KEY UPDATE
    recreates its hidden index entry; subsequent ordinary UPDATEs then work.
  8. While processing historical rows with this UPSERT workaround, the hidden
    idx_status_id row count increased from 2,978 to 72,657, confirming that row
    rewrites repopulate the missing index.

There is also an upgrade correlation:

  • On 2026-07-16, before the reported upgrade, the same application code using
    ordinary UPDATE successfully claimed and completed more than 13,000 tasks.
  • After the upgrade, affected historical rows return success without changing.
  • Catalog metadata does not show the indexes being recreated during upgrade.
  • idx_source remains complete, so there is no evidence of blanket secondary-index loss.

The leading hypothesis is that idx_status_id was already incomplete and the
new UPDATE/Multi Update path now requires the missing hidden-index row. However,
direct index loss during upgrade has not been ruled out because no pre-upgrade
hidden-table row-count snapshot is available.

Expected Behavior

  1. Secondary-index hidden tables must remain consistent with the base table.
  2. UPDATE of an indexed column must update the base row and all indexes.
  3. If index corruption makes the update impossible, the statement must return an
    error instead of reporting success while changing nothing.
  4. Upgrade must not change a previously working UPDATE into a silent no-op.

Steps to Reproduce

The index-loss creation path has not yet been reproduced on a fresh table. The
silent UPDATE behavior is reproducible on the affected historical rows with:

SELECT COUNT(*) FROM task_queue WHERE status = 'FAILED';
SELECT COUNT(*) FROM task_queue WHERE HEX(status) = '4641494C4544';

START TRANSACTION;
UPDATE task_queue SET status = 'RUNNING' WHERE id = 10001;
SELECT id, status FROM task_queue WHERE id = 10001;
ROLLBACK;

We have preserved the affected table/index state and can collect additional
object-level diagnostics before rebuilding the damaged index.

Related Issues

Activity

  1. lxw665 commented on Jul 20, 2026

    @lxw665
    Author

    Additional resource-impact evidence from system.statement_info:

    • 2026-07-19, statements referencing document_file_task with HEX(status) cumulatively reported about 4.02 billion rows read and 3.13 TB logical bytes scanned.
    • 2026-07-20 at the time of measurement, the same class had already reported about 922 million rows read and 746 GB logical bytes scanned.
    • The application claims only 20 tasks per batch. Because HEX(status) bypasses the incomplete index, each claim performs a base-table scan. When UPDATE status silently no-ops, the same tasks remain eligible and are selected again. The subsequent worker_id + HEX(status) read also scans the table.

    This creates a scan/no-op/re-scan amplification loop. It is a strong resource-pressure correlate and can contribute to CN CPU/memory exhaustion, although it does not by itself prove the root cause of every observed OOM.

  2. lxw665 commented on Jul 20, 2026

    @lxw665
    Author

    Additional cross-table audit: same corruption pattern on four queue tables

    We audited all conventional secondary indexes in the affected account and performed transaction/rollback probes on the other queue tables. Table names are simplified below; no credentials or customer data are included.

    Queue role Base rows idx_status_id(status,id) hidden rows
    document file queue 1,069,515 about 106,000 and increasing as affected rows are rewritten through the UPSERT workaround
    receipt file queue 425,390 500
    candidate queue v2 515,697 0
    legacy candidate queue 1,591 0

    All four tables have the same relevant shape:

    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    status VARCHAR(16) NOT NULL DEFAULT 'PENDING',
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY idx_status_id (status, id)

    They are application-owned state-machine queues that repeatedly transition PENDING -> RUNNING -> DONE/FAILED.

    For the three additional queues, indexed predicates returned missing or nearly empty results while expressions that bypass the status index returned the base-table truth:

    receipt queue:
      indexed DONE       = 500
      base-scan DONE     = 358,331
      indexed PENDING    = 0
      base-scan PENDING  = 28,757
    
    candidate queue v2:
      indexed DONE       = 0
      base-scan DONE     = 316,808
      indexed PENDING    = 0
      base-scan PENDING  = 21,343
    
    legacy candidate queue:
      indexed DONE       = 0
      base-scan DONE     = 581
      indexed PENDING    = 0
      base-scan PENDING  = 170
    

    A transaction/rollback probe on one historical row from each additional table reproduced the silent no-op:

    START TRANSACTION;
    UPDATE queue_table SET status='INDEX_PROBE' WHERE id=<historical_id>;
    SELECT ROW_COUNT(); -- 0
    SELECT status FROM queue_table WHERE id=<historical_id>; -- unchanged
    ROLLBACK;

    No SQL error was returned.

    This is not blanket index loss:

    • Primary keys and business/unique indexes remain populated.
    • Companion indexes such as source/business-key indexes are populated.
    • Core indexes on the active file, file-working, and scheduler-task tables match their base tables.
    • The common failing signature is specifically the mutable, low-cardinality (status, auto_increment_id) secondary-index family on queue tables.

    The first two queue/index definitions existed in application DDL since 2026-05-21; the candidate queue definitions existed since 2026-07-08. All predate the 2026-07-17 cluster upgrade. Therefore this audit still does not prove that the upgrade originally removed the entries. It does show that the post-upgrade Multi Update behavior turns the pre-existing/inherited index inconsistency into silent UPDATE no-ops across multiple independent queues.

    Operational impact:

    1. A queue scan may return zero and report drained/success while base rows remain pending.
    2. If a small indexed subset is visible, claim and completion UPDATEs can both no-op; the same rows are processed repeatedly because status and retry_count never change.
    3. Expression-based scans plus repeated no-op updates amplify table scans and Multi Update memory/CPU pressure.

    We are preserving the affected index state before rebuilding and can provide additional catalog/plan/profile evidence if needed.

  3. added
    kind/bug
    on Jul 20, 2026
  4. added theissue type on Jul 20, 2026
  5. added this to the MO-202607 milestone on Jul 20, 2026
  6. ck89119 commented on Jul 21, 2026

    @ck89119
    Contributor

    index是在有问题的老版本上建的,update有问题且静默通过,新版本已经修复了该问题且重建了index,试运行没问题

  7. added
    no-pr-linked
    on Jul 21, 2026
  8. lxw665 commented on Jul 21, 2026

    @lxw665
    Author

    在新版本后 修复index 后 正常

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

Metadata

Metadata

Labels

kind/bugno-pr-linkedseverity/s-1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions