简单慢sql处理思路 #W05

解决问题的秘诀在于思路,这也是需要训练的最重要的能力之一。下面通过复盘一次慢sql解决的过程,争取提炼出某一维度的思路。

SELECT DISTINCT `customers`.* FROM customers as customers WHERE ((customers.user_id in (SELECT `users`.`id` FROM `users` WHERE `users`.`status` = 1 AND `users`.`locked_at` IS NULL AND ((users.path like '0/123456/%' 
or users.path = '0/123456')) AND `users`.`deleted_at` IS NULL) or customers.department_id in (1****2))) AND 
`customers`.`customer_common_setting_id` IS NULL ORDER BY customers.updated_at desc, `customers`.`id` DESC LIMIT 10 OFFSET 0

执行时长为8秒,相关的两张表数据量都有数百万。

先看整体

看到这条语句居然执行了8秒,实在觉得不可思议,一下子兴趣就更加浓厚。

解构骨架

拿到语句后,首先要做的事情是从整体上梳理出它的结构,然后再逐步进入细节,从整体到局部都有相对清晰的了解。下面来划分一下chunk:

select distinct + 子查询条件 + 其他与/或条件 + 排序 + 分页

可以看出整条语句还是相对简单,是一种很常规的结构。

思考可能的执行计划

清楚结构之后,应该在脑中思考一下可能的执行计划是什么,会用到哪些索引。

查看执行计划

接下来需要做的事情就是查看执行计划了,下面是在测试环境的执行计划:

*************************** 1. row ***************************
id: 1
select_type: PRIMARY
table: customers
partitions: NULL
type: ref
possible_keys: index_customers_on_department_id,index_customers_on_common_setting_id_flow_into_at
key: index_customers_on_co
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>音乐相册</title> <style> @import url("CSS/ring.css"); @import url("CSS/square.css"); /* 定义动画 */ @keyframes box-ani{ /* 开始动画 */ from{ transform: rotateX(-15deg) rotateY(10deg); } /* 结束动画 */ to{ transform: rotateX(-15deg) rotateY(370deg); } } /* 使用动画 */ .box{ animation-name: box-ani; animation-duration: 10s; animation-iteration-count: infinite; animation-timing-function: linear; } </style> </head> <body> <div class="btn-box"> <button class="btn">环形</button> <button class="btn-square">正方体</button> </div> <div class="box square"> <img src="img/w01.jpg" alt=""/> <img src="img/w02.jpg" alt=""/> <img src="img/w03.jpg" alt=""/> <img src="img/w04.jpg" alt=""/> <img src="img/w05.jpg" alt=""/> <img src="img/w06.jpg" alt=""/> <img src="img/w07.jpg" alt=""/> <img src="img/2014.jpg" alt=""/> <img src="img/2015.jpg" alt=""/> <img src="img/2016.jpg" alt=""/> <img src="img/2017.jpg" alt=""/> <img src="img/2018上.jpg" alt=""/> </div> </body> <script> var btn =document.querySelector(".btn"); var box =document.querySelector(".box"); var btnSquare=document.querySelector(".btn-square") btn.onclick =function(){ // 现在点击以后要在box的盒子上面添加一个class 为ring的样式 box.classList.remove("square"); box.classList.add("ring"); } btnSquare.onclick =function(){ box.classList.remove("ring"); box.classList.add("square"); } </script> </html>帮我写一个可以添加背景音乐的代码
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值