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

planner: tot_col_size in mysql.stats_histograms might be a negative number #55126

Closed
qw4990 opened this issue Aug 1, 2024 · 1 comment · Fixed by #55327 or #56631
Closed

planner: tot_col_size in mysql.stats_histograms might be a negative number #55126

qw4990 opened this issue Aug 1, 2024 · 1 comment · Fixed by #55327 or #56631
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. 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. component/statistics report/customer Customers have encountered this bug. severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Aug 1, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

image

It seems like the negative number is caused by this modification: https://github.com/pingcap/tidb/blob/v6.5.6/table/tables/tables.go#L477-L490

The current method to maintain the col_size:

  1. update mysql.stats_histograms.tot_col_size each time when there is a DML statement (see https://github.com/pingcap/tidb/blob/v6.5.6/table/tables/tables.go#L477-L490);
  2. calculate avg_col_size by mysql.stats_histograms.tot_col_size / mysql.stats_histograms.not_null_count when actually using it in the cost model;

The behavior above seems overly complex, which might cause unexpected result like the negative number here.
A better/simpler/robuster way to maintain avg_col_size seems to calculate and store it directly in analyze.

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

The tot_col_size should be equal or large than 0.

3. What did you see instead (Required)

A negative number.

4. What is your TiDB version? (Required)

v6.5.6

@qw4990 qw4990 added type/bug The issue is confirmed as a bug. component/statistics sig/planner SIG: Planner severity/moderate labels Aug 1, 2024
@jebter jebter added the affects-6.5 This bug affects the 6.5.x(LTS) versions. label Aug 8, 2024
@ti-chi-bot ti-chi-bot added affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.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. labels Aug 11, 2024
@seiya-annie
Copy link

/report customer

@ti-chi-bot ti-chi-bot bot added the report/customer Customers have encountered this bug. label Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. 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. component/statistics report/customer Customers have encountered this bug. severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
4 participants