[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

stmtsummary: implement tidb_statements_stats, a cumulative version of statements_summary #57155

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

henrybw
Copy link
Contributor
@henrybw henrybw commented Nov 6, 2024

What problem does this PR solve?

Issue Number: ref #57147

Problem Summary: The statement summary tables are the current mechanism we have for collecting cumulative metrics about the execution and performance of SQL queries. However, these metrics aren't truly cumulative: they are refreshed at a regular interval, meaning the cumulative metrics collected for queries are reset, and their previous values are made accessible via a separate history table. For the workload repository, we want to be able to snapshot cumulative metrics aggregated over the lifetime of a TiDB instance, which the statement summary tables do not easily provide.

What is changed and how it works?

  • The statistics captured by the statement summaries for each interval have been factored out into a new struct, stmtSummaryStats, that each statement summary interval (stmtSummaryByDigestElement) now uses instead. The struct is embedded so existing field accesses continue to work as-is.
  • In the statement summary struct itself (stmtSummaryByDigest), add a new "cumulative" set of statistics (i.e. another stmtSummaryStats struct).
  • Create a new memory table, information_schema.tidb_statements_stats, that uses the same stmtSummaryRetriever as the statement summary tables.
  • Modify the column factories for the statement summary rows reader to accept an additional stmtSummaryStats parameter. For the existing statement summary tables, this parameter is the stmtSummaryStats struct embedded in the stmtSummaryByDigestElement (i.e. the same values as before). For the new cumulative statement stats table, this parameter is the cumulative stmtSummaryStats struct in the stmtSummaryByDigest. The column factories then read from this stmtSummaryStats parameter, rather than the stmtSummaryByDigestElement struct directly, thus making them polymorphic and able to work for both the cumulative and statements summary tables.
  • Add a cluster-wide version of the statement stats table: cluster_tidb_statements_stats.

(The diff for this PR is pretty large, so I'd recommend reading each individual commit one at a time, since they build on each other incrementally.)

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code
- Started tidb-server.
- Ran one query, e.g. `select 1;`.
- Verified that a row appeared for this query.
- Re-ran the query several more times.
- Verified that the cumulative stats in that row updated accordingly.
- Verified that the corresponding row in cluster_tidb_statements_stats updated accordingly.

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.

Add a new system table `INFORMATION_SCHEMA.TIDB_STATEMENTS_STATS` to provide cumulative metrics about the execution and performance of SQL queries on TiDB nodes.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 6, 2024
Copy link
tiprow bot commented Nov 6, 2024

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

Copy link
codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 77.63158% with 119 lines in your changes missing coverage. Please review.

Project coverage is 74.7522%. Comparing base (ae27921) to head (b6e59d5).
Report is 115 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57155        +/-   ##
================================================
+ Coverage   72.9008%   74.7522%   +1.8514%     
================================================
  Files          1672       1717        +45     
  Lines        461870     470110      +8240     
================================================
+ Hits         336707     351418     +14711     
+ Misses       104439      96625      -7814     
- Partials      20724      22067      +1343     
Flag Coverage Δ
integration 49.1877% <69.3609%> (?)
unit 72.2618% <77.6315%> (-0.0233%) ⬇️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 60.7032% <ø> (+15.5745%) ⬆️

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 6, 2024
@xhebox
Copy link
Contributor
xhebox commented Nov 15, 2024

/retest

Copy link
tiprow bot commented Nov 15, 2024

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

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.

@xhebox
Copy link
Contributor
xhebox commented Nov 15, 2024

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 15, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 15, 2024
Copy link
ti-chi-bot bot commented Nov 15, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-06 11:03:00.553226698 +0000 UTC m=+1038893.392382239: ☑️ agreed by djshow832.
  • 2024-11-15 04:52:59.029883883 +0000 UTC m=+591141.220752880: ☑️ agreed by xhebox.

@D3Hunter
Copy link
Contributor

/approve

infoschema part lgtm

Copy link
ti-chi-bot bot commented Nov 22, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: D3Hunter, djshow832, xhebox
Once this PR has been reviewed and has the lgtm label, please assign winoros for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@@ -64,6 +64,27 @@ func NewStmtSummaryReader(user *auth.UserIdentity, hasProcessPriv bool, cols []*
return reader
}

// GetStmtSummaryCumulativeRows gets statement summary rows with cumulative metrics.
func (ssr *stmtSummaryReader) GetStmtSummaryCumulativeRows() [][]types.Datum {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add some input parameters to only needed stats back?like only return records after some ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that is a good idea, but I'm not sure if it makes sense in this context. For in-memory tables like this, I think the kind of filtering you're referring to would be done at a higher level, by the executor.

Perhaps we could implement a "pushdown" mechanism (like predicate pushdown to TiKV) for in-memory tables like this. While that could be a useful feature, I think building something like that would be a pretty large project, and is thus out of scope for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner 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.

5 participants