Skip to content
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

statistics: fix Clone method to include checked field in ColAndIdxExistenceMap #60171

Merged
merged 3 commits into from
Mar 20, 2025

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Mar 19, 2025

What problem does this PR solve?

Issue Number: close #60104

Problem Summary:

What changed and how does it work?

We should also clone the checked field. Otherwise, the sync load will mistakenly attempt to load the stats of a non-existent index.

Note: This bug only occurs when there are no further writes to the table. Otherwise, the stats item is correctly updated as checked, preventing this issue from happening.

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.

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed do-not-merge/needs-triage-completed labels Mar 19, 2025
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.8824%. Comparing base (7b81ae6) to head (d118e34).
Report is 7 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #60171        +/-   ##
================================================
+ Coverage   73.1557%   73.8824%   +0.7266%     
================================================
  Files          1708       1738        +30     
  Lines        471636     480570      +8934     
================================================
+ Hits         345029     355057     +10028     
+ Misses       105420     103596      -1824     
- Partials      21187      21917       +730     
Flag Coverage Δ
integration 45.5732% <100.0000%> (?)
unit 72.4348% <100.0000%> (+0.0659%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 47.2537% <ø> (+0.0194%) ⬆️
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Rustin170506
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Mar 20, 2025
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 20, 2025
Copy link
Member Author

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔢 Self-check (PR reviewed by myself and ready for feedback.)

@Rustin170506
Copy link
Member Author

Tested locally:

  1. Start the TiDB cluster with patch: tiup playground v8.5.1 --db.binpath /Users/rustin/code/tidb/bin/tidb-server
  2. Run queries:
USE test;
CREATE TABLE t1 (a INT, b INT, c INT);
CREATE TABLE t2 (a INT, b INT, c INT);
CREATE TABLE t3 (a INT, b INT, c INT);
CREATE TABLE t4 (a INT, b INT, c INT);

INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
INSERT INTO t4 VALUES (3,2,0), (4,2,0);

-- Wait for stats to be fully loaded
SHOW STATS_META;

CREATE INDEX idx_b ON t2(b);

SELECT t2.a, t2.b, t3.a, t3.b, t4.a, t4.b
  FROM (t3, t4)
       LEFT JOIN
       (t1, t2)
       ON t3.a = 1 AND t3.b = t2.b AND t2.b = t4.b
  ORDER BY 1, 2, 3, 4, 5;
  1. Start a new TiDB(I use a debug instance):
USE test;
SELECT t2.a, t2.b, t3.a, t3.b, t4.a, t4.b
  FROM (t3, t4)
       LEFT JOIN
       (t1, t2)
       ON t3.a = 1 AND t3.b = t2.b AND t2.b = t4.b
  ORDER BY 1, 2, 3, 4, 5;
  1. Check the logs, there are no warnings at all.

@Rustin170506
Copy link
Member Author

/retest

@Rustin170506 Rustin170506 requested a review from Copilot March 20, 2025 07:33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes the Clone method in the ColAndIdxExistenceMap by including the checked field, which prevents the sync load from attempting to load stats for a non-existent index.

  • Added a test in table_test.go to validate the complete cloning behavior.
  • Updated the Clone method in table.go to copy the checked field along with the analyzed maps.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
pkg/statistics/table.go Clone method now includes the checked field
pkg/statistics/table_test.go Added test to validate Clone method copying all fields
Files not reviewed (1)
  • pkg/statistics/BUILD.bazel: Language not supported
Copy link

ti-chi-bot bot commented Mar 20, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, lance6716

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 approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 20, 2025
Copy link

ti-chi-bot bot commented Mar 20, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-20 01:56:31.725118661 +0000 UTC m=+493485.409354756: ☑️ agreed by lance6716.
  • 2025-03-20 08:01:18.002841525 +0000 UTC m=+515371.687077607: ☑️ agreed by hawkingrei.

@Rustin170506
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit d406be6 into pingcap:master Mar 20, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to retrieve the histogram metadata record for the newly added indexes
3 participants