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

*: optimize query statements summary table by avoid decode plan for each row #25892

Merged
merged 9 commits into from
Jul 6, 2021

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Before this PR, query the statemens summary table maybe very slow cause by decode plan, event the query doesn't need to read the plan.

Bench

Generate 3000 statements to filling statemens summary , and each SQL length is 10240 byte.

  1. Use loadgen to generated load:

    bin/loadgen payload  gen-stmt --stmt-cnt 3000 --query-len 10240 --host 172.16.5.40 --port 4019  --concurrency 10

    The generated SQL is look like this:

    select * from t_gen_stmt_1 where a = 1 or b = 1 or c = 1 
    union all
    select * from t_gen_stmt_2 where a = 2 or b = 2 or c = 2 
    union all
    ...
    ...
    ...
  2. Wait generated statements(SQL) fill in the statemens summary.

  3. Bench the SQL: select count(*) from information_schema.cluster_statements_summary_history;

Bellow is the bench result compare with the master:

Master This PR
Query duration 3.4s 7ms
Query memory consume 500MB < 1MB

Related TiDB memory consume metric is below:

Master:

image

This PR:

image

# What is changed and how it works?

This PR add a special stmtSummaryReader to read the statemens summary table data, and only 'decode' the needed column, avoid decode plan for each table row.

Also, this PR implements prune columns for LogicalMemTable if the mem table is statemens summary table. Otherwise, stmtSummaryReader still has to read all column since LogicalMemTable doesn't prune column.

Related changes

  • N/A

Check List

Tests

  • Unit test
  • Manual test

Side effects

    • N/A

Release note

  • N/A

Signed-off-by: crazycs <[email protected]>
Signed-off-by: crazycs <[email protected]>
@ti-chi-bot ti-chi-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 2, 2021
@sre-bot
Copy link
Contributor

sre-bot commented Jul 2, 2021

Please follow PR Title Format:

  • pkg [, pkg2, pkg3]: what's changed

Or if the count of mainly changed packages are more than 3, use

  • *: what's changed

@github-actions github-actions bot added the sig/execution SIG execution label Jul 2, 2021
@crazycs520 crazycs520 changed the title Opt stmt query *: optimize query statements summary table by avoid decode plan for each row Jul 2, 2021
@crazycs520
Copy link
Contributor Author

@djshow832 @winoros @ClSlaid PTAL

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520 crazycs520 requested review from djshow832 and ClSlaid and removed request for djshow832 July 2, 2021 06:36
executor/infoschema_reader.go Outdated Show resolved Hide resolved
util/stmtsummary/reader.go Show resolved Hide resolved
Signed-off-by: crazycs <[email protected]>
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 5, 2021
@ClSlaid
Copy link
Contributor

ClSlaid commented Jul 5, 2021

/LGTM

@ti-chi-bot
Copy link
Member

@ClSlaid: Please use GitHub review feature instead of /lgtm [cancel] when you want to submit review to the pull request.
For how to use GitHub review feature, see also this document provided by GitHub.

For the reason we drop support to the commands, see also this page.
This reply is being used as a temporary reply during the migration of review process and will be removed on July 1st.

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.

Copy link
Contributor

@ClSlaid ClSlaid left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Member

@ClSlaid: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

LGTM

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.

@crazycs520
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AilinKid
  • djshow832

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 6, 2021
@crazycs520
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 4cf9788

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 6, 2021
@ti-chi-bot ti-chi-bot merged commit a8d23fd into pingcap:master Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/sql-infra SIG: SQL Infra size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants