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
count(id) not count(*)
You are joining a table from the left. It is recommended to add an index to the UID
Why do we need inline tables for statistics? If we want to group, wouldn’t it be better to use group by UID?
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
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.