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: do not load unnecessary index statistics (#54060) #54087

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #54060

What problem does this PR solve?

Issue Number: close #54022

Problem Summary:

See more at the issue.

A quick summary:
If you have tidb_opt_objective='determine' enabled, it will trigger some async stats load for some tables. If there tables histogram isn't in the system, it would cause some problems when we try to load it.

What changed and how does it work?

Check that the index statistics are really needed before loading them.

If we don't check it here, it will cause some problems if the index statistics don't exist.

Note: We still don't know why the histogram record for the index is missing. There are some possible issues:

  1. When users create this table, they may not have created this index yet, so we don't create the record for it automatically. (But if this is the case, I don't why do we have the index in the stats cache information)
  2. It may have been accidentally dropped, but I can't find any scenario where we would only drop one index for a table.

What happened in the test case:

  1. We create a table and the statsHandle.Update(do.InfoSchema()) will load this table into the stats cache. You can test it by breakpoint here:
    image
  2. We drop the stats of the stats, it will clean up all system table records for this table.
  3. We insert some data and wait for the modfiy_count and the count is not null in the mysql.stats_meta.
  4. Try to select some data from this table by ID, it would trigger an async load. Then we get that bug.
    https://github.com/hi-rustin/tidb/blob/648fc6386aa9aabb365baf0912f1e18c4ab74d95/pkg/planner/core/logical_plan_builder.go#L4824
  5. So in the test case we check if the index is still in the needed item array after we fix it.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test
  • 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.

Fix a memory leak when loading index statistics.
修复加载 index 统计信息可能会造成内存泄漏的问题

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-7.1 This PR is cherry-picked to release-7.1 from a source PR. labels Jun 18, 2024
@ti-chi-bot ti-chi-bot bot added do-not-merge/cherry-pick-not-approved size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2024
@Rustin170506 Rustin170506 force-pushed the cherry-pick-54060-to-release-7.1 branch from 279e315 to 1d2fde1 Compare June 18, 2024 08:56
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 18, 2024
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 18, 2024
@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jun 18, 2024
@Rustin170506
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 18, 2024
Copy link

ti-chi-bot bot commented Jun 18, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-18 08:57:25.592179631 +0000 UTC m=+105172.077668463: ☑️ agreed by hi-rustin.
  • 2024-06-18 10:08:22.874711342 +0000 UTC m=+109429.360200173: ☑️ agreed by qw4990.

@hawkingrei
Copy link
Member

/retest

4 similar comments
@hawkingrei
Copy link
Member

/retest

@Rustin170506
Copy link
Member

/retest

@hawkingrei
Copy link
Member

/retest

@Rustin170506
Copy link
Member

/retest

Copy link

ti-chi-bot bot commented Sep 6, 2024

PR needs rebase.

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 added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 6, 2024
Signed-off-by: hi-rustin <[email protected]>
@Rustin170506 Rustin170506 force-pushed the cherry-pick-54060-to-release-7.1 branch from 1d2fde1 to 577c819 Compare November 11, 2024 03:45
Copy link

ti-chi-bot bot commented Nov 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qw4990, Rustin170506

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:
  • OWNERS [Rustin170506,qw4990]

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

Signed-off-by: Rustin170506 <[email protected]>
@Rustin170506 Rustin170506 removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2024
Signed-off-by: Rustin170506 <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 11, 2024
Signed-off-by: Rustin170506 <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2024
@Rustin170506
Copy link
Member

Because it doesn't have tidb_opt_objective, so I removed the test.

Signed-off-by: Rustin170506 <[email protected]>
@Rustin170506
Copy link
Member

/retest

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 18.75000% with 13 lines in your changes missing coverage. Please review.

Please upload report for BASE (release-7.1@bda92d4). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-7.1     #54087   +/-   ##
================================================
  Coverage               ?   73.6797%           
================================================
  Files                  ?       1212           
  Lines                  ?     382906           
  Branches               ?          0           
================================================
  Hits                   ?     282124           
  Misses                 ?      82972           
  Partials               ?      17810           

@Rustin170506
Copy link
Member

/retest

1 similar comment
@Rustin170506
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot merged commit 7578037 into pingcap:release-7.1 Nov 11, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. type/cherry-pick-for-release-7.1 This PR is cherry-picked to release-7.1 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants