The
index is not absolute, it depends on whether the index can reduce IO.
first of all, in your example, you can obviously use user_score_have_index_user_type_id_index to quickly locate the data of type=5, and the index is orderly, that is to say, you only need to locate the data of the first type=5, and you can read to the right along the pointer, which is much faster than the discrete reading of the whole table. In addition, for both id and type conditions, user_score_have_index_user_type_id_index already overrides the index. Brother, can the index name be shorter? )
it is often said that duplicate values are not suitable for indexing, taking into account the cost of returning to the table.
it's not that you don't need to add, it's that it's of little use. If you look at the specific scene and the scan of the table, and 1s and 6s themselves are not "significantly improved" or dozens of times, if it's not count, and get a few pieces of data, your index is useless. For such a large data, you can't get count, directly, you should store it in other places, and the database will fail after a few requests. You just happen to encounter the usefulness of count, but it doesn't work well in most cases
MySQL index principle and slow query optimization
talking about optimization without actual business is a hooligan.
if the above reply has already been mentioned, just add a
I ask you if a sentence is visited very frequently, but there are a lot of repetitions, do you add it?