sql not in 优化问题
问题情境:
not in 耗时过长。想用join或exits代替。结果并不明显,这里先记录3种写法,以后探讨速度问题。
sql语句:
// not exists
sql = @"select c.customerid, c.customername, c.sex, c.birthday, c.CustomerNumber, s.CreateTime, d.description, s.seriesID
from customerinfo c, seriestable s, sitecode d
where s.customerid = c.customerid
and s.createsite = d.siteid
and not exists
(select 1 from customer_healthinfo h where h.customerid = c.customerid)
order by s.CreateTime";
//not in
sql = @"select c.customername, c.sex, c.birthday, c.CustomerNumber, s.CreateTime, d.description, s.seriesID
from customerinfo c, seriestable s, sitecode d
where s.customerid = c.customerid
and s.createsite = d.siteid
and c.customerid not in
(select customerid from customer_healthinfo) order by s.CreateTime";
//left join
sql = @"select customername, sex, birthday, CustomerNumber, tempA.CreateTime, tempA.description, tempA.seriesID
from
(select c.customerid, c.customername, c.sex, c.birthday, c.CustomerNumber, s.CreateTime, d.description, s.seriesID
from customerinfo c, seriestable s, sitecode d
where s.customerid = c.customerid
and s.createsite = d.siteid) as tempA left join customer_healthinfo h
on tempA.customerid = h.customerid
where h.customerid is null
order by CreateTime";
sql not in 优化问题的更多相关文章
- SQL SERVER全面优化-------Expert for SQL Server 诊断系列
现在很多用户被数据库的慢的问题所困扰,又苦于花钱请一个专业的DBA成本太高.软件维护人员对数据库的了解又不是那么深入,所以导致问题迟迟不能解决,或只能暂时解决不能得到根治.开发人员解决数据问题基本又是 ...
- 谈谈SQL 语句的优化技术
https://blogs.msdn.microsoft.com/apgcdsd/2011/01/10/sql-1/ 一.引言 一个凸现在很多开发者或数据库管理员面前的问题是数据库系统的性能问题.性能 ...
- SQL SERVER全面优化-------写出好语句是习惯
前几篇文章已经从整体提供了诊断数据库的各个方面问题的基本思路...也许对你很有用,也许你觉得离自己太远.那么今天我们从语句的一些优化写法及一些简单优化方法做一个介绍.这对于很多开发人员来说还是很有用的 ...
- SQL SERVER全面优化-------索引有多重要?
想了好久索引的重要性应该怎么写?讲原理结构?我估计大部分人不愿意看,也不愿意花那么多时间仔细研究.光写应用?感觉不明白原理一样不会用.举例说明?情况太多也写不全....到底该怎么写呢? 随便写吧,想到 ...
- SQL SERVER全面优化
今天我们从语句的一些优化写法及一些简单优化方法做一个介绍.这对于很多开发人员来说还是很有用的!为了方便阅读给出前文链接: SQL SERVER全面优化-------Expert for SQL Ser ...
- SQL Server 性能优化(一)——简介
原文:SQL Server 性能优化(一)--简介 一.性能优化的理由: 听起来有点多余,但是还是详细说一下: 1.节省成本:这里的成本不一定是钱,但是基本上可以变相认为是节省钱.性能上去了,本来要投 ...
- oracle中sql语句的优化
oracle中sql语句的优化 一.执行顺序及优化细则 1.表名顺序优化 (1) 基础表放下面,当两表进行关联时数据量少的表的表名放右边表或视图: Student_info (30000条数据)D ...
- SQL Server 性能优化之——系统化方法提高性能
SQL Server 性能优化之——系统化方法提高性能 阅读导航 1. 概述 2. 规范逻辑数据库设计 3. 使用高效索引设计 4. 使用高效的查询设计 5. 使用技术分析低性能 6. 总结 1. 概 ...
- SQL 查询优化 索引优化
sql语句优化 性能不理想的系统中除了一部分是因为应用程序的负载确实超过了服务器的实际处理能力外,更多的是因为系统存在大量的SQL语句需要优化. 为了获得稳定的执行性能,SQL语句越简单越好.对复杂的 ...
- 深入研究Spark SQL的Catalyst优化器(原创翻译)
Spark SQL是Spark最新和技术最为复杂的组件之一.它支持SQL查询和新的DataFrame API.Spark SQL的核心是Catalyst优化器,它以一种新颖的方式利用高级编程语言特性( ...
随机推荐
- [python][easygui]使用enterbox()方法,简体字会显示成繁体字了
- 10行代码爬取全国所有A股/港股/新三板上市公司信息
摘要: 我们平常在浏览网页中会遇到一些表格型的数据信息,除了表格本身体现的内容以外,可能还想透过表格背后再挖掘些有意思或者有价值的信息.这时,可用python爬虫来实现.本文采用pandas库中的re ...
- POJ 1066 昂贵的聘礼
Description 年轻的探险家来到了一个印第安部落里. 在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长减 ...
- javascript实现百度地图鼠标滑动事件显示、隐藏
其实现思路是给label设置样式,我们来看下具体做法吧 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 var label = new BMap.Labe ...
- PHPer是草根吗
以下文字并没有非常多的技术词汇,所以只要对PHP感兴趣的人都可以看看. PHPer是草根吗? 从PHP诞生之日起,PHP就开始在Web应用方面为广大的程序员服务.同时,作为针对Web开发量身定制的脚本 ...
- leetcode 200. Number of Islands 、694 Number of Distinct Islands 、695. Max Area of Island 、130. Surrounded Regions
两种方式处理已经访问过的节点:一种是用visited存储已经访问过的1:另一种是通过改变原始数值的值,比如将1改成-1,这样小于等于0的都会停止. Number of Islands 用了第一种方式, ...
- centos7上svn安装
svn安装 yum install subversion 查看svn安装的版本 svnserve --version新建svn目录 mkdir /opt/svn 建立版本库目录 mkdir ...
- Android分享到微信和朋友圈的工具类
1.只要填写上正确的app_id,且引用上该工具类你就能实现分享到朋友圈和分享到微信. 2.需要到微信平台下载jar包,以及注册一个appid import android.content.Conte ...
- haproxy [WARNING] 312/111530 (17395) : config : 'option forwardfor' ignored for frontend 'harbor_login' as it requires HTTP mode.
1.经过调查, 2down voteaccepted x-forwarded-for is an HTTP header field, so has nothing to do with the tr ...
- 【LeeCode23】Merge k Sorted Lists★★★
1.题目描述: 2.解题思路: 题意:将K个已经排序的链表合并成一个排序的链表,分析并描述所用算法的复杂度. 方法一:基于“二分”思想的归并排序.本文用非递归和递归两种方法实现. (1)非递归:归并排 ...