Skip to content

ddl: Non clustered reorg duplicate tidb rowid fix #60132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Mar 18, 2025

What problem does this PR solve?

Issue Number: close #59680

Problem Summary:
Issue is that for non-clustered, partitioned tables and REORGANIZE PARTITION (and related alters).
And possibility of EXCHANGE PARTITION, which allows duplicate _tidb_rowid's between partitions.
And the new reorganized set of partitions are not kept in-sync with the old non-reorganized partitions.

What changed and how does it work?

Original issue was #53385. After trying both "Always generate a new _tidb_rowid", (#53770, leading to #57510) and "using AddRecord", to generate new _tidb_rowid's (#57114, leading to #59680) and having the indexes up-to-date (for the currently used set of partition), there will always be issues between the original set of partitions and the reorganized set of partitions, due to not being in sync / having the same _tidb_rowid.

This solution will make sure that if a row exists in both sets of partitions, it will always have the same _tidb_rowid.

It works like this:
During backfill, if a the currents row's tidb_rowid already exists in the new partition:
If same row (content is same as current row)

  • Skip backfilling it (since already there)
    else
  • generate a new table unique _tidb_rowid and delete the current row and add it back with the new _tidb_rowid and save the same row, with the new _tidb_rowid in the new partition.

During DML:
Delete: Only delete the reorganized row if it matches both _tidb_rowid AND row content
Update: Use DELETE+INSERT (RemoveRecord+AddRecord) where DELETE is the same as above. When insert/AddRecord creates a new _tidb_rowid, use that newly generated id for both new and old partitions.
And INSERT: if moving between partitions in the current set of partition, then a new unique _tidb_rowid will be generated, so use that the other set of partitions as well. Else if the _tidb_rowid already exists in the other set of partitions, then generate a new _tidb_rowid and use for both sets of partitions.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fixed issues with concurrent DML during REORGANIZE PARTITION for non-clustered tables that had been EXCHANGED.

TODO: Still check issues with new _tidb_rowid's when it comes to
INDEX as well as updating both new+old set of partition
as well as old+new...
@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Apr 9, 2025
@ti-chi-bot ti-chi-bot bot removed the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Apr 9, 2025
Copy link

ti-chi-bot bot commented Apr 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Defined2014, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm approved and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 10, 2025
Copy link

ti-chi-bot bot commented Apr 10, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-27 02:18:32.26101975 +0000 UTC m=+1099605.945255841: ☑️ agreed by Defined2014.
  • 2025-04-10 04:15:54.339742775 +0000 UTC m=+2316248.023978870: ☑️ agreed by tangenta.

@ti-chi-bot ti-chi-bot bot merged commit 13fe7ab into pingcap:master Apr 10, 2025
27 checks passed
@mjonss mjonss deleted the non-clustered-reorg-duplicate-_tidb_rowid-fix branch April 10, 2025 05:52
@bb7133 bb7133 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Apr 15, 2025
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Apr 15, 2025
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #60565.
But this PR has conflicts, please resolve them!

@bb7133
Copy link
Member

bb7133 commented Apr 15, 2025

/cherry-pick release-8.5

@ti-chi-bot
Copy link
Member

@bb7133: new pull request could not be created: failed to create pull request against pingcap/tidb#release-8.5 from head ti-chi-bot:cherry-pick-60132-to-release-8.5: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for ti-chi-bot:cherry-pick-60132-to-release-8.5."}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request","status":"422"}

In response to this:

/cherry-pick release-8.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Apr 15, 2025
@ti-chi-bot ti-chi-bot bot removed the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More than one row with the same primary key when inject fault
5 participants