select的内容越多,速度越低,所以要先限定范围再选择内容。如果select内容多,比如mysql的limit,偏移量越往后越慢。
下面分页,百万数据,没有查询条件,应该是最慢的情况,sqlserver 在0.5-1.2秒可以返回。mysql似乎可以快一倍。
//sqlserver 2005 高效率分页
//select
select * from contenttest
INNER JOIN
(
select id, row_number() over(order by contenttest.Keywords) as rowid
from contenttest
where Keywords = '关键字18'
)
as t
on t.id = contenttest.id
where t.rowid between 500000 and 500010
//count
select count(*) from contenttest
where Keywords = '关键字18'
//mysql 高效率分页
//select
SELECT * from contenttest
inner join
(
SELECT id from contenttest
where Keywords = '关键字9'
ORDER BY Keywords
limit 500000,10) as t ON t.id = contenttest.id
//count
SELECT count(*) from contenttest
where Keywords = '关键字9'