Skip to content

dbutil: keep column and index buckets apart when names collide - #905

Open
yzxcj797 wants to merge 1 commit into
pingcap:masterfrom
yzxcj797:fix/buckets-name-collision-904
Open

dbutil: keep column and index buckets apart when names collide#905
yzxcj797 wants to merge 1 commit into
pingcap:masterfrom
yzxcj797:fix/buckets-name-collision-904

Conversation

@yzxcj797

@yzxcj797 yzxcj797 commented Aug 22, 2026

Copy link
Copy Markdown

Issue Number: close #904

What problem does this PR solve?

GetBucketsInfo merged column statistics and index statistics under bare names, so an index sharing its name with a column (e.g. KEY \contentid` (`contentid`,`flag`,`datetime`)) produced one bucket sequence mixing scalar column bounds with tuple index bounds — chunk splitting then failed with analyze value 1683857 failed` (#904).

What is changed and how it works?

Column (is_index=0) and index (is_index=1) buckets are collected into separate maps during the scan and merged at the end, with the index entry winning its own name: lookups by index name must return the index statistics. The PRIMARY fallback reads from the column map directly so a PK column named like another index keeps its own entry.

Check List

  • Manual test: TestGetBucketsInfoIndexNameCollidesWithColumn (sqlmock) reproduces the report's table shape and asserts only the tuple buckets are returned under the index name; differential on unpatched code fails with the merged-sequence behavior.
  • Full ./pkg/dbutil/ bucket tests pass.
sync-diff-inspector: fix "analyze value ... failed" when an index shares its name with a column (column and index statistics no longer merge under one key)

GetBucketsInfo keyed both column statistics (is_index=0, scalar
bounds) and index statistics (is_index=1, tuple bounds) by bare name
and appended into one map, so an index sharing its name with a column
merged two bucket sequences under one key. Chunk splitting then fed
scalar column bounds to AnalyzeValuesFromBuckets against the index's
columns and failed with 'analyze value 1683857 failed' — as happens
for a table whose first secondary index is named after its leading
column (KEY contentid (contentid, flag, datetime)).

Collect the two kinds into separate maps during the scan and merge at
the end, with the index entry winning its name: lookups by index name
must get the index statistics. The PRIMARY fallback now reads from the
column map directly, so a PK column named like another index keeps its
own entry.

Fixes pingcap#904
@ti-chi-bot

ti-chi-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jmpotato for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

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

Details 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 commented Aug 22, 2026

Copy link
Copy Markdown

Hi @yzxcj797. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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 kubernetes-sigs/prow repository.

@ti-chi-bot

ti-chi-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

Welcome @yzxcj797!

It looks like this is your first PR to pingcap/tidb-tools 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb-tools. 😃

@pingcap-cla-assistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sync-diff-inspector: analyze value 1683857 failed when index name equals column name

1 participant