1,同事报告了一条非常复杂的sql,说很慢,叫我优化下。
很慢的sql,也很长有几百行吧,^_^,如下:
| select bm2.bis_must_id, bm2.qz_year_month, bm2.money, bm2.adjust_money, bm2.bis_cont_id, bm2.must_type, bm2.rent_last_pay_date, bc.BIS_STORE_IDS, bc.BIS_STORE_NOS, bc.BIS_SHOP_ID, bc.BIS_SHOP_NAME, bc.BIS_PROJECT_ID, bp.short_name, bp.project_name, bm2.billing_period_begin, bm2.billing_period_end from (selectsum(m.money) money, sum(aj.adjust_money) adjust_money, m.must_type must_type, m.qz_year_month qz_year_month, m.bis_project_id bis_project_id, m.bis_cont_id bis_cont_id, max(m.rent_last_pay_date) rent_last_pay_date, max(m.billing_period_begin) billing_period_begin, min(m.billing_period_end) billing_period_end, max(m.bis_must_id) bis_must_id from bis_must2 m, (select j.* from bis_mf_adjust j where (j.is_del = '1'or j.is_del </ |

面对同事报告的一条运行缓慢、长达几百行的SQL语句,通过F5分析发现bis_must2和bis_mf_adjust表存在表扫描问题。为bis_must2表添加索引后,查询成本降低,执行效率显著提升至0.1秒。优化应适可而止,避免过度索引影响DML性能。

2万+

被折叠的 条评论
为什么被折叠?



