sql大数据多条件查询索引优化
此优化的前提可以称之为最近流行的头条人物“许三多”,总数据多,查询条件多,返回列多
优化前分页查询内部select列为需要的全部列,优化后内部select只返回ID主键,外部查询关联原数据表,然后查出所需要的列
例子1
优化前:
- 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
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
优化后:
- 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
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秒多
- 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
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毫秒
- 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
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】MySQL大数据量分页查询方法及其优化
---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适应场景: 适用于数据量较少的情况(元组百/千 ...
- MySQL大数据量分页查询方法及其优化
MySQL大数据量分页查询方法及其优化 ---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适 ...
- MySql数据表设计,索引优化,SQL优化,其他数据库
MySql数据表设计,索引优化,SQL优化,其他数据库 1.数据表设计 1.1数据类型 1.2避免空值 1.3text类型优化 2.索引优化 2.1索引分类 2.2索引优化 3.SQL优化 3.1分批 ...
- mysql处理大数据量的查询速度究竟有多快和能优化到什么程度
mysql处理大数据量的查询速度究竟有多快和能优化到什么程度 深圳-ftx(1433725026) 18:10:49 mysql有没有排名函数啊 横瓜(601069289) 18:13:06 无 ...
- MySQL大数据量分页查询
mysql大数据量使用limit分页,随着页码的增大,查询效率越低下. 测试实验 1. 直接用limit start, count分页语句, 也是我程序中用的方法: select * from p ...
- J2EE综合:如何处理大数据量的查询
在实际的任何一个系统中,查询都是必不可少的一个功能,而查询设计的好坏又影响到系统的响应时间和性能这两个要害指标,尤其是当数据量变得越来越大时,于是如何处理大数据量的查询成了每个系统架构设计时都必须面对 ...
- PL/SQL Developer 使用中文条件查询时无数据的解决方法
PL/SQL Developer 使用中文条件查询时无数据,这是由于字符集的不一致导致的. 执行以下sql命令:select userenv('language') from dual; 显示:SIM ...
- PL/SQL Developer 使用中文条件查询时无数据的解决方法(转)
原文地址: PL/SQL Developer 使用中文条件查询时无数据的解决方法 PL/SQL Developer 使用中文条件查询时无数据,这是由于字符集的不一致导致的. 执行以下sql命令:sel ...
- 【大数据之数据仓库】GreenPlum优化器对比测试
在< [大数据之数据仓库]选型流水记>一文中有提及,当时没有测试GreenPlum的quicklz压缩算法和ORCA查询优化器,考虑到quicklz压缩算法因为版权问题不会开源(详情请参阅 ...
随机推荐
- Python对象引用和del删除引用
1.首先介绍下python的对象引用 1)Python中不存在传值调用,一切传递的都是对象引用,也可以认为是传址调用.即Python不允许程序员选择采用传值或传引用.Python参数传递采用的是“传对 ...
- shiro学习笔记_0300_jdbcRealm和认证策略
使用shiro框架来完成认证工作,默认是iniRealm,如果需要使用其他的realm,需要配置. ini配置文件详解,官方文档的说明如下: [main] section 是你配置应用程序的 Secu ...
- Installing Vim 8.0 on Ubuntu 16.04 and Linux Mint 18
sudo add-apt-repository ppa:jonathonf/vim sudo apt update sudo apt install vim uninstall sudo apt re ...
- Http的Get和Post--扫盲篇
Http Get请求,根据Http规范Get用于服务器信息的获取,而且安全及幂等的.其中安全的在此处的含义是:不会对服务器数据造成修改.增加.以及数据状态的改变. Http Post请求,表示可能修改 ...
- InnoDB的启动,关闭,恢复
InnoDB存储引擎是MySQL的存储引擎之一,因此InnoDB存储引擎的启动和关闭更准确地是指在MySQL实例的启动过程中对InnoDB表存储引擎的处理过程. 参数innodb_fast_shutd ...
- 理解Python语言里的异常(Exception)
Exception is as a sort of structured "super go to".异常是一种结构化的"超级goto". 作为一个数十年如一日 ...
- C#调用SQLite报错:无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块
C#调用SQLite数据库,有些情况下会报以下这个错误: 无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块 实际上程序目录中是存在SQLite.Interop.dll这个文 ...
- Django models 的增删改查
增 from app01.models import * #create方式一: Author.objects.create(name='Alvin') #create方式二: Author.obje ...
- 数据库索引--------B/B+树、聚集、非聚集、符合索引
摘录自博客:http://www.cnblogs.com/morvenhuang/archive/2009/03/30/1425534.html 一.引言 对数据库索引的关注从未淡出我的们的讨论,那么 ...
- nodejs学习笔记四(模块化、在npm上发布自己的模块)
模块化: 1.系统模块: http.querystring.url 2.自定义模块 3.包管理器 [系统模块] Assert 断言:肯定确定会出现的情 ...