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: remove unreachable code #16996

Merged
merged 4 commits into from May 13, 2024

Conversation

hi-rustin
Copy link
Member

@hi-rustin hi-rustin commented May 11, 2024

What is changed and how it works?

Removed some unreachable code. The code is now unreachable as TiDB no longer sends mixed analyze requests to TiKV if the statistics version is set to 2.

You can only find one reference of the mixed request type in TiDB.

image

You can find it here: https://github.com/pingcap/tidb/blob/12b37d88dceb4eb4da6fe316fb4d0af2024ab58b/pkg/executor/builder.go#L2706

But for version 2, we use buildAnalyzeSamplingPushdown to build the analysis task.

image

Issue Number: Ref #16463

What's Changed:

statistics: remove unreachable code

The code is now unreachable as TiDB no longer
sends mixed analyze requests to TiKV if the
statistics version is set to 2.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

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

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

None

Copy link
Contributor

ti-chi-bot bot commented May 11, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Connor1996
  • JmPotato

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.

Copy link
Member Author

@hi-rustin hi-rustin 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.)

Copy link
Member

@Connor1996 Connor1996 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 ti-chi-bot bot added the status/LGT1 Status: PR - There is already 1 approval label May 11, 2024
Copy link
Member Author

@hi-rustin hi-rustin 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.)

Copy link
Member Author

@hi-rustin hi-rustin 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.)

@hi-rustin
Copy link
Member Author

hi-rustin commented May 11, 2024

Test locally:

  1. Start the tidb cluster with patch: tiup playground nightly --kv.binpath /Volumes/t7/code/tikv/target/aarch64-apple-darwin/debug/tikv-server
mysql>  select * from information_schema.cluster_info;
+---------+-----------------+-----------------+---------------------------+------------------------------------------+---------------------+--------------+-----------+
| TYPE    | INSTANCE        | STATUS_ADDRESS  | VERSION                   | GIT_HASH                                 | START_TIME          | UPTIME       | SERVER_ID |
+---------+-----------------+-----------------+---------------------------+------------------------------------------+---------------------+--------------+-----------+
| tidb    | 127.0.0.1:4000  | 127.0.0.1:10080 | 8.2.0-alpha-3-g79c1499bec | 79c1499bec7e609a051634c87460511b203c5389 | 2024-05-11 15:01:48 | 9m0.4416s    |       713 |
| pd      | 127.0.0.1:2379  | 127.0.0.1:2379  | 8.2.0-alpha-1-g4a7bffcb3  | 4a7bffcb3baf7a8e2515e70834d8567bc17439da | 2024-05-11 15:01:18 | 9m30.441602s |         0 |
| tiflash | 127.0.0.1:3930  | 127.0.0.1:20292 | 8.2.0-alpha-17-g8e50de84e | 8e50de84e6d6ecdcc108990217b70b6bb3f50271 | 2024-05-11 15:01:55 | 8m53.441603s |         0 |
| tikv    | 127.0.0.1:20160 | 127.0.0.1:20180 | 8.2.0-alpha               | 87c9a2a0965ae512fd254e26733ccc0c424bb36a | 2024-05-11 15:01:27 | 9m21.441603s |         0 |
+---------+-----------------+-----------------+---------------------------+------------------------------------------+---------------------+--------------+-----------+
4 rows in set (0.01 sec)
  1. Create a table and analyze with stats version 2:
create table t(a int);
import { Client } from "https://deno.land/x/mysql/mod.ts";

const client = await new Client().connect({
  hostname: "127.0.0.1",
  port: 4000,
  username: "root",
  db: "test",
  password: "",
});

for (let i = 0; i < 2000; i++) {
  await client.execute(`INSERT INTO t (a) VALUES (?)`, [i]);
  if (i % 2 === 0) {
    await client.execute(`INSERT INTO t (a) VALUES (?)`, [i]);
  }
}

await client.close();;
analyze table t;
image 4. Create another table and analyze it with statistics version 1:
create table t1(a int);
import { Client } from "https://deno.land/x/mysql/mod.ts";

const client = await new Client().connect({
  hostname: "127.0.0.1",
  port: 4000,
  username: "root",
  db: "test",
  password: "",
});

for (let i = 0; i < 2000; i++) {
  await client.execute(`INSERT INTO t1 (a) VALUES (?)`, [i]);
  if (i % 2 === 0) {
    await client.execute(`INSERT INTO t1 (a) VALUES (?)`, [i]);
  }
}

await client.close();;
set @@session.tidb_analyze_version=1;
analyze table t1;
image
  1. Create a new table with a string index:
create table t2(a varchar(50), b int, PRIMARY KEY (a));
import { Client } from "https://deno.land/x/mysql/mod.ts";

const client = await new Client().connect({
  hostname: "127.0.0.1",
  port: 4000,
  username: "root",
  db: "test",
  password: "",
});

for (let i = 0; i < 2000; i++) {
  const a = `string${i}`;
  const b = i;
  await client.execute(`INSERT INTO t2 (a, b) VALUES (?, ?)`, [a, b]);
}

await client.close();
set @@session.tidb_analyze_version=1;
analyze table t2;
image

Copy link
Contributor

ti-chi-bot bot commented May 11, 2024

@time-and-fate: 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:

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.

The code is now unreachable as TiDB no longer
sends mixed analyze requests to TiKV if the
statistics version is set to 2.

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@ti-chi-bot ti-chi-bot bot added status/LGT2 Status: PR - There are already 2 approvals and removed status/LGT1 Status: PR - There is already 1 approval labels May 13, 2024
@hi-rustin
Copy link
Member Author

hi-rustin commented May 13, 2024

For the backward compatibility:

  1. This code has been unreachable since v5.1.0.
  2. For tidb v5.0.x, we didn't allow users to use the analysis version 2.
image

@overvenus
Copy link
Member

/merge

Copy link
Contributor

ti-chi-bot bot commented May 13, 2024

@overvenus: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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

ti-chi-bot bot commented May 13, 2024

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

Commit hash: cca919d

@ti-chi-bot ti-chi-bot bot added the status/can-merge Status: Can merge to base branch label May 13, 2024
@ti-chi-bot ti-chi-bot bot merged commit 911f200 into tikv:master May 13, 2024
7 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none size/M status/can-merge Status: Can merge to base branch status/LGT2 Status: PR - There are already 2 approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants