1. There are more than 1 million pieces of data. The count speed is extremely slow. Please let me know how to optimize it.
2. Code:
SELECT
COUNT(*)
FROM
`score`
INNER JOIN `users` ON (
`score`.`UID` = `users`.`UID`
)
WHERE
(`score`.`Score` >= 10)
AND (`score`.`Score` <= 81);
3, Index
user table
黄舟2017-05-18 10:53:56
You are joining a table from the left. It is recommended to add an index to the UID
世界只因有你2017-05-18 10:53:56
Why do we need inline tables for statistics? If we want to group, wouldn’t it be better to use group by UID?
ringa_lee2017-05-18 10:53:56
The statement is simple, the index is normal, and it should not be slow. You can post the execution plan through explain + statement.
In addition, the users table structure is also posted. If UID is the primary key of the users table, you can remove the connection of the table
为情所困2017-05-18 10:53:56
I don’t see the necessity of connecting tables. You only need to count the number of data in fractional segments. I don’t see that it has anything to do with the user table. Just count in a single table.