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

Stats GC: Unexpected behavior that an existing table with one record in stats_meta doesn't find its memory obj in memory cache #57956

Closed
winoros opened this issue Dec 3, 2024 · 6 comments
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. component/statistics severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@winoros
Copy link
Member

winoros commented Dec 3, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

No clear reproduce step, it's found in super big cluster testing with 1 million tables.

#57844
From the debugging image, you can see that
Image
Image
The log said that the table is not found in the memory cache. But we can read its table meta from infoschema and can read its stats meta from the physical table mysql.stats_meta.
And our stats initialization also reads all the things from mysql.stats_meta into memory.

So this could not find is very strange and should be treated as a bug.

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

current master

@winoros winoros added severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug. labels Dec 3, 2024
@winoros winoros added affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 labels Dec 3, 2024
@winoros
Copy link
Member Author

winoros commented Dec 3, 2024

Image
As you can see, it happened when we iterate rows read from mysql.stats_meta, which means that it did have a record in the kv storage. Then we got the table meta from infoschema and it succeeded.
So it did have stats.

@winoros
Copy link
Member Author

winoros commented Dec 3, 2024

In the testing env, this phenomenon also occurs when there's no foreground workload.
This makes this issue more strange :(

@winoros
Copy link
Member Author

winoros commented Dec 3, 2024

Another insight may be related to this issue.
Image
The unneeded analyze metrics differ from the two tidb nodes.
And the most unexpected not founds are coming from the tidb node1. But tidb node0 also has the log.

So this issue seems still to be related to the table not analyzed.

@winoros
Copy link
Member Author

winoros commented Dec 3, 2024

In this pull request https://github.com/pingcap/tidb/pull/52347/files#diff-3e2f686997ae61d9cca386e3d4430ada2d09002649faa0714340f0a9cd0dcf37R96 .
We've made sure that the put into cache would succeed finally. So I still believe that the init stats should be correct. 🤔

@winoros
Copy link
Member Author

winoros commented Dec 4, 2024

Similar to the issue #57901.
The stats' GC process also uses the same assumption.
Image
It directly uses the condition no row in mysql.stats_histograms without checking whether the table meta exists to decide the existence the of table.
So the table stats is wrongly deleted by gc process.
(And then being re-created when we dump row count changes into memory, and then loading into memory and being deleted by gc process again, hahaha...)

@winoros winoros changed the title Unexpected behavior that an existing table with one record in stats_meta doesn't find its memory obj in memory cache stats' gc process wrongly deletes the statistics of tables that are not analyzed in extreme situation Dec 4, 2024
@winoros winoros changed the title stats' gc process wrongly deletes the statistics of tables that are not analyzed in extreme situation Unexpected behavior that an existing table with one record in stats_meta doesn't find its memory obj in memory cache Dec 4, 2024
@Rustin170506 Rustin170506 moved this to 🏊WIP in 😆Stats Dec 18, 2024
@Rustin170506 Rustin170506 changed the title Unexpected behavior that an existing table with one record in stats_meta doesn't find its memory obj in memory cache Stats GC: Unexpected behavior that an existing table with one record in stats_meta doesn't find its memory obj in memory cache Jan 9, 2025
@Rustin170506
Copy link
Member

@winoros If I understand correctly, this issue is dumpcate with #57983, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. component/statistics severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants