网络编程
位置:首页>> 网络编程>> 数据库>> Mysql索引性能优化问题解决方案

Mysql索引性能优化问题解决方案

作者:手撕高达的村长  发布时间:2024-01-27 12:14:41 

标签:Mysql,索引,性能,优化

mysql 创建的优化就是加索引,可是有时候会遇到加索引都没法达到想要的效果的情况,

Mysql索引性能优化问题解决方案

加上了所以,却还是搜索的全数据,原因是sql


EXPLAIN  SELECT
     cs.sid,
     -- c.courseFrontTitle,
     -- c.imgBig,
     cs.studyStatus,
     coi.fee,
     -- act.PROC_INST_ID_ AS processId,
     cs.createDTM,
     cs.payStatus,
     cs.isCompleted,
     cs.saleChannel,
cs.isDelete
   FROM
     Biz_CourseStudy cs

LEFT JOIN Biz_CourseOrderItem coi ON   cs.sid = coi.CourseStudyID

WHERE
     cs.studentID = 00001 and cs.payStatus not in(0)

通过看索引,原因是因为sid为bigint , CourseStudyID 的类型确实varchar,原因就是在这里,修改类型为bigint后,查询速度瞬间提升.

遇到过这样一种情况,分析extra,去掉order by 0.6s速度OK,加上order by 6s

Mysql索引性能优化问题解决方案

解决方法,给order by 创建索引,这里我的order by是两个字段

order by endTime desc ,isDelete desc

为a b 创建联合索引, index_a_b

SELECT xxx FROM manage a FORCE INDEX(index_a_b)
LEFT JOIN f_name f ON f.user_id = a.user_id
ORDER BY a.endTime desc,a.isDelete desc

此时看性能,Using filesort已经消失

Mysql索引性能优化问题解决方案

速度直接变成0.6s

来源:https://www.cnblogs.com/sunxun/p/12463679.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com