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: split lock stats handler and rewrite the insert SQL #46403

Merged
merged 10 commits into from
Aug 29, 2023

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Aug 24, 2023

What problem does this PR solve?

Issue Number: ref #46351

Problem Summary:

What is changed and how it works?

  • Split the lock stats handler.
  • Split the AddLockedTables function to small functions.
  • Rewrote the INSERT SQL.
  • Only try to execute the SQL if the table is not locked.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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 release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 24, 2023
@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #46403 (31d4eff) into master (c9b8d9c) will decrease coverage by 0.6781%.
Report is 32 commits behind head on master.
The diff coverage is 56.4220%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46403        +/-   ##
================================================
- Coverage   73.4051%   72.7270%   -0.6782%     
================================================
  Files          1293       1322        +29     
  Lines        393587     402490      +8903     
================================================
+ Hits         288913     292719      +3806     
- Misses        86314      91363      +5049     
- Partials      18360      18408        +48     
Flag Coverage Δ
integration 25.7840% <5.0458%> (?)
unit 73.5655% <56.4220%> (+0.1604%) ⬆️

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

Components Coverage Δ
dumpling 54.0444% <ø> (ø)
parser 85.1752% <ø> (+0.1118%) ⬆️
br 47.9509% <ø> (-4.4156%) ⬇️

@Rustin170506 Rustin170506 changed the title executor/lockstats: reuse the same code and return err earlier statistics: split lock stats handler and rewrite the insert SQL Aug 24, 2023
@Rustin170506 Rustin170506 marked this pull request as draft August 24, 2023 10:10
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 24, 2023
statistics: update SQL

statistics: add tests
@Rustin170506 Rustin170506 marked this pull request as ready for review August 28, 2023 06:21
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 28, 2023
@Rustin170506
Copy link
Member Author

Rustin170506 commented Aug 28, 2023

  1. Start the TiDB cluster: tiup playground nightly --tiflash 0 --db.binpath /Users/hi-rustin/GolandProjects/tidb/bin/tidb-server
  2. Create table and analyze it:
create table t(a int, b int);
insert into t values (1,2), (3,4), (5,6), (7,8);
analyze table t;
show warnings;
  1. Lock table: lock stats t;
  2. Analyze it again: analyze table t;
  3. Check the warnings: show warnings;
mysql> show warnings;
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                 |
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Note    | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t, reason to use this rate is "use min(1, 110000/4) as the sample-rate=1" |
| Warning | 1105 | skip analyze locked table: t                                                                                                            |
+---------+------+-----------------------------------------------------------------------------------------------------------------------------------------+
  1. Check the mysql.stats_table_locked table:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from stats_table_locked;
+----------+--------------+-------+--------------------+
| table_id | modify_count | count | version            |
+----------+--------------+-------+--------------------+
|       98 |            4 |     4 | 443863948666601483 |
+----------+--------------+-------+--------------------+
1 row in set (0.00 sec)
  1. Try to lock it again: lock stats t;
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> lock stats t;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+-----------------------------------+
| Level   | Code | Message                           |
+---------+------+-----------------------------------+
| Warning | 1105 | skip locking locked table: test.t |
+---------+------+-----------------------------------+
1 row in set (0.00 sec)

Co-authored-by: Yuanjia Zhang <qw4990@163.com>
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 28, 2023
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 29, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 29, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-08-28 11:49:07.036336878 +0000 UTC m=+1754911.585352865: ☑️ agreed by qw4990.
  • 2023-08-29 04:01:41.218691489 +0000 UTC m=+1813265.767707476: ☑️ agreed by time-and-fate.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 29, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, qw4990, time-and-fate

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 [hawkingrei,qw4990,time-and-fate]

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

@Rustin170506
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 603a15f into pingcap:master Aug 29, 2023
5 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved component/statistics lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants