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 SQL for handle ID query #9034

Closed
dawnbreaks opened this issue Jan 14, 2019 · 7 comments
Closed

Optimize SQL for handle ID query #9034

dawnbreaks opened this issue Jan 14, 2019 · 7 comments

Comments

@dawnbreaks
Copy link

Feature Request

CREATE TABLE `test`.`id_test` (
  `id` varchar(64) NOT NULL,
  `name` varchar(64) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

explain SELECT * from test.id_test where _tidb_rowid = 1;
explain SELECT * from test.id_test where _tidb_rowid >= 1 and _tidb_rowid < 100;

Query execution plan for the above SQL are not acceptable, TableScan is too slow and expensive. It 's expected that TIDB should use the handle ID(_tidb_rowid) to access the the raw table data directly!

Projection_4	5.60	root	test.id_test.id, test.id_test.name
└─TableReader_7	5.60	root	data:Selection_6
  └─Selection_6	5.60	cop	ge(test.id_test._tidb_rowid, 1), lt(test.id_test._tidb_rowid, 100)
    └─TableScan_5	7.00	cop	table:id_test, range:[-inf,+inf], keep order:false, stats:pseudo
@XuHuaiyu
Copy link
Contributor

Hi, @dawnbreaks
What's your tidb_version?
You can run sql select tidb_version() to get it.

@shenli
Copy link
Member

shenli commented Jan 14, 2019

@dawnbreaks There is no data in your table. So I think it is reasonable for the query plan.
Please try inserting some data into your table and explain the query again.

@dawnbreaks
Copy link
Author

@XuHuaiyu The version of TIDB is "Release Version: v2.1.2-1-g8ba8096".

@shenli We have a table which has more than 100 million rows, and the query execution is the same as above.

@XuHuaiyu
Copy link
Contributor

Hi, @dawnbreaks , we've fixed it in this PR.
#8047

But it may not be cherry-picked to version 2.1.

@dawnbreaks
Copy link
Author

Is there a plan to cherry-pick it to version 2.1?

@XuHuaiyu
Copy link
Contributor

PTAL @zz-jason @shenli

@zz-jason
Copy link
Member

@dawnbreaks already cherry picked to release-2.1, close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants