c# - mysql query optimization?
怪我咯
怪我咯 2017-05-18 10:51:56
0
5
722

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

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
phpcn_u1582

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template