简体   繁体   中英

Mysql: How to optimize this query. for faster results

How to optimize this query, for faster result it tooks 80+ Seconds on 10 million rows.

su_id AND admin_id both are BTREE Indexed

SELECT su_id FROM members_ext WHERE admin_id = 5962789

both are INT Data Types, with BTREE index

cardinality of su_id is 8496470 and admin_id is 10437

Explain result

id  ,select_type,table  ,type,rows, Extra   
1, SIMPLE ,members_ext , ALL ,8496471 ,Using where

在admin_id、su_id上做一个组合键,这样数据就只能通过索引获取了。

Don't store numbers in varchars and then compare to numbers. It won't work efficiently.

Add the quotes here:

SELECT su_id FROM members_ext WHERE admin_id = "5962789"

Then, for faster query, have INDEX(admin_id, su_id)

If anything in this answer is wrong, please provide SHOW CREATE TABLE members_ext . There is something important missing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM