Skip to content

Support shared lock for foreign key #19087

@zyguan

Description

@zyguan

Background

TiDB supports foreign key constraint check by default. When writing a child table, it checks whether the corresponding foreign key value exists in the parent table, and locks the row in the parent table to avoid the foreign key value being deleted by other operations violating the foreign key constraint. However, the current implementation uses exclusive locks for foreign key checks, which can lead to performance bottlenecks in high-concurrency scenarios. To address this, we have introduced shared locks for foreign key checks in pessimistic transactions. This allows multiple transactions to read-lock the same foreign key simultaneously, improving concurrency and performance.

Tracking list(master)

  • kvproto add shared lock type
  • tikv support shared locks in mvcc storage format
  • tikv update lock waiting logic for shared locks
  • tikv support shared locks in write commands
  • tikv prevent xlock starving
  • tikv support deadlock detection
  • tikv add shared lock unit tests
  • client go support shared locks
  • tidb use shared locks in foreign key checks
  • tidb coprocessor resolve shared locks
  • tidb add integration tests for shared locks
  • tidb support shared lock in unistore
  • compatibility with other features(1pc, async commit, fair locking features)

Development Task

kvproto

tikv

tidb & client-go

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-8.5This bug affects the 8.5.x(LTS) versions.sig/transactionSIG: Transactiontype/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions