mysql limit分页一般查多少页,limit多少才会有性能问题?
一般文章分页都是 limit 20 条数据左右,我不知道为什么,limit 最大的性能瓶颈在哪里,最大的值在哪里,一次性取5000条有没有问题,10000条呢,到底多少合适,好不好,每次分页取20条太麻烦了。
一直以来我有一个问题,困惑:
1:什么时候要分页,
2:什么时候要有limit限制,
3:什么时候可以直接痛快的获取全部数据
比如饿了么餐厅页面,餐厅可能有很多分类,每个分类下面还有很多菜品,那么这个时候它是直接获取全部数据吗,没有limit限制吗?
假使分类数量不多,不需要limit可以痛快的全部取出,但是每个分类下面的菜品数量可能有点多(打个比方,我也不知道有多少)那么取每个下面的菜品时需要使用limit吗,如果要limit那么取多少条呢,如果这样做那么不是可能会有个“点击查看更多餐品吗”,那不要做个AJAX取余下的数据啊,取余下的数据该怎么取呢?
大概概念是这样,但是我还是很晕,希望大神结合我说的实例指点一下困惑,谢谢了!
回复内容:
一般文章分页都是 limit 20 条数据左右,我不知道为什么,limit 最大的性能瓶颈在哪里,最大的值在哪里,一次性取5000条有没有问题,10000条呢,到底多少合适,好不好,每次分页取20条太麻烦了。
一直以来我有一个问题,困惑:
1:什么时候要分页,
2:什么时候要有limit限制,
3:什么时候可以直接痛快的获取全部数据
比如饿了么餐厅页面,餐厅可能有很多分类,每个分类下面还有很多菜品,那么这个时候它是直接获取全部数据吗,没有limit限制吗?
假使分类数量不多,不需要limit可以痛快的全部取出,但是每个分类下面的菜品数量可能有点多(打个比方,我也不知道有多少)那么取每个下面的菜品时需要使用limit吗,如果要limit那么取多少条呢,如果这样做那么不是可能会有个“点击查看更多餐品吗”,那不要做个AJAX取余下的数据啊,取余下的数据该怎么取呢?
大概概念是这样,但是我还是很晕,希望大神结合我说的实例指点一下困惑,谢谢了!
什么时候要分页?
当表中数据量大的时候就应该考虑分页什么时候要有limit限制?
同上什么时候可以直接痛快的获取全部数据?
当表中数据量不大的时候可以一次取所有数据
读取20条数据和读取5000条乃至更多的数据,性能上肯定是20条更快的。而且这个快,不光体现在数据库上,还体现在网络上的传输过程中(数据量小传得当然快),页面的渲染中(数据量少展示页面就更快)。另外,即使你一次展示5000条数据,但用户绝大多数情况下也就能看到二三十条,并不会将5000条全看完,所以多余的数据也就是浪费的。
如果是小型元素(比如只有文字,或者信息量较少的元素),单页量设置在100以下。如果是大型元素(信息量大,带图文一类的),单页量最好控制在30以下。
够用就好。取多了浪费。
用户只看20条,你取21条都多余。
返回几百条上千条甚至全部,那影响就大了。
首先数据库查询慢,占用更多的服务器资源,查出结果后传输慢,占用更多的带宽资源,其次渲染慢,浏览器也会崩溃。
不用想太多了,这个只是产品定下来的而已,通常最多就20~30条,展示多少条完全是看美观而已。当然,你说的 什么时候可以直接痛快的获取全部数据。这个情况是绝对不可能存在的,怎么可能会获取全部的数据呢,如果文章量达到了千万级怎么办,这取出来也太久了吧。
分页20,而为什么不是5000,10000,主要还是一楼说的,用不到,用不到,用不到那么多
数据库一般有个配置可以配置你每次查询请求返回数据的大小上限,一般情况下,是不会超出这个上限的.只要不超出这个上限,其实怎么拿都是可以的.但是,一般采用按需获取原则,你原则上没有必要拿这么多就不需要拿这么多,毕竟拿得多,你对于网卡的带宽是有占用的,我举例,假设你是千M网卡,limit 1W消耗的带宽是10K,那么从网卡带宽的角度来说(先不说数据库性能问题)你能够极限的QPS也就是1000M/10K=10W QPS.当然如果你网卡可以上万兆网卡.另外对于用户端来说,每次请求获取更多的数据,实际上也是降低了请求到达的速度.
网络传输消耗带宽
网络传输消耗带宽
网络传输消耗带宽
重要事情说3遍

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.
