当前位置:网站首页>MySQL uses or to query SQL, and SQL execution is very slow
MySQL uses or to query SQL, and SQL execution is very slow
2022-04-23 04:59:00 【GreatorMan】
When the company makes a one-stop service hall , The interface returns slowly due to data reasons . An interface returns to 90S;
According to the interface analysis , Found the program executing SQL I found some more data executing SQL Time is slow , One SQL It takes time to run 30S about .
SELECT DISTINCT
t.id AS appId,
t.priority
FROM
yzs_unified_app t
LEFT JOIN yzs_unified_app_theme t1 ON t.id = t1.app_id
LEFT JOIN yzs_app_unified_role t2 ON t.id = t2.app_id
LEFT JOIN yzs_user_unified_role t3 ON t2.role_id = t3.role_id
LEFT JOIN yzs_app_unified_dept_post t4 ON t.id = t4.app_id
LEFT JOIN yzs_user_unified_dept_post t5 ON t4.dept_post_id = t5.dept_post_id
WHERE
(
t3.user_id = '1185405911867326464' or t5.dept_post_id = -2
)
and t1.theme_id = 5
t3 The table data has 1W Number of multiple , T5 Yes 100 Multiple data ;
When SQL
t5.dept_post_id = -2 or t3.user_id = '1185405911867326464'
After replacing the above conditions, I found that soon
Our analysis found that T3 The filtered data exists in the table at Don't appear very slowly , Each piece of data needs to be traversed 1W Number of pieces ;
solve the problem :
stay On Filter data conditionally ,
SELECT DISTINCT
t.id AS appId,
t.priority
FROM
yzs_unified_app t
LEFT JOIN yzs_unified_app_theme t1 ON t.id = t1.app_id
LEFT JOIN yzs_app_unified_role t2 ON t.id = t2.app_id
LEFT JOIN yzs_user_unified_role t3 ON t2.role_id = t3.role_id and t3.user_id = '1185405911867326464'
LEFT JOIN yzs_app_unified_dept_post t4 ON t.id = t4.app_id
LEFT JOIN yzs_user_unified_dept_post t5 ON t4.dept_post_id = t5.dept_post_id and t5.dept_post_id = -2
WHERE
t1.theme_id = 5
Or subquery :
.............................
版权声明
本文为[GreatorMan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220553102358.html
边栏推荐
- Com alibaba. Common methods of fastjson
- Record the ThreadPoolExecutor main thread waiting for sub threads
- How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
- How to exit VIM
- Pixel mobile phone brick rescue tutorial
- Manually write smart pointer shared_ PTR function
- Graduation project
- Innovation training (V) configuration information
- AQS源码阅读
- selenium模式下切换窗口,抓取数据的实现
猜你喜欢
JS engine loop mechanism: synchronous, asynchronous, event loop
What are the redis data types
Unity rawimage background seamlessly connected mobile
Learning Android II from scratch - activity
Learning Android from scratch -- Introduction
Deep learning notes - data expansion
Perfect test of coil in wireless charging system with LCR meter
The 8 diagrams let you see the execution sequence of async / await and promise step by step
Windows remote connection to redis
Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
随机推荐
DIY 一个 Excel 版的子网计算器
ApplicationContext injection bean
Manually write smart pointer shared_ PTR function
Innovation training (II) task division
Alibaba tip: it is better to create threads manually
【数据库】MySQL多表查询(一)
The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose
Details related to fingerprint payment
Detailed explanation of hregionserver
Arduino UNO r3+LCD1602+DHT11
redis数据类型有哪些
C. Tree Infection(模拟+贪心)
Painless upgrade of pixel series
使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
List remove an element
2022/4/22
What is a blocking queue? What is the implementation principle of blocking queue? How to use blocking queue to implement producer consumer model?
Innovation training (VI) routing
The unity camera rotates with the mouse
Com alibaba. Common methods of fastjson