开发者

mysql optimization / how to use index tip...?

开发者 https://www.devze.com 2023-02-11 10:10 出处:网络
if this is my USERS table user_id user_fname user_lname user_email user_pass user_verified user_city user_joined

if this is my USERS table

user_id 
user_fname  
user_lname  
user_email  
user_pass   
user_verified   
user_city   
user_joined 
us开发者_运维问答er_lastlogin  
user_about

i set user_id as PRIMARY (is an auto incremental value)

thaen, should i set user_email as INDEX? other suggestion?


You should add indexes to columns that are often used in query conditions, ordering, joining. There is no point in adding an index to a column that doesn't play any role in the query.

If you have thoughts about optimizing a query, at first, you should check it out in EXPLAIN query to see how complex the query is.


You should use indexes when your table is searched more frequently than it gets updated. If your table is searched using user_email very often, then you may use indexes on that column.

Remember, if user_email field gets updated more often than being used in a search condition, then it will ultimately lead to a performance overhead.

Go here for further insight.

0

精彩评论

暂无评论...
验证码 换一张
取 消