此优化的前提可以称之为最近流行的头条人物“许三多”,总数据多,查询条件多,返回列多

优化前分页查询内部select列为需要的全部列,优化后内部select只返回ID主键,外部查询关联原数据表,然后查出所需要的列

例子1

优化前:

  1. select t.* from (
  2. select r.* ,row_number() over(order by r.id desc) row from tab(nolock) r
  3. where 1=1 and r.IsDelete=0 and r.Status>0 and r.PlatformID=1 and r.CreateUser=100000
  4. ) as t  where row between 1 and 10
select t.* from (
select r.* ,row_number() over(order by r.id desc) row from tab(nolock) r
where 1=1 and r.IsDelete=0 and r.Status>0 and r.PlatformID=1 and r.CreateUser=100000
) as t where row between 1 and 10

优化后:

  1. select r.* from (
  2. select r.ID ,row_number() over(order by r.id desc) row from tab(nolock) r
  3. where 1=1 and r.IsDelete=0 and r.Status>0 and r.PlatformID=1 and r.CreateUser=100000
  4. ) as t join tab r on r.id=t.id where row between 1 and 10
select r.* from (
select r.ID ,row_number() over(order by r.id desc) row from tab(nolock) r
where 1=1 and r.IsDelete=0 and r.Status>0 and r.PlatformID=1 and r.CreateUser=100000
) as t join tab r on r.id=t.id where row between 1 and 10

最近又有一个例子

例子2

优化前:tablA数据量1千多万,tablB数据量几百万,查询速度11秒多

  1. select * from (
  2. select d.LessonPlanID,d.ResUrl,p.createID,p.CreateTime,row_number() over(order by d.id desc) row
  3. from tablA(nolock) d
  4. join tablB(nolock) p on p.id=d.lessonplanid
  5. where p.createID in(109486,103295,103298,109347,130346,181382,330312)
  6. ) t where t.row between 1 and 20
select * from (
select d.LessonPlanID,d.ResUrl,p.createID,p.CreateTime,row_number() over(order by d.id desc) row
from tablA(nolock) d
join tablB(nolock) p on p.id=d.lessonplanid
where p.createID in(109486,103295,103298,109347,130346,181382,330312)
) t where t.row between 1 and 20

优化后:查询速度14毫秒

  1. select d.LessonPlanID,d.ResUrl,p.createID,p.CreateTime from (
  2. select  d.id,row_number() over(order by d.id desc) row
  3. from tablA(nolock) d
  4. join tablB(nolock) p on p.id=d.lessonplanid
  5. where p.createID in(109486,103295,103298,109347,130346,181382,330312)
  6. ) t join tablA(nolock) d on d.id=t.id   join tablB(nolock) p on p.id=d.lessonplanid
  7. where t.row between 1 and 20
select d.LessonPlanID,d.ResUrl,p.createID,p.CreateTime from (
select d.id,row_number() over(order by d.id desc) row
from tablA(nolock) d
join tablB(nolock) p on p.id=d.lessonplanid
where p.createID in(109486,103295,103298,109347,130346,181382,330312)
) t join tablA(nolock) d on d.id=t.id join tablB(nolock) p on p.id=d.lessonplanid
where t.row between 1 and 20

sql大数据多条件查询索引优化的更多相关文章

  1. 【1】MySQL大数据量分页查询方法及其优化

    ---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适应场景: 适用于数据量较少的情况(元组百/千 ...

  2. MySQL大数据量分页查询方法及其优化

    MySQL大数据量分页查询方法及其优化   ---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适 ...

  3. MySql数据表设计,索引优化,SQL优化,其他数据库

    MySql数据表设计,索引优化,SQL优化,其他数据库 1.数据表设计 1.1数据类型 1.2避免空值 1.3text类型优化 2.索引优化 2.1索引分类 2.2索引优化 3.SQL优化 3.1分批 ...

  4. mysql处理大数据量的查询速度究竟有多快和能优化到什么程度

    mysql处理大数据量的查询速度究竟有多快和能优化到什么程度 深圳-ftx(1433725026) 18:10:49  mysql有没有排名函数啊 横瓜(601069289) 18:13:06  无 ...

  5. MySQL大数据量分页查询

    mysql大数据量使用limit分页,随着页码的增大,查询效率越低下. 测试实验 1.   直接用limit start, count分页语句, 也是我程序中用的方法: select * from p ...

  6. J2EE综合:如何处理大数据量的查询

    在实际的任何一个系统中,查询都是必不可少的一个功能,而查询设计的好坏又影响到系统的响应时间和性能这两个要害指标,尤其是当数据量变得越来越大时,于是如何处理大数据量的查询成了每个系统架构设计时都必须面对 ...

  7. PL/SQL Developer 使用中文条件查询时无数据的解决方法

    PL/SQL Developer 使用中文条件查询时无数据,这是由于字符集的不一致导致的. 执行以下sql命令:select userenv('language') from dual; 显示:SIM ...

  8. PL/SQL Developer 使用中文条件查询时无数据的解决方法(转)

    原文地址: PL/SQL Developer 使用中文条件查询时无数据的解决方法 PL/SQL Developer 使用中文条件查询时无数据,这是由于字符集的不一致导致的. 执行以下sql命令:sel ...

  9. 【大数据之数据仓库】GreenPlum优化器对比测试

    在< [大数据之数据仓库]选型流水记>一文中有提及,当时没有测试GreenPlum的quicklz压缩算法和ORCA查询优化器,考虑到quicklz压缩算法因为版权问题不会开源(详情请参阅 ...

随机推荐

  1. Java中的异常Exception

    涉及到异常类相关的文章: (1)异常类不能是泛型的 http://www.cnblogs.com/extjs4/p/8888085.html (2)Finally block may not comp ...

  2. 配置Linux本地源镜像

    今天看到同事做了一个公司本地的apache镜像源,感觉好叼的样子.然后就自己上网找些资料,尝试自己搭建一套出来.然后就有了这篇博文... 声明:本文中充满了浓浓的技术嫉妒的心理,阅读需谨慎. 本文以 ...

  3. Hibernate 4.3 SessionFactory

    Configuration configuration = new Configuration().configure(); //以下这两句就是4.3的新用法 StandardServiceRegis ...

  4. 玩转树莓派《二》——用python实现动画与多媒体

    环境:树莓派,系统raspbian,系统自带两个版本的python以及pygame. 1.画板 程序如下: !/home/pi/game_1.py import pygame width = 640 ...

  5. JS中的 ES6新类型iterable

    1.1 iterable字面意思:可迭代的,可重复的 iterable是ES6标准引入的新的类型.而Array.Map和Set都属于iterable类型 1.2 为什么加入iterable类型? 遍历 ...

  6. WINFORM如何实现无聚焦框的Button按钮

    当我们将一个button按钮设置如下属性时,总有一个聚焦框来困扰着我们 button1.FlatStyle = FlatStyle.Flat; 我们想要的效果是这样的: 但当使用了Tab切换焦点时 发 ...

  7. Virtualbox/Vagrant安装

    它们分别是什么? VirtualBox: 号称是最强的免费虚拟机软件和VM类似. 不仅具有丰富的特色,而且性能也很优异. Vagrant: 是一个基于Ruby的工具,用于创建和部署虚拟化开发环境. 使 ...

  8. TabControl 选项卡控件

    TabControl 控件是由System.Windows.Forms.TabControl类提供的,作用就是讲相关的组件组合到一系列选项卡页面上.   MulitiLine 属性用来设置是否显示多行 ...

  9. Redis---1、介绍

    Redis简介: 是以key-value形式存储,和传统的关系型数据库不一样,不一定遵循传统数据库的一些基本要求. 优点: 对数据高并发读写 对海量数据的高效率存储和访问 对数据的可扩展性和高可用行 ...

  10. 从CentOS官网下载系统镜像详细教程

      很多新手小白鼠想学习CentOS系统,但是不知道镜像去哪里搞,随便去个第三方发现要么要注册,要么各种广告病毒,或者好不容易找到官网,点进去一看却一脸懵逼,不仅全英文,有些专业术语也不懂啊,不要担心 ...