sql Server 查询优化
2016-03-30 18:46
393 查看
t_FSHH_PartitionInfo表大概有10多万条数据,RdRecords大概3万条数据,刚开始使用如下语句执行时,大概耗时2分钟
Select p.* From t_FSHH_PartitionInfo p Where p.cLineID=2 and p.dQCVoucherDate Between '2016-03-01 00:00:00' And '2016-03-31 23:59:59' And ( isnull(p.bReturn,'否')='是' or exists( Select d.cdefine28 As cBarcode From RdRecords d Where p.cBarcode=d.cdefine28 group By d.cdefine28 ) )
2分钟肯定是不能接受的,于是开始优化,最张将子查询的实现方式改为union all的查询方式,语句如下:
select p.* from t_FSHH_PartitionInfo p Where p.cLineID=2 and p.dQCVoucherDate Between '2016-03-01 00:00:00' And '2016-03-31 23:59:59' And isnull(p.bReturn,'否')='是' Union All Select p.* From t_FSHH_PartitionInfo p Where p.cLineID=2 and isnull(p.bReturn,'否')!='是' And exists( Select d.cdefine28 As cBarcode From RdRecords d Where p.cBarcode=d.cdefine28 --and r.dDate Between '2016-03-28 00:00:00' And '2016-03-28 23:59:59' group By d.cdefine28 )
最后耗时变为10秒左右,这个速度仍然不够理想,不过已经比之前好多了。
相关文章推荐
- MySQL Got a packet bigger than 'max_allowed_packet' bytes错误配置
- sqlite manager serial number
- memcache 服务器状态信息
- 初次安装Mysql5.7以上版本后初始root密码找不到的问题
- mongodb增删改查
- 源码编译安装 MySQL 5.5.x 实践
- spring-data-redis用配置类连接时,抛异常Cannot get Jedis connection; nested exception is java.lang.NullPointerEx
- oracle 存储过程中调用存储过程
- SQL Server使用文件组备份降低备份文件占用的存储空间
- xampp下mariaDB数据库设置默认字符集utf8(Windows)
- sqlserver多表连接更新
- 基于redis排行榜的实战总结
- 提升项目性能的几个简单方法
- window下使用直接复制数据库文件方式复制数据库和表的方法
- MySQL性能分析脚本
- centos 上安装 mongodb3.2
- redis实战课题
- sqlserver跨实例查询方法
- 如何将Windows故障转移集群日志插入到SQLServer的表中
- 数据库索引碎片的自动重建或重组