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: refactor stats meta handling to use DeltaUpdate for multi-table support #58657

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Jan 2, 2025

What problem does this PR solve?

Issue Number: ref #57869

Problem Summary:

What changed and how does it work?

If you want to understand how it works, read more at #57869 (comment).

This PR split from #58331.

Just updated the UpdateStatsMeta can handle multiple detla table updates by taking a slice of DeltaUpdate as an argument.

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. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/needs-tests-checked labels Jan 2, 2025
@Rustin170506
Copy link
Member Author

/retest

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 78.78788% with 14 lines in your changes missing coverage. Please review.

Project coverage is 74.7839%. Comparing base (23ed0df) to head (22fbe79).
Report is 35 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #58657        +/-   ##
================================================
+ Coverage   73.0885%   74.7839%   +1.6953%     
================================================
  Files          1676       1707        +31     
  Lines        463646     482775     +19129     
================================================
+ Hits         338872     361038     +22166     
+ Misses       103927      99766      -4161     
- Partials      20847      21971      +1124     
Flag Coverage Δ
integration 46.8320% <0.0000%> (?)
unit 73.3877% <78.7878%> (+1.1047%) ⬆️

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

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 45.7539% <ø> (+0.0209%) ⬆️

@Rustin170506
Copy link
Member Author

/retest

@Rustin170506 Rustin170506 force-pushed the rustin-patch-multi-tables branch from de24b35 to 19b12d5 Compare January 3, 2025 05:34
Copy link
Member Author

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

🔢 Self-check (PR reviewed by myself and ready for feedback.)

}

// UpdateStatsMeta updates the stats meta for multiple tables.
// It uses the INSERT INTO ... ON DUPLICATE KEY UPDATE syntax to fill the missing records.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you update the function from one tabledelta to multi DeltaUpdate. But there is no code in PR to use the multi DeltaUpdate. Will/Where you use the multi interface in the future?
If the answer is yes, could you please add some test for the multi deltaupdate which is not same as the past.

Copy link
Member Author

@Rustin170506 Rustin170506 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the PR body, this PR split from #58331. You can find the usage from there.

If the answer is yes, could you please add some test for the multi deltaupdate which is not same as the past.

We have a lot of tests to check the count and modify_count. I think they have covered this change. To verify it independently, we need to use the mock session to execute the SQL. From my previous experience of using and maintaining it, it is difficult to understand and maintain. (Difficult to follow the mock logic and the mock framework.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also verified the SQL change.

  1. First create the test table:
CREATE TABLE IF NOT EXISTS mysql.stats_meta (
    version BIGINT UNSIGNED NOT NULL,
    table_id BIGINT UNSIGNED NOT NULL,
    modify_count BIGINT UNSIGNED NOT NULL DEFAULT 0,
    count BIGINT UNSIGNED NOT NULL DEFAULT 0,
    PRIMARY KEY (table_id)
) ENGINE=InnoDB;
  1. Insert initial test data:
INSERT INTO mysql.stats_meta (version, table_id, modify_count, count) 
VALUES (900, 100, 10, 25)
ON DUPLICATE KEY UPDATE 
    version = VALUES(version),
    modify_count = VALUES(modify_count),
    count = VALUES(count);
  1. array version of negative value handling SQL:
INSERT INTO mysql.stats_meta (version, table_id, modify_count, count) 
VALUES (1000, 100, 1, 10)
ON DUPLICATE KEY UPDATE 
    version = VALUES(version),
    modify_count = modify_count + VALUES(modify_count),
    count = IF(count > VALUES(count), count - VALUES(count), 0);
  1. or a single version of the negative value handling SQL:
INSERT INTO mysql.stats_meta (version, table_id, modify_count, count) 
VALUES (1000, 100, 1, 0)
ON DUPLICATE KEY UPDATE 
    version = VALUES(version),
    modify_count = modify_count + VALUES(modify_count),
    count = IF(count > 10, count - 10, 0);
  1. View results:
SELECT * FROM mysql.stats_meta WHERE table_id = 100;

For other changes, it is easy to follow, only for the negitive number there is a little refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is no good way to test multiple table updates now because we're not using it yet. I guess we can add some tests after we start using it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no problem leaving the manual testing steps in the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the PR body, this PR split from #58331. You can find the usage from there.

If the answer is yes, could you please add some test for the multi deltaupdate which is not same as the past.

We have a lot of tests to check the count and modify_count. I think they have covered this change. To verify it independently, we need to use the mock session to execute the SQL. From my previous experience of using and maintaining it, it is difficult to understand and maintain. (Difficult to follow the mock logic and the mock framework.)

OK, no question for me. Just want to know what is this PR used for.

@Rustin170506 Rustin170506 requested a review from elsa0520 January 6, 2025 06:02
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 6, 2025
Copy link

ti-chi-bot bot commented Jan 7, 2025

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Jan 7, 2025
Copy link

ti-chi-bot bot commented Jan 7, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-01-06 18:59:46.638436441 +0000 UTC m=+207329.927268146: ☑️ agreed by winoros.
  • 2025-01-07 07:22:28.294579274 +0000 UTC m=+251891.583410980: ☑️ agreed by qw4990.

@Rustin170506
Copy link
Member Author

/test all

@Rustin170506 Rustin170506 force-pushed the rustin-patch-multi-tables branch from 19b12d5 to 4b3bc0e Compare January 7, 2025 09:17
@Rustin170506
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 67249cb into pingcap:master Jan 7, 2025
25 checks passed
@Rustin170506 Rustin170506 deleted the rustin-patch-multi-tables branch January 7, 2025 14:31
breezewish added a commit that referenced this pull request Jan 8, 2025
…long-vector

* commit '510d0037b18f258f505abc6cf13a8128563e9359':
  *: upgrade pd client to make sure tso client initiate successfully (#58752)
  ttl, test: scale TTL workers during the fault tests (#58750)
  planner: improve warning messages for unsupported HASH_JOIN hints (#58646)
  planner: prealloc the slices in the SplitCorColAccessCondFromFilters (#58785)
  ddl: supports non-unique global index (#58678)
  util/stmtsummary: add the network traffic related fields (#58101)
  var: enable `pd_enable_follower_handle_region` as default (#58385)
  statistics: refactor stats meta handling to use DeltaUpdate for multi-table support (#58657)
  parser: move 'model' to 'ast' pkg (#58704)
  statistics: add recover to protect background task (#58739)
  disttask: cancel subtask context if scheduled away (#58615)
  *: don't handle live updates of column size (#58596)
  *: fix a bug for default_authentication_plugin (2) (#58723)
  dupdetect: gRPC cancel should trigger retry (#58542)
  *: fix a bug for default_authentication_plugin (#57391)
  distsql: Fix backoff execution info inaccurate issue (#58707)
@Rustin170506 Rustin170506 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Jan 13, 2025
@ti-chi-bot
Copy link
Member

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

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-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants