Skip to content

importinto: update stats using UpdateStatsMeta#63269

Merged
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
D3Hunter:nextgen-import-table-stats
Sep 2, 2025
Merged

importinto: update stats using UpdateStatsMeta#63269
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
D3Hunter:nextgen-import-table-stats

Conversation

@D3Hunter

@D3Hunter D3Hunter commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #61702

Problem Summary:

What changed and how does it work?

previously, we update the stats inside the sessionVars, and depends on the deltaUpdateTickerWorker to update them at regular interval, but in nextgen wen don't have such worker for user ks since we are inside SYSTEM ks, so change to update stats using UpdateStatsMeta.

Check List

Tests

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

before the pr, the stats_meta is not updated

mysql> select * from mysql.stats_meta where table_id in(select tidb_table_id from information_schema.tables where table_name in('sys','ks1','t'));
+--------------------+----------+--------------+-------+----------+-------------------------------+
| version            | table_id | modify_count | count | snapshot | last_stats_histograms_version |
+--------------------+----------+--------------+-------+----------+-------------------------------+
| 460514792177401872 |        7 |            0 |     0 |        0 |            460514792177401872 |
+--------------------+----------+--------------+-------+----------+-------------------------------+

after the pr

mysql> import into t from 's3://mybucket/1024.csv?access-key=minioadmin&secret-access-key=minioadmin&endpoint=http%3a%2f%2f0.0.0.0%3a9000';


+--------+-----------+--------------------------------------------------------------------------------------------------------+--------------+----------+-------+----------+------------------+---------------+----------------+----------------------------+----------------------------+----------------------------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
| Job_ID | Group_Key | Data_Source                                                                                            | Target_Table | Table_ID | Phase | Status   | Source_File_Size | Imported_Rows | Result_Message | Create_Time                | Start_Time                 | End_Time                   | Created_By | Last_Update_Time           | Cur_Step | Cur_Step_Processed_Size | Cur_Step_Total_Size | Cur_Step_Progress_Pct | Cur_Step_Speed | Cur_Step_ETA |
+--------+-----------+--------------------------------------------------------------------------------------------------------+--------------+----------+-------+----------+------------------+---------------+----------------+----------------------------+----------------------------+----------------------------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+
|      2 | NULL      | s3://mybucket/1024.csv?access-key=xxxxxx&endpoint=http%3A%2F%2F0.0.0.0%3A9000&secret-access-key=xxxxxx | `test`.`t`   |       10 |       | finished | 13.72KiB         |          1024 |                | 2025-09-01 18:56:33.618220 | 2025-09-01 18:56:34.558693 | 2025-09-01 18:56:43.084532 | root@%     | 2025-09-01 18:56:43.084532 | NULL     | NULL                    | NULL                | NULL                  | NULL           | NULL         |
+--------+-----------+--------------------------------------------------------------------------------------------------------+--------------+----------+-------+----------+------------------+---------------+----------------+----------------------------+----------------------------+----------------------------+------------+----------------------------+----------+-------------------------+---------------------+-----------------------+----------------+--------------+

after a while, see table id 10

mysql> select count(1) row_count from mysql.stats_top_n where table_id in(select tidb_table_id from information_schema.tables where table_name in('sys','ks1','t'));
+-----------+
| row_count |
+-----------+
|       130 |
+-----------+
1 row in set (0.01 sec)

mysql> select * from mysql.stats_histograms where table_id in(select tidb_table_id from information_schema.tables where table_name in('sys','ks1','t'));
+----------+----------+---------+----------------+------------+--------------+--------------+--------------------+----------------------+-----------+------+---------------------+------------------------------------+
| table_id | is_index | hist_id | distinct_count | null_count | tot_col_size | modify_count | version            | cm_sketch            | stats_ver | flag | correlation         | last_analyze_pos                   |
+----------+----------+---------+----------------+------------+--------------+--------------+--------------------+----------------------+-----------+------+---------------------+------------------------------------+
|        7 |        0 |       1 |              0 |          0 |            0 |            0 | 460514680139415566 | NULL                 |         0 |    0 |                   0 | NULL                               |
|       10 |        0 |       3 |              0 |          0 |            0 |            0 | 460514707140509713 | NULL                 |         0 |    0 |                   0 | NULL                               |
|       10 |        0 |       4 |              0 |          0 |            0 |            0 | 460514707140509713 | NULL                 |         0 |    0 |                   0 | NULL                               |
|       10 |        0 |       1 |             64 |          0 |         8192 |            0 | 460514710312452097 | NULL                 |         2 |    0 | 0.07804878048780488 | NULL                               |
|       10 |        0 |       2 |              1 |          0 |         4096 |            0 | 460514710312452097 | NULL                 |         2 |    0 |                   1 | NULL                               |
|       10 |        1 |       1 |             64 |          0 |         8192 |            0 | 460514710312452097 | NULL                 |         2 |    0 |                   0 | NULL                               |
|       10 |        1 |       2 |              1 |          0 |         4096 |            0 | 460514710312452097 | NULL                 |         2 |    0 |                   0 | NULL                               |
+----------+----------+---------+----------------+------------+--------------+--------------+--------------------+----------------------+-----------+------+---------------------+------------------------------------+
7 rows in set (0.01 sec)

mysql> select * from mysql.stats_meta where table_id in(select tidb_table_id from information_schema.tables where table_name in('sys','ks1','t'));
+--------------------+----------+--------------+-------+--------------------+-------------------------------+
| version            | table_id | modify_count | count | snapshot           | last_stats_histograms_version |
+--------------------+----------+--------------+-------+--------------------+-------------------------------+
| 460514681725124609 |        7 |            6 |     6 |                  0 |            460514680139415566 |
| 460514710312452097 |       10 |            0 |  1024 | 460514710286237703 |            460514710312452097 |
+--------------------+----------+--------------+-------+--------------------+-------------------------------+
  • 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-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 28, 2025
@codecov

codecov Bot commented Aug 28, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.2432%. Comparing base (aabb693) to head (51cf719).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #63269        +/-   ##
================================================
+ Coverage   72.7782%   73.2432%   +0.4650%     
================================================
  Files          1832       1832                
  Lines        495769     495883       +114     
================================================
+ Hits         360812     363201      +2389     
+ Misses       113016     110833      -2183     
+ Partials      21941      21849        -92     
Flag Coverage Δ
integration 42.0303% <0.0000%> (?)
unit 72.3098% <75.0000%> (+0.0542%) ⬆️

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

Components Coverage Δ
dumpling 52.8700% <ø> (ø)
parser ∅ <ø> (∅)
br 46.5193% <ø> (+0.0101%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@D3Hunter D3Hunter changed the title importinto: update stats using UpdateStatsMeta [wip]importinto: update stats using UpdateStatsMeta Aug 28, 2025
@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 28, 2025
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 1, 2025
@D3Hunter D3Hunter changed the title [wip]importinto: update stats using UpdateStatsMeta importinto: update stats using UpdateStatsMeta Sep 1, 2025
@ti-chi-bot ti-chi-bot Bot removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-linked-issue labels Sep 1, 2025
@D3Hunter

D3Hunter commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Sep 1, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@D3Hunter

D3Hunter commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-nextgen-20250815

@ti-chi-bot

Copy link
Copy Markdown
Member

@D3Hunter: once the present PR merges, I will cherry-pick it on top of release-nextgen-20250815 in the new PR and assign it to you.

Details

In response to this:

/cherry-pick release-nextgen-20250815

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 ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 2, 2025
Comment on lines 67 to +69
testfailpoint.Enable(s.T(), "github.com/pingcap/tidb/pkg/domain/deltaUpdateDuration", `return`)
testfailpoint.Enable(s.T(), "github.com/pingcap/tidb/pkg/util/cpu/mockNumCpu", "return(16)")
bak := vardef.GetStatsLease()

@joechenrh joechenrh Sep 2, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we can remove L67 now, previously I used failpoint to reduce stat update interval... But it's ok to keep it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

let's keep it, there is a random duration added there, at most 1minute

tidb/pkg/domain/domain.go

Lines 2229 to 2234 in 98bbd14

// We need to have different nodes trigger tasks at different times to avoid the herd effect.
randDuration := time.Duration(rand.Int63n(int64(time.Minute)))
updateDuration := 20*lease + randDuration
failpoint.Inject("deltaUpdateDuration", func() {
updateDuration = 20 * time.Second
})

@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: GMHDBJD, joechenrh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 Sep 2, 2025
@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2025

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2025-09-02 02:36:41.317821125 +0000 UTC m=+839693.195652079: ☑️ agreed by GMHDBJD.
  • 2025-09-02 02:36:51.89302301 +0000 UTC m=+839703.770853965: ☑️ agreed by joechenrh.

@D3Hunter

D3Hunter commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

/retest

@tiprow

tiprow Bot commented Sep 2, 2025

Copy link
Copy Markdown

@D3Hunter: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

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.

@ti-chi-bot ti-chi-bot Bot merged commit 72427c5 into pingcap:master Sep 2, 2025
26 checks passed
@ti-chi-bot

Copy link
Copy Markdown
Member

@D3Hunter: new pull request created to branch release-nextgen-20250815: #63322.

Details

In response to this:

/cherry-pick release-nextgen-20250815

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.

@D3Hunter D3Hunter deleted the nextgen-import-table-stats branch September 2, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. 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.

4 participants