网上乱七八糟一堆分页测试汇总

  网上关于分页有大堆各种各样的,有人说这个这个处理大数据性能好,有人说那个性能好,听别人说没啥用,自己测试下才知道,但是我只测试除了第一个在查询分页后段的时候真的是不行,其他的在下面的测试中是没问题,也许是下面的例子并不能真实的测出,本来是实力有限,欢迎批评指出, 然后有集中分页方式,然后下面有几种分页方式在稍微复杂点的查询面前,你就会想死,所以就算性能再好写我也是不太喜欢用的  

  • 首先先创建两张简单测试表,student, class

create table student
(
    sno int ,
    cno int ,
    sname VARCHAR(200)
);
create table class
(
    cno int ,
    cname VARCHAR(200)
);
  • student 插入100万条数据,插入脚本来之 这里

--随机插入100万数据
DECLARE @LN VARCHAR(300),@MN VARCHAR(200),@FN VARCHAR(200)
DECLARE @LN_N INT,@MN_N INT,@FN_N INT
SET @LN=‘李王张刘陈杨黄赵周吴徐孙朱马胡郭林何高梁郑罗宋谢唐韩曹许邓萧冯曾程蔡彭潘袁于董余苏叶吕魏蒋田杜丁沈姜范江傅钟卢汪戴崔任陆廖姚方金邱夏谭韦贾邹石熊孟秦阎薛侯雷白龙段郝孔邵史毛常万顾赖武康贺严尹钱施牛洪龚‘
SET @MN=‘德绍宗邦裕傅家積善昌世贻维孝友继绪定呈祥大正启仕执必定仲元魁家生先泽远永盛在人为任伐风树秀文光谨潭棰‘
SET @FN=‘丽云峰磊亮宏红洪量良梁良粮靓七旗奇琪谋牟弭米密祢磊类蕾肋庆情清青兴幸星刑‘
SET @LN_N=LEN(@LN)
SET @MN_N=LEN(@MN)
SET @FN_N=LEN(@FN)
DECLARE @TMP VARCHAR(1000),@I INT,@CNO INT
SET @I=1
WHILE @I<1000000
BEGIN
    SET @CNO=floor(rand()*100000);
    SET @TMP=CAST(SUBSTRING(@LN,CAST(RAND()*@LN_N AS INT),1) AS VARCHAR)
    SET @TMP=@TMP+CAST(SUBSTRING(@MN,CAST(RAND()*@MN_N AS INT),1) AS VARCHAR)
    SET @TMP=@TMP+CAST(SUBSTRING(@FN,CAST(RAND()*@FN_N AS INT),1) AS VARCHAR)
    INSERT INTO student(sno, cno, sname)VALUES(@I, @I % 100000, @TMP)
    SET @I=@I+1
end
  • class插入10 万条数据

--向数据库中插入10万条随机姓名记录用于测试(sqlserver2005)
DECLARE @LN VARCHAR(300),@MN VARCHAR(200),@FN VARCHAR(200)
DECLARE @LN_N INT,@MN_N INT,@FN_N INT
SET @LN=‘李王张刘陈杨黄赵周吴徐孙朱马胡郭林何高梁郑罗宋谢唐韩曹许邓萧冯曾程蔡彭潘袁于董余苏叶吕魏蒋田杜丁沈姜范江傅钟卢汪戴崔任陆廖姚方金邱夏谭韦贾邹石熊孟秦阎薛侯雷白龙段郝孔邵史毛常万顾赖武康贺严尹钱施牛洪龚‘
SET @MN=‘一二三四五六七八九十abcdefghijklmnopqistuvwxyz1234567890‘
SET @FN=‘丽云峰磊亮宏红洪量良梁良粮靓七旗奇琪谋牟弭米密祢磊类蕾肋庆情清青兴幸星刑‘
SET @LN_N=LEN(@LN)
SET @MN_N=LEN(@MN)
SET @FN_N=LEN(@FN)
DECLARE @TMP VARCHAR(1000),@I INT
SET @I=100
WHILE @I<100000
BEGIN
    SET @TMP=CAST(SUBSTRING(@LN,CAST(RAND()*@LN_N AS INT),1) AS VARCHAR)
    SET @TMP=@TMP+CAST(SUBSTRING(@MN,CAST(RAND()*@MN_N AS INT),1) AS VARCHAR)
    SET @TMP=@TMP+CAST(SUBSTRING(@FN,CAST(RAND()*@FN_N AS INT),1) AS VARCHAR)
    INSERT INTO class(cno,cname)VALUES(@I,@TMP)
    SET @I=@I+1
