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

A Practical Guide For SQL Tuning #19108

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

Conversation

dbsid
Copy link
Contributor

@dbsid dbsid commented Oct 14, 2024

First-time contributors' checklist

What is changed, added or deleted? (Required)

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v8.4 (TiDB 8.4 versions)
  • v8.3 (TiDB 8.3 versions)
  • v8.2 (TiDB 8.2 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)
  • v5.3 (TiDB 5.3 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

@dbsid dbsid marked this pull request as draft October 14, 2024 02:00
@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. contribution This PR is from a community contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Oct 14, 2024
Copy link

ti-chi-bot bot commented Oct 14, 2024

Hi @dbsid. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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/test-infra repository.

@ti-chi-bot ti-chi-bot bot added missing-translation-status This PR does not have translation status info. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 14, 2024
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 14, 2024
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 17, 2024
@dbsid dbsid marked this pull request as ready for review November 11, 2024 02:37
@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 Nov 11, 2024
@Oreoxmt Oreoxmt self-requested a review November 11, 2024 03:16
@Oreoxmt Oreoxmt self-assigned this Nov 11, 2024
@Oreoxmt Oreoxmt added the translation/doing This PR's assignee is translating this PR. label Nov 11, 2024
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
TiDB uses a cost-based optimizer (CBO) to determine the most efficient execution plan for a SQL statement. This optimizer evaluates different execution strategies and chooses the one with the lowest estimated cost. The cost is influenced by factors such as:

- SQL
- Schema Design

Choose a reason for hiding this comment

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

Should we also add a section about the schema design? For example, do not use auto-increment attribute if you need to specify a specific value for this column; do not use partition table when data were not cleaned up by partitions. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think after we put the best practice for the partition table online, we can add a schema design session and link to the partition table document

sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Show resolved Hide resolved
@Oreoxmt Oreoxmt added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Dec 3, 2024
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Show resolved Hide resolved
Copy link
Member

@time-and-fate time-and-fate left a comment

Choose a reason for hiding this comment

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

And looks like the format and terminology also need improvement. Like

  1. Wrap `` for column/table names, text from SQL text, texts from EXPLAIN ANALYZE, operator names, etc.
  2. Unify the capitalizations. Like "hash join", "Hash Join", "HashJoin", "TOPN", "TopN", "TopN", "top-N", "Point Get", "Point_Get", etc.

Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

My review part 1. Good structure and clear explanations, only some minor suggestions, feel free to ignore :)

sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
dbsid and others added 2 commits December 4, 2024 20:48
Co-authored-by: Mattias Jonsson <[email protected]>
Co-authored-by: Zhou Kunqin <[email protected]>
Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

Very good job with examples and explanations. I only have some minor questions and suggestions!

sql-tuning-best-practice.md Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
sql-tuning-best-practice.md Outdated Show resolved Hide resolved
Copy link

ti-chi-bot bot commented Dec 4, 2024

@mjonss: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

Very good job with examples and explanations. I only have some minor questions and suggestions!

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.

@mjonss
Copy link
Contributor

mjonss commented Dec 4, 2024

Maybe @mjonss can check if we could/should add more details about partitioning

@dveeden I think this PR is big enough as-is, I create a follow up, #19578, instead.

Copy link

ti-chi-bot bot commented Dec 13, 2024

@Yui-Song: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.2 Should cherry pick this PR to release-8.2 branch. needs-cherry-pick-release-8.3 Should cherry pick this PR to release-8.3 branch. needs-cherry-pick-release-8.4 Should cherry pick this PR to release-8.4 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. ok-to-test Indicates a PR is ready to be tested. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. translation/doing This PR's assignee is translating this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants