Home > Database > Mysql Tutorial > sql-MySql执行分页时查询统计数据量的Sql语句差别及性能

sql-MySql执行分页时查询统计数据量的Sql语句差别及性能

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 09:34:59
Original
1212 people have browsed it

sqlmysql程序员数据

现在开发系统,涉及到了分页查询,在做的时候就在想,能不能自动把查询sql语句通过参数自动封装成能够统计查询语句不在分页条件下查询出的数据量有多大,例如一般做法是:

1.先根据拼接的sql语句进行查询:select * from ecs_goods where goods_type = 1 limit 1000, 10

2.再统计数量:select count(*) from ecs_goods where goods_type = 1

然后就可以得出分页的相关数据了

现在想着的逻辑是:

1.程序员写出带查询的Sql语句:select * from ecs_goods where goods_type = 1

2.程序员传入分页信息参数获取到:limit 1000,10

3.程序自动根据以上两步拼接出:select count(*) from (select * from ecs_goods where goods_type = 1)

这样两种方式在查询速度及性能上会差距很大吗?为什么?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template