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

executor: disable paging for small limit (#41120) #41121

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #41120

What problem does this PR solve?

Issue Number: close #40741

What is changed and how it works?

  • disable paging for small limit DAG requests.
set @@tidb_enable_paging = 1;
use test;
drop table if exists ge1;

CREATE TABLE `ge1` (
  `actor_login` varchar(40) NOT NULL DEFAULT '',
  `id` bigint(20) NOT NULL DEFAULT '0',
  `type` varchar(29) NOT NULL DEFAULT 'Event',
  `action` varchar(11) NOT NULL DEFAULT '',
  `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `repo_id` bigint(20) NOT NULL DEFAULT '0',
  KEY (`repo_id`,`type`,`action`,`created_at`,`actor_login`))
PARTITION BY LIST COLUMNS(`type`)
( PARTITION `watch_event` VALUES IN ('WatchEvent'));

insert into ge1 value  ('xxy'        , 26332576530 , 'WatchEvent' , 'started' , '2023-01-10 12:00:06' , 41986369 ),
('DuWen'        , 26332576530 , 'WatchEvent' , 'started' , '2023-01-10 12:00:06' , 200039032 ),
('zzt'        , 26332576530 , 'WatchEvent' , 'started' , '2023-01-10 12:00:06' , 41986369 ),
('mmw'        , 26332576530 , 'WatchEvent' , 'started' , '2023-01-10 12:00:06' , 41986369 );

original

MySQL [test]> trace SELECT actor_login FROM ge1 WHERE type = 'WatchEvent' AND action = 'started' AND repo_id = 41986369 ORDER BY created_at limit 1;
+-------------------------------------------------------------------------+-----------------+------------+
| operation                                                               | startTS         | duration   |
+-------------------------------------------------------------------------+-----------------+------------+
| trace                                                                   | 02:00:03.937238 | 4.160278ms |
|   ├─session.ExecuteStmt                                                 | 02:00:03.937249 | 1.022849ms |
|   │ ├─executor.Compile                                                  | 02:00:03.937269 | 678.481µs  |
|   │ └─session.runStmt                                                   | 02:00:03.937989 | 248.746µs  |
|   │   └─distsql.Select                                                  | 02:00:03.938113 | 39.583µs   |
|   │     └─regionRequest.SendReqCtx                                      | 02:00:03.938255 | 978.998µs  |
|   │       ├─rpcClient.SendRequest, region ID: 15, type: Cop             | 02:00:03.938295 | 921.254µs  |
|   │       │ └─tikv.RPC                                                  | 02:00:03.938297 | 442.072µs  |
|   │       │   └─tikv.Wait                                               | 02:00:03.938297 | 77.812µs   |
|   │       │     └─tikv.GetSnapshot                                      | 02:00:03.938297 | 77.812µs   |
|   │       └─regionRequest.SendReqCtx                                    | 02:00:03.939272 | 577.443µs  |
|   │         ├─rpcClient.SendRequest, region ID: 15, type: Cop           | 02:00:03.939283 | 548.32µs   |
|   │         │ └─tikv.RPC                                                | 02:00:03.939284 | 190.851µs  |
|   │         │   └─tikv.Wait                                             | 02:00:03.939284 | 16.581µs   |
|   │         │     └─tikv.GetSnapshot                                    | 02:00:03.939284 | 16.581µs   |
|   │         └─regionRequest.SendReqCtx                                  | 02:00:03.939881 | 719.966µs  |
|   │           ├─rpcClient.SendRequest, region ID: 15, type: Cop         | 02:00:03.939891 | 675.607µs  |
|   │           │ └─tikv.RPC                                              | 02:00:03.939892 | 358.912µs  |
|   │           │   └─tikv.Wait                                           | 02:00:03.939892 | 37.794µs   |
|   │           │     └─tikv.GetSnapshot                                  | 02:00:03.939892 | 37.794µs   |
|   │           └─regionRequest.SendReqCtx                                | 02:00:03.940661 | 558.226µs  |
|   │             └─rpcClient.SendRequest, region ID: 15, type: Cop       | 02:00:03.940681 | 524.14µs   |
|   │               └─tikv.RPC                                            | 02:00:03.940682 | 213.454µs  |
|   │                 └─tikv.Wait                                         | 02:00:03.940682 | 19.889µs   |
|   │                   └─tikv.GetSnapshot                                | 02:00:03.940682 | 19.889µs   |
|   ├─*executor.ProjectionExec.Next                                       | 02:00:03.938283 | 3.030583ms |
|   │ └─*executor.TopNExec.Next                                           | 02:00:03.938286 | 3.016226ms |
|   │   ├─*executor.IndexReaderExecutor.Next                              | 02:00:03.938299 | 1.045114ms |
|   │   ├─*executor.IndexReaderExecutor.Next                              | 02:00:03.939370 | 1.897819ms |
|   │   └─*executor.IndexReaderExecutor.Next                              | 02:00:03.941282 | 5.307µs    |
|   └─*executor.ProjectionExec.Next                                       | 02:00:03.941323 | 18.616µs   |
|     └─*executor.TopNExec.Next                                           | 02:00:03.941325 | 12.205µs   |
+-------------------------------------------------------------------------+-----------------+------------+

MySQL [test]> explain analyze  SELECT actor_login FROM ge1 WHERE type = 'WatchEvent' AND action = 'started' AND repo_id = 41986369 ORDER BY created_at limit 1;
+-------------------------------+---------+---------+-----------+-------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------+-----------+------+
| id                            | estRows | actRows | task      | access object                                                                                   | execution info                                                                                                                                                                                                                       | operator info                                                                                           | memory    | disk |
+-------------------------------+---------+---------+-----------+-------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------+-----------+------+
| Projection_9                  | 0.00    | 1       | root      |                                                                                                 | time:2.86ms, loops:2, Concurrency:OFF                                                                                                                                                                                                | test.ge1.actor_login                                                                                    | 2.61 KB   | N/A  |
| └─TopN_10                     | 0.00    | 1       | root      |                                                                                                 | time:2.86ms, loops:2                                                                                                                                                                                                                 | test.ge1.created_at, offset:0, count:1                                                                  | 708 Bytes | N/A  |
|   └─IndexReader_17            | 0.00    | 3       | root      |                                                                                                 | time:2.82ms, loops:3, cop_task: {num: 4, max: 929.3µs, min: 536µs, avg: 670.4µs, p95: 929.3µs, max_proc_keys: 1, p95_proc_keys: 1, rpc_num: 4, rpc_time: 2.62ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 1}                 | index:Limit_16                                                                                          | 747 Bytes | N/A  |
|     └─Limit_16                | 0.00    | 3       | cop[tikv] |                                                                                                 | tikv_task:{proc max:0s, min:0s, avg: 0s, p80:0s, p95:0s, iters:4, tasks:4}, scan_detail: {total_process_keys: 3, total_process_keys_size: 459, total_keys: 7, get_snapshot_time: 118µs, rocksdb: {key_skipped_count: 3, block: {}}}  | offset:0, count:1                                                                                       | N/A       | N/A  |
|       └─IndexRangeScan_15     | 0.00    | 3       | cop[tikv] | table:ge1, partition:watch_event, index:repo_id(repo_id, type, action, created_at, actor_login) | tikv_task:{proc max:0s, min:0s, avg: 0s, p80:0s, p95:0s, iters:4, tasks:4}                                                                                                                                                           | range:[41986369 "WatchEvent" "started",41986369 "WatchEvent" "started"], keep order:false, stats:pseudo | N/A       | N/A  |
+-------------------------------+---------+---------+-----------+-------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------+-----------+------+

after

MySQL [test]> trace SELECT actor_login FROM ge1 WHERE type = 'WatchEvent' AND action = 'started' AND repo_id = 41986369 ORDER BY created_at limit 1;

+-------------------------------------------------------------------+-----------------+------------+
| operation                                                         | startTS         | duration   |
+-------------------------------------------------------------------+-----------------+------------+
| trace                                                             | 01:57:53.839381 | 1.999229ms |
|   ├─session.ExecuteStmt                                           | 01:57:53.839391 | 915.645µs  |
|   │ ├─executor.Compile                                            | 01:57:53.839412 | 551.257µs  |
|   │ └─session.runStmt                                             | 01:57:53.839999 | 271.472µs  |
|   │   └─distsql.Select                                            | 01:57:53.840137 | 38.047µs   |
|   │     └─regionRequest.SendReqCtx                                | 01:57:53.840288 | 906.74µs   |
|   │       └─rpcClient.SendRequest, region ID: 15, type: Cop       | 01:57:53.840321 | 857.697µs  |
|   │         └─tikv.RPC                                            | 01:57:53.840323 | 432.854µs  |
|   │           └─tikv.Wait                                         | 01:57:53.840323 | 170.02µs   |
|   │             └─tikv.GetSnapshot                                | 01:57:53.840323 | 170.02µs   |
|   ├─*executor.ProjectionExec.Next                                 | 01:57:53.840316 | 1.008551ms |
|   │ └─*executor.TopNExec.Next                                     | 01:57:53.840318 | 999.017µs  |
|   │   ├─*executor.IndexReaderExecutor.Next                        | 01:57:53.840328 | 920.367µs  |
|   │   └─*executor.IndexReaderExecutor.Next                        | 01:57:53.841277 | 30.717µs   |
|   └─*executor.ProjectionExec.Next                                 | 01:57:53.841333 | 10.162µs   |
|     └─*executor.TopNExec.Next                                     | 01:57:53.841335 | 831ns      |
+-------------------------------------------------------------------+-----------------+------------+

MySQL [test]> explain analyze  SELECT actor_login FROM ge1 WHERE type = 'WatchEvent' AND action = 'started' AND repo_id = 41986369 ORDER BY created_at limit 1;
+-------------------------------+---------+---------+-----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------+-----------+------+
| id                            | estRows | actRows | task      | access object                                                                                   | execution info                                                                                                                                                                           | operator info                                                                                           | memory    | disk |
+-------------------------------+---------+---------+-----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------+-----------+------+
| Projection_9                  | 0.00    | 1       | root      |                                                                                                 | time:955.7µs, loops:2, Concurrency:OFF                                                                                                                                                   | test.ge1.actor_login                                                                                    | 2.61 KB   | N/A  |
| └─TopN_10                     | 0.00    | 1       | root      |                                                                                                 | time:950.8µs, loops:2                                                                                                                                                                    | test.ge1.created_at, offset:0, count:1                                                                  | 708 Bytes | N/A  |
|   └─IndexReader_17            | 0.00    | 1       | root      |                                                                                                 | time:932µs, loops:2, cop_task: {num: 1, max: 847.4µs, proc_keys: 1, rpc_num: 1, rpc_time: 790.3µs, copr_cache_hit_ratio: 0.00, distsql_concurrency: 1}                                   | index:Limit_16                                                                                          | 387 Bytes | N/A  |
|     └─Limit_16                | 0.00    | 1       | cop[tikv] |                                                                                                 | tikv_task:{time:0s, loops:1}, scan_detail: {total_process_keys: 1, total_process_keys_size: 153, total_keys: 2, get_snapshot_time: 118.3µs, rocksdb: {key_skipped_count: 1, block: {}}}  | offset:0, count:1                                                                                       | N/A       | N/A  |
|       └─IndexRangeScan_15     | 0.00    | 1       | cop[tikv] | table:ge1, partition:watch_event, index:repo_id(repo_id, type, action, created_at, actor_login) | tikv_task:{time:0s, loops:1}                                                                                                                                                             | range:[41986369 "WatchEvent" "started",41986369 "WatchEvent" "started"], keep order:false, stats:pseudo | N/A       | N/A  |
+-------------------------------+---------+---------+-----------+-------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------+-----------+------+

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

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.

Fix the issue of performance regression that occurs when TiDB using `paging`

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member Author

ti-chi-bot commented Feb 7, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • tiancaiamao

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 release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/cherry-pick-not-approved labels Feb 7, 2023
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bugfix This PR fixes a bug. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Feb 7, 2023
store/copr/coprocessor_test.go Outdated Show resolved Hide resolved
kv/kv.go Outdated Show resolved Hide resolved
@solotzg
Copy link
Contributor

solotzg commented Feb 7, 2023

/test build

@VelocityLight VelocityLight added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Feb 7, 2023
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 7, 2023
@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 Feb 7, 2023
@tiancaiamao
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member Author

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

Commit hash: e33dd4e

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 7, 2023
@ti-chi-bot
Copy link
Member Author

@ti-chi-bot: Your PR was out of date, I have automatically updated it for you.

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.

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.

@solotzg
Copy link
Contributor

solotzg commented Feb 7, 2023

/test unit-test

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Feb 7, 2023

/merge

@solotzg
Copy link
Contributor

solotzg commented Feb 7, 2023

/test unit-test

1 similar comment
@tiancaiamao
Copy link
Contributor

/test unit-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 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/bugfix This PR fixes a bug. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants