我安装了MySQL Tuner,这是报告的结果:
所以,我启用了慢查询日志并报告了这类查询:
选择 u.PIN,u.name,u.lastname,u.id_country,t1.id_user_list,COUNT(t2.id_user_list) AS q1 FROM联系AS t1,联系AS t2,用户AS u WHERE t1.id_user = N AND t2.id_user = t1.id_user_list AND u.id_user = t1.id_user_list GROUP BY t1.id_user_list ORDER BY name,lastname
和...
SELECT * FROM user WHERE city LIKE'S' AND gender = N AND flg_pic = N AND flg_hidden = N AND flg_ban = N AND id_user!= N ORDER BY id_user DESC LIMIT N,N
我只是需要一些关于表格优化的帮助,这些是:
我应该索引查询中使用的所有varchars(WHERE和ORDER)吗?谢谢你的帮助。
答案 0 :(得分:1)
您应该运行explain analyze以更好地了解查询中最昂贵的部分,并围绕这些字段进行索引或优化。
例如:
explain analyze SELECT * FROM user WHERE city LIKE 'S' AND gender = N AND flg_pic = N AND flg_hidden = N AND flg_ban = N AND id_user != N ORDER BY id_user DESC LIMIT N,N
并且您应该优先考虑那些运行最频繁且速度最慢的慢查询