end
  • 首先测试最简单的分页不带查询条件,不带表连接, 下面的都是查询第100页的查询语句

-- 取不在前n条的s条数据,n:10w 就挂了
-- s=PageSize,
-- n=PageSize * (PageIndex - 1) 第一页:0 第二页:10 第三页:20
SELECT TOP 10 * FROM student WHERE  sno NOT IN
    (SELECT TOP 990 sno FROM student  ORDER BY sno desc)
ORDER BY sno desc
--查询最后面的n条数据,取后面的s条,然后再数据再倒置数据
-- s=PageSize
-- n=PageSize * PageIndex 第一页:10 第二页:20 第三页:30
SELECT * FROM
    (SELECT TOP 10 * FROM
        (SELECT TOP 1000 * FROM student ORDER BY  sno DESC)
     f ORDER BY f.sno asc)
s ORDER BY s.sno DESC
-- 原理同上,只不过最后倒置不是直接Order by查询结果,而是自连接一次倒置,感觉应该更慢吧
SELECT * FROM student w1,
    ( SELECT TOP 10 sno FROM
        ( SELECT TOP 1000 sno FROM student ORDER BY sno DESC)
     w ORDER BY w.sno ASC )
w2 WHERE w1.sno = w2.sno  ORDER BY w1.sno DESC
-- 原理同上只不过表连接改成了 in 的语法
SELECT * FROM student w1 WHERE sno in
    (SELECT top 10 sno FROM (
        SELECT top 1000 sno FROM student ORDER BY  sno DESC)
     w ORDER BY w.sno ASC)
ORDER BY w1.sno DESC
-- 查询最后面的s条,row_number正序排序,然后取最后的n条
-- s=PageSize * PageIndex
-- n=PageSize * (PageIndex - 1)
SELECT w2.n, w1.* FROM student w1,
    (SELECT TOP 1000 row_number() OVER (ORDER BY  sno DESC) n, sno FROM student)
w2 WHERE w1.sno = w2.sno AND w2.n > 990 ORDER BY w2.sno desc
-- 这个方式看起来明显爽很多, 除了后面between and 计算起来比较麻烦一点
-- s=PageSize * (PageIndex - 1) + 1
-- n=PageSize * PageIndex
SELECT * FROM
    (SELECT ROW_NUMBER() Over(ORDER BY sno DESC) AS n, * FROM student)
AS t WHERE n between 991 and 1000
  • 然后测试带查询条件

-- 查询很麻烦得两个地方都要查
SELECT TOP 10 * FROM student WHERE sname like ‘%元%‘ and sno NOT IN
    (SELECT TOP 990 sno FROM student where sname like ‘%元%‘  ORDER BY sno desc)
ORDER BY sno desc
-- 查询在最内层做就好了
SELECT * FROM
    (SELECT TOP 10 * FROM
        (SELECT TOP 1000 * FROM student where sname like ‘%元%‘ ORDER BY  sno DESC)
     f ORDER BY f.sno asc)
s ORDER BY s.sno DESC
-- 原理同上
SELECT * FROM student w1,
    ( SELECT TOP 10 sno FROM
        (SELECT TOP 1000 sno FROM student where sname like ‘%元%‘ ORDER BY sno DESC)
      w ORDER BY  w.sno ASC)
