Skip to content

[Bug]: Secondary-index churn inflates UPDATE cardinality and escalates disjoint-key updates to a table lock #32889

Closed

Description

@iamlinjunhong

On a MatrixOne v4.2.8 cluster, three transactions renewed disjoint groups of shard leases. Each UPDATE triggered an exclusive table lock. Two failed with error 20701 after the lock service recorded wait cycles. One committed, allowing a comparison of estimated and actual cardinalities.

Observed plan

Operator Estimated output Actual output on successful path
Secondary index table scan 24,576 768
Inner join 24,576 256
Lock operator 24,576 256

Each group has its own composite primary keys (group, shard). The transactions use a locking read of assigned shards followed by a conditional batched UPDATE of an expiry column covered by a secondary index. All three CNs logged Row lock upgraded to table lock for SQL with estimated output 24,576. Both failed transactions requested Exclusive-Range-Wait on the same base table.

Why the estimate crosses the threshold

TN flush logs showed 32 distinct data-object outputs of 768 rows each. The L0 object count advanced from 31 to 32 across the final flush. The unfiltered secondary-index scan had cost and estimated output of 24,576, with blocknum 33. This matches the collector summing physical data-object rows without subtracting row-level deletes. Historical CN statistics-cache membership could not be verified object by object. The join with the main-table branch (estimated at 1,000 rows) retained 24,576, and the lock operator inherited that estimate. On the successful path the lock operator actually emitted 256 rows.

Expected behavior. Retained versions in a secondary index should not by themselves cause a selective base-table UPDATE over disjoint keys to take a whole-table exclusive lock.

Regression case to validate. Compare updates on three groups of 256 shards before and after repeated updates and flushes of the indexed expiry column, keeping the live key count fixed. Inspect plan cardinalities and base-table lock granularity. Include an unbounded UPDATE as a control to preserve intentional table locking. This report is based on an observed production case. An isolated reproducer has not been run.

The cluster reported v4.2.8 / 10d204b at investigation time. Individual CN image digests at incident time were unavailable.

Object statistics collection · Scan estimate · Lock escalation

Activity

  1. added
    severity/s0
    on Nov 18, 2026
  2. iamlinjunhong commented on Nov 19, 2026

    @iamlinjunhong
    ContributorAuthor

    main 中已有修复,风险较大,不合入 4.2-dev

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triageseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions