For a table with 600000 data, how to optimize the use of WHERE + ORDER BY SQL?

Boss, the following sentence SQL, the execution time has reached 6s, what should I do?

in the end, I chose the scheme of "create a separate index" with the least impact.
not sure this is the best result! just because of my environment, comprehensive testing is more difficult, so I chose the "fastest, least impact" approach.
thanks again to @ Yujiaao and @ chenbinhua for their help.

Business scenario

sort by code > click_count , and get the first 20 results with c_id as 17 + choice as 1 .

SQL original sentence

SELECT `id` 
FROM `akb48` 
WHERE `c_id` = 17 AND `choice` = 1 ORDER BY `click_count` DESC LIMIT 20 OFFSET 600;

SQL analysis

"1"SIMPLE"akb48" N "index"IDX_C_ID,IDX_C_ID_POINT"IDX_CLICK_COUNT"4" N "10281"0.61"Using where"

select_type: SIMPLE;
type: index;
key: IDX_CLICK_COUNT
key_len: 4
rows: 10281;
filtered: 0.61%;

add:
table data 600,000 items , visual observation is because ORDER BY takes the lead in execution? Causes other indexes to be unavailable.

Jun.09,2022

do you need to jointly index the c_id, choice, and click_count fields


'choice' field?


wouldn't it be better to filter out a collection first, and then sort the from subquery?
I do not have an index here, and similar queries will not exceed 1 second

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e39e25-44562.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e39e25-44562.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?