w2 WHERE w1.sno = w2.sno  ORDER BY w1.sno DESC
-- 原理同上
SELECT * FROM student w1 WHERE sno in
    (SELECT top 10 sno FROM
        (SELECT top 1000 sno FROM student where sname like ‘%元%‘ ORDER BY  sno DESC)
     w ORDER BY w.sno ASC )
ORDER BY w1.sno DESC
-- 原理同上
SELECT w2.n, w1.* FROM student w1,
    (SELECT TOP 1000 row_number() OVER (ORDER BY  sno DESC) n, sno FROM student where sname like ‘%元%‘)
w2 WHERE w1.sno = w2.sno AND w2.n > 990 ORDER BY w2.sno desc
-- 这个做查询就爽多了
SELECT * FROM
    (SELECT ROW_NUMBER() Over(ORDER BY sno DESC) AS n, * FROM student where sname like ‘%元%‘)
AS t WHERE n between 991 and 1000
  • 然后测试class表跟student表连接,查询class表的cname 字段包含a的,并且吧cname 也要返回

-----------------------------------------------------------------------------------------------------
-- 感觉想死
SELECT TOP 10 * FROM student s inner join class c on s.cno = c.cno WHERE c.cname like ‘%a%‘ and sno NOT IN
    (SELECT TOP 990 sno FROM student s inner join class c on s.cno = c.cno where c.cname like ‘%a%‘ ORDER BY sno desc)
ORDER BY sno desc;
-- 注意下内存有两个cno 所以不要写 * 写 s.*, c.cname 就好了
SELECT * FROM
    (SELECT TOP 10 * FROM(
        SELECT TOP 1000 s.*, c.cname FROM student s inner join class c on s.cno = c.cno where c.cname like ‘%a%‘ ORDER BY  s.sno DESC)
f ORDER BY f.sno asc) s ORDER BY s.sno DESC;
-- 返回字段感觉麻烦的要死,想死
SELECT w1.sno, w2.cname, w2.sname, w1.cno FROM student w1,
    (SELECT TOP 10 w.cname, w.sname, sno FROM
        (SELECT TOP 1000 s.*, c.cname  FROM student s inner join class c on s.cno = c.cno where c.cname like ‘%a%‘ ORDER BY sno DESC)
    w ORDER BY  w.sno ASC )
w2 WHERE w1.sno = w2.sno  ORDER BY w1.sno DESC;
-- 压根没办法返回class的cname 字段了 因为in 的语法内层值有sno, 除非外面再套一层join, 想死
SELECT * FROM student w1 WHERE sno in
    (SELECT top 10 w.sno  FROM
        (SELECT top 1000 s.sno, s.sname, c.cname FROM student s inner join class c on s.cno = c.cno where c.cname like ‘%a%‘ ORDER BY  sno DESC )
     w ORDER BY w.sno ASC )
ORDER BY w1.sno DESC;
-- 感觉还好
SELECT w2.* FROM student w1,
    (SELECT TOP 1000 row_number() OVER (ORDER BY  s.sno DESC) n, s.*, c.cname FROM student s inner join class c on s.cno = c.cno where c.cname like ‘%a%‘)
w2 WHERE w1.sno = w2.sno AND w2.n > 990 ORDER BY w2.sno desc;
-- 这个做表连接页爽多了
SELECT * FROM
    (SELECT ROW_NUMBER() Over(ORDER BY sno DESC) AS n, s.*, c.cname FROM student s inner join class c on s.cno = c.cno where c.cname like ‘%a%‘)
AS t WHERE n between 991 and 1000;
时间: 2024-10-11 03:39:00

网上乱七八糟一堆分页测试汇总的相关文章

分页插件汇总

jpaginate是基于jquery的分页插件,非常轻量,没有任何侵入性,当然所能做的也就非常少.事实上它的作用仅仅是提供一个好看的分页样式,只提供一个触发事件.但是轻量带来了巨大的灵活性,让它可以提供任何内容的分页服务. 官方网站为http://tympanus.net/codrops/2009/11/17/jpaginate-a-fancy-jquery-pagination-plugin/,demo网站为http://tympanus.net/jPaginate/. 该项目好像到2009年

分页sql汇总

1.oracle数据库分页 select * from (select a.*,rownum rc from 表名 where rownum<=endrow) a where a.rc>=startrow 2.DB2数据库分页 Select * from (select rownumber() over() as rc,a.* from (select * from 表名 order by 列名) as a) where rc between startrow and endrow 3.SQL

迷你商城后台管理系统---------stage3项目部署测试汇总

系统测试 在项目部署到云服务器之前,已通过本机启动springboot程序,访问localhost:8080,输入登陆的账户等一系列操作测试:功能测试.健壮性测试,系统已满足用户规定的需求. 系统部署 ##项目打包 1. 在主机上打包项目到deploy: ``` cd litemall cat ./litemall-db/sql/litemall_schema.sql > ./deploy/db/litemall.sql cat ./litemall-db/sql/litemall_table.

测试感想

做了这么久的软件测试工作,一直没写过博客之类的.一直以来,都感觉没什么可写.直到最近找工作,不是那么顺利,才突然发现自己的欠缺的很多. 之前总以为自己懂得不少测试技术,找工作那还不是轻轻松松.现在回头想想,这个坑好深,自己沉浸在其中,沾沾自喜,更可悲的是,自己竟毫无所觉. 我想,在这个坑中的人,大有所在.所以今天突然觉得自己该写点什么了,以此来警醒自己,也让那些看到此文的同僚,有所体悟吧. 一.未认清工作的本质 我想,说到软件测试的本质,也就是测试目的,很多人能够脱口而出,那就是“发现更多的缺陷

大数据量分页存储过程效率测试附代码

在项目中,我们经常遇到或用到分页,那么在大数据量(百万级以上)下,哪种分页算法效率最优呢?我们不妨用事实说话. 测试环境 硬件:CPU 酷睿双核T5750  内存:2G 软件:Windows server 2003    +   Sql server 2005 OK,我们首先创建一数据库:data_Test,并在此数据库中创建一表:tb_TestTable 按 Ctrl+C 复制代码1create database data_Test --创建数据库data_Test 2GO 3use data

mybatis常用分页插件,快速分页处理

在未分享整个查询分页的执行代码之前,先了解一下执行流程. 1.总体上是利用mybatis的插件拦截器,在sql执行之前拦截,为查询语句加上limit X X 2.用一个Page对象,贯穿整个执行流程,这个Page对象需要用java编写前端分页组件 3.用一套比较完整的三层entity,dao,service支持这个分页架构 4.这个分页用到的一些辅助类 注:分享的内容较多,这边的话我就不把需要的jar一一列举,大家使用这个分页功能的时候缺少什么就去晚上找什么jar包即可,尽可能用maven包导入

ANDROID内存优化(大汇总——全)

转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上把网上搜集的各种内存零散知识点进行汇总.挑选.简化后整理而成. 所以我将本文定义为一个工具类的文章,如果你在ANDROID开发中遇到关于内存问题,或者马上要参加面试,或者就是单纯的学习或复习一下内存相关知识,都欢迎阅读.(本文最后我会尽量列出所参考的文章). OOM: 内存泄露可以引发很多的问题:

web测试常用的用例及知识

  1.      Web测试中关于登录的测试... 1 2.      搜索功能测试用例设计... 2 3.      翻页功能测试用例... 3 4.      输入框的测试... 5 5.      Web测试的常用的检查点... 6 6.      用户及权限管理功能常规测试方法... 8 7.      Web测试之兼容性测试... 9 8.      Web测试-sql注入... 10 9.      Web测试中书写用例时要考虑的检查点... 11 10.        手机电子邮

MyBatis笔记----mybatis分页

mybatis版本3.4以下 结构 spring-mvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://