当前位置:网站首页>MYSQL 使用OR查询SQL执行很慢
MYSQL 使用OR查询SQL执行很慢
2022-04-22 05:54:00 【GreatorMan】
在公司做一站式服务大厅时, 因为数据原因导致接口返回很慢。一个接口返回要90S;
根据接口分析,发现程序在执行SQL时发现又一些数据在执行SQL时很慢,一条SQL运行需要花30S左右。
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表数据有1W多条数 , T5有100多条数据;
当SQL
t5.dept_post_id = -2 or t3.user_id = '1185405911867326464'
替换上面条件后发现很快
我们分析发现T3 过滤数据在表存在在时间 不出现很慢, 每一条数据要遍历1W条数;
解决问题:
在On条件上过滤数据,
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
或者子查询:
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
版权声明
本文为[GreatorMan]所创,转载请带上原文链接,感谢
https://blog.csdn.net/GreatorMan/article/details/103002967
边栏推荐
- OpenInfra Live | 九州云黄舒泉当选Track Chair并带来精彩主题分享
- 杭州轨交监管平台边缘云获奖 树立行业新标杆
- Great! Kyushu cloud edge computing management platform has been certified by the national authority
- MySQL basics 2
- 2021-07-07
- InnoDB storage engine of MySQL
- 数美科技荣登“北京民营企业科技创新百强榜单”
- The annual list of its intelligent service excellent enterprises was released, and Kyushu cloud won the "2021 top 10 of Xinchuang operation and maintenance"
- Pineapple V1 spot household mute model power consumption parameters
- 聚焦边缘计算创新与实践,九州云出席2021中国联通5G MEC研讨会
猜你喜欢

直击痛点,九州云5G专网助力一汽富晟智慧物流建设

Pineapple V1 spot household mute model power consumption parameters

InnoDB storage engine of MySQL

《通用数据保护条例》(GDPR)系列解读一:如何判断出海企业是否受GDPR管辖?

数美科技获得ISO/IEC 27701隐私信息管理体系国际认证

sort排序

Focusing on the innovation and practice of edge computing, Kyushu cloud attended the 2021 China Unicom 5g MEC seminar

Postgreshub中文资源网介绍

数美科技受邀参加信通院内容治理标签研讨会

九州云获颁“2021年度企业”荣誉奖
随机推荐
九州云获颁“2021年度企业”荣誉奖
Evaluation of the first Avalon 1246-85t chassis with large computing power and low power consumption
Kyushu cloud was selected into the list of 36 krypton enterprises with the most potential to land on the science and innovation board
InnoDB storage engine of MySQL
mysql知识点总结
Functions and differences between synchronized keyword and volatile keyword
The sixth anniversary of digital technology pays tribute to you behind it
Analysis and practice of open source at home and abroad
解决Windows2012 R2下安装PostgreSQL报错的问题
Kyushu cloud passes the authoritative evaluation of EC ready edge cloud
Kyushu cloud was selected into China's top 500 Xinchuang in 2021
Kyushu cloud won the honorary award of "enterprise of 2021"
Postgreshub中文资源网介绍
数美科技荣登“北京民营企业科技创新百强榜单”
Solutions for minors protection in the social industry of digital beauty technology: guarding the "social circle" of minors
The annual list of its intelligent service excellent enterprises was released, and Kyushu cloud won the "2021 top 10 of Xinchuang operation and maintenance"
es6模块化
数美科技获得ISO/IEC 27701隐私信息管理体系国际认证
Method of querying cumulative value in MySQL
PostgreSQL使用clickhousedb_fdw访问ClickHouse