您现在的位置是:网站首页> 编程资料编程资料
SQL Server 使用join all优化 or 查询速度_MsSql_
2023-05-26
486人已围观
简介 SQL Server 使用join all优化 or 查询速度_MsSql_
比如:,master,test, 表示 该用户为 test 的下级代码,test登录后可以看到 test名下的业务和所有下级代理的业务。相关表的结构如下:
user表 大约10万条记录 |-uid-|-user-|----site------| | 1 | test | ,master, | | 2 | user | ,master,test,| product表 大约30万条记录 |-pid-|-product-|-puser-| | 1 | order01 | test | | 2 | order02 | user | | 3 | order03 | user |
优化前的SQL语句如下:
select * from product as p left join user as u on p.puser=u.user where user='test' or site like '%,test,%'
不使用 or 单独查询时,都不超过100毫秒,排除索引的问题。既然单个没问题,两种结果不存在重复记录,可以考虑 join all 优化。
优化后的语句如下:
select * from product where pid in ( select pid from product where user='test' join all ( select pid from product as p left join user as u on p.puser=u.user where site like '%,test,%' ) )
用户A名下共有4000+个业务,优化前 优化前11359毫秒,优化后621毫秒
用户B名下共有12个业务,优化前 优化前10359毫秒,优化后78毫秒
到此这篇关于SQL Server 使用join all优化 or 查询速度的文章就介绍到这了,更多相关SQL Server join all优化内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- SQL删除语句DROP、TRUNCATE、 DELETE 的区别_MsSql_
- 详解partition by和group by对比_MsSql_
- 分区表场景下的 SQL 优化_MsSql_
- SQL Server异常代码处理的深入讲解_MsSql_
- SQL Server中的集合运算: UNION, EXCEPT和INTERSECT示例代码详解_MsSql_
- 图书管理系统的sqlserver数据库设计示例_MsSql_
- sql server 交集,差集的用法详解_MsSql_
- SQL Server中row_number分页查询的用法详解_MsSql_
- 秒懂drop、truncate和delete的区别_MsSql_
- 详解SQL 通配符_MsSql_
