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

planner, executor: enable inline projection for Limit #20288

Merged
merged 20 commits into from
Oct 19, 2020

Conversation

pingyu
Copy link
Contributor

@pingyu pingyu commented Sep 28, 2020

What problem does this PR solve?

Issue Number: part of #14428

Problem Summary:
Implement inline projection for Limit, part of #14428.

What is changed and how it works?

What's Changed:
Enable inline projection for LIMIT.

How it Works:
markChildrenUsedCols is applied to Limit.

Benchmark:

$ go test  -v -benchmem -run=XX -bench="BenchmarkLimitExec" -count 1
goos: darwin
goarch: amd64
pkg: github.com/pingcap/tidb/executor
BenchmarkLimitExec/(rows:30000,_offset:10000,_count:10000,_inline_projection:false)-12         	   20329	     58699 ns/op	   24373 B/op	     100 allocs/op
BenchmarkLimitExec/(rows:30000,_offset:10000,_count:10000,_inline_projection:true)-12          	  255342	      5157 ns/op	    3216 B/op	      34 allocs/op
PASS
ok  	github.com/pingcap/tidb/executor	60.073s

About 10x faster for a simple select i from t where j=1 limit 10000,10000
(i & j are both LongLong fields)

Related changes

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

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)
mysql root@localhost:test1> explain select i from t1 where k=1;                                                                                                                                               
+-----------------------+----------+-----------+---------------+--------------------------------+
| id                    | estRows  | task      | access object | operator info                  |
+-----------------------+----------+-----------+---------------+--------------------------------+
| Projection_4          | 10.00    | root      |               | test1.t1.i                     |
| └─TableReader_7       | 10.00    | root      |               | data:Selection_6               |
|   └─Selection_6       | 10.00    | cop[tikv] |               | eq(test1.t1.k, 1)              |
|     └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t1      | keep order:false, stats:pseudo |
+-----------------------+----------+-----------+---------------+--------------------------------+
4 rows in set
Time: 0.014s
mysql root@localhost:test1> explain select i from t1 where k=1 limit 3;                                                                                                                                       
+--------------------------+---------+-----------+---------------+--------------------------------+
| id                       | estRows | task      | access object | operator info                  |
+--------------------------+---------+-----------+---------------+--------------------------------+
| Limit_8                  | 3.00    | root      |               | offset:0, count:3              |
| └─TableReader_14         | 3.00    | root      |               | data:Limit_13                  |
|   └─Limit_13             | 3.00    | cop[tikv] |               | offset:0, count:3              |
|     └─Selection_12       | 3.00    | cop[tikv] |               | eq(test1.t1.k, 1)              |
|       └─TableFullScan_11 | 3000.00 | cop[tikv] | table:t1      | keep order:false, stats:pseudo |
+--------------------------+---------+-----------+---------------+--------------------------------+
5 rows in set
Time: 0.014s
mysql root@localhost:test1>  

Side effects

  • Performance regression
    • Consumes more CPU
      No.
    • Consumes more MEM
      No.
  • Breaking backward compatibility
    No.

Release note

  • Support inline projection for Limit

@pingyu pingyu requested review from a team as code owners September 28, 2020 17:10
@pingyu pingyu requested review from SunRunAway and removed request for a team September 28, 2020 17:10
@ti-srebot ti-srebot added the contribution This PR is from a community contributor. label Sep 28, 2020
@pingyu
Copy link
Contributor Author

pingyu commented Sep 28, 2020

/run-all-tests

@github-actions github-actions bot added the sig/execution SIG execution label Sep 28, 2020
@pingyu
Copy link
Contributor Author

pingyu commented Sep 28, 2020

/run-all-tests

planner/core/logical_plans.go Outdated Show resolved Hide resolved
planner/core/physical_plans.go Outdated Show resolved Hide resolved
planner/core/rule_column_pruning.go Outdated Show resolved Hide resolved
planner/core/rule_column_pruning.go Outdated Show resolved Hide resolved
planner/core/logical_plans.go Outdated Show resolved Hide resolved
util/chunk/chunk.go Outdated Show resolved Hide resolved
@pingyu
Copy link
Contributor Author

pingyu commented Oct 11, 2020

/run-all-tests

@pingyu
Copy link
Contributor Author

pingyu commented Oct 11, 2020

/run-unit-test

@pingyu
Copy link
Contributor Author

pingyu commented Oct 11, 2020

All comments are addressed or replied, PTAL~ @SunRunAway

(Failure of unit-test was caused by infosync.GetAllServerInfo timeout in domain_test.go, and should not be relevant to this PR)

[2020-10-11T15:11:41.828Z] === RUN   TestInfo
...
[2020-10-11T15:11:41.829Z] [2020/10/11 23:10:16.965 +08:00] [WARN] [syncer.go:305] ["[ddl] etcd-cli delete key failed"] [key=/tidb/server/info/957e7044-c832-467c-827d-39ebacf3dc20] [error="context deadline exceeded"] [retryCnt=0]
[2020-10-11T15:11:41.829Z] [2020/10/11 23:10:18.409 +08:00] [INFO] [info.go:773] ["get key failed"] [key=/tidb/server/info] [error="context deadline exceeded"]
[2020-10-11T15:11:41.829Z] [2020/10/11 23:10:19.609 +08:00] [INFO] [info.go:773] ["get key failed"] [key=/tidb/server/info] [error="context deadline exceeded"]
[2020-10-11T15:11:41.829Z] [2020/10/11 23:10:20.810 +08:00] [INFO] [info.go:773] ["get key failed"] [key=/tidb/server/info] [error="context deadline exceeded"]
[2020-10-11T15:11:41.829Z] [2020/10/11 23:10:22.010 +08:00] [INFO] [info.go:773] ["get key failed"] [key=/tidb/server/info] [error="context deadline exceeded"]
[2020-10-11T15:11:41.829Z] [2020/10/11 23:10:23.211 +08:00] [INFO] [info.go:773] ["get key failed"] [key=/tidb/server/info] [error="context deadline exceeded"]
...
[2020-10-11T15:11:41.829Z] --- FAIL: TestInfo (13.08s)
[2020-10-11T15:11:41.829Z]     domain_test.go:220: err context deadline exceeded, infos map[]
[2020-10-11T15:11:41.829Z] FAIL
[2020-10-11T15:11:41.829Z] coverage: 83.3% of statements
[2020-10-11T15:11:41.829Z] FAIL	github.com/pingcap/tidb/domain	42.953s

@ti-srebot

This comment has been minimized.

@SunRunAway
Copy link
Contributor

/reward 750

@ti-challenge-bot
Copy link

This PR's linked issue is not picked.

@SunRunAway
Copy link
Contributor

/cc @XuHuaiyu

@SunRunAway
Copy link
Contributor

/reward 750

@ti-challenge-bot
Copy link

Reward success.

@SunRunAway
Copy link
Contributor

/cc @qw4990

@ti-srebot ti-srebot requested a review from qw4990 October 15, 2020 11:55
Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@qw4990
Copy link
Contributor

qw4990 commented Oct 15, 2020

/merge

@ti-srebot ti-srebot added status/can-merge Indicates a PR has been approved by a committer. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 15, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Oct 15, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@pingyu merge failed.

@pingyu
Copy link
Contributor Author

pingyu commented Oct 18, 2020

/run-all-tests

@XuHuaiyu
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 4501f6d into pingcap:master Oct 19, 2020
@ti-challenge-bot
Copy link

@pingyu, Congratulations, you get 750 in this PR, and your total score is 750 in high-performance challenge program.

More

Tip : None

Warning:
The pull request merged, pingyu got the score. But it seems linked issue not picked.

cc: Mentor @SunRunAway

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. sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants