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: add protection to avoid setting tot_col_size to negative numbers #55327

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Aug 9, 2024

What problem does this PR solve?

Issue Number: close #55126

Problem Summary: planner: add protection to avoid setting tot_col_size to negative numbers

What changed and how does it work?

See more details and analysis in the issue.
When updating tot_col_size, use GREATEST to protect it from becoming a negative number.

Hard to use UT to test it, so I tested it manually locally:

First I hacked the code below to simulate all positive updates on tot_col_size are lost:
image

Then execute those SQLs:

mysql> create table t (a varchar(100), key(a));
Query OK, 0 rows affected (0.01 sec)

mysql> analyze table t;
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> insert into t values (space(100));
Query OK, 1 row affected (0.01 sec)

mysql> update t set a="";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Then we can see the tot_col_size becomes a negative number:

mysql> show stats_histograms;
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation | Load_status | Total_mem_usage | Hist_mem_usage | Topn_mem_usage | Cms_mem_usage |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| test    | t          |                | a           |        0 | 2024-08-09 14:39:42 |              0 |          0 |         -101 |           0 | allLoaded   |               0 |              0 |              0 |             0 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+

After this PR, this case won't happen, at least we can ensure it's equal or larger than 0:

mysql> show stats_histograms;
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation | Load_status | Total_mem_usage | Hist_mem_usage | Topn_mem_usage | Cms_mem_usage |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| test    | t          |                | a           |        0 | 2024-08-09 14:47:16 |              0 |          0 |            0 |           0 | allLoaded   |               0 |              0 |              0 |             0 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+

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-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/planner SIG: Planner labels Aug 9, 2024
Copy link

tiprow bot commented Aug 9, 2024

Hi @qw4990. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Aug 9, 2024
Copy link
Member

@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.

Looks good to me. Thanks! 👍

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 9, 2024
Copy link

ti-chi-bot bot commented Aug 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, hi-rustin

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 9, 2024
Copy link

ti-chi-bot bot commented Aug 9, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-09 06:51:19.449852286 +0000 UTC m=+594009.316951367: ☑️ agreed by hi-rustin.
  • 2024-08-09 06:53:38.503660836 +0000 UTC m=+594148.370759922: ☑️ agreed by hawkingrei.

@qw4990
Copy link
Contributor Author

qw4990 commented Aug 9, 2024

/test mysql-test

Copy link

tiprow bot commented Aug 9, 2024

@qw4990: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test mysql-test

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.

Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 75.3320%. Comparing base (b066365) to head (c57d6cd).
Report is 81 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55327        +/-   ##
================================================
+ Coverage   74.7027%   75.3320%   +0.6292%     
================================================
  Files          1570       1570                
  Lines        364767     443291     +78524     
================================================
+ Hits         272491     333940     +61449     
- Misses        72509      88739     +16230     
- Partials      19767      20612       +845     
Flag Coverage Δ
integration 51.1343% <75.0000%> (?)
unit 71.8280% <75.0000%> (-1.8035%) ⬇️

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

Components Coverage Δ
dumpling 52.9567% <ø> (-2.2327%) ⬇️
parser ∅ <ø> (∅)
br 62.9417% <ø> (+15.3240%) ⬆️

@hawkingrei
Copy link
Member

/retest

@ti-chi-bot ti-chi-bot bot merged commit 4d384d3 into pingcap:master Aug 9, 2024
22 of 23 checks passed
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. label Aug 13, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Aug 13, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #55380.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #55523.

ti-chi-bot bot pushed a commit that referenced this pull request Aug 20, 2024
@winoros
Copy link
Member

winoros commented Aug 23, 2024

/cherrypick release-7.5
/cherrypick release-7.1

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Aug 23, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

@winoros: new pull request created to branch release-7.1: #55628.

In response to this:

/cherrypick release-7.5
/cherrypick release-7.1

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 ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

@winoros: new pull request created to branch release-7.5: #55629.

In response to this:

/cherrypick release-7.5
/cherrypick release-7.1

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 ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. ok-to-test Indicates a PR is ready to be tested. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner: tot_col_size in mysql.stats_histograms might be a negative number
5 participants