Hongmu Notes
Home Language Notes Mysql efficiency improvement: limit this piece of shit
Language Notes mySql

Mysql efficiency improvement: limit this piece of shit

Mysql efficiency improvement: limit this piece of shit

In mysql, the limit efficiency is not high, especially when I have millions of data, the limit is 100000, 50. Written like this, the query is even slower. It was quite fast at the beginning, but later the server cup was filled up directly for me!

I thought the server had been hacked, so I looked for the problem. After searching for a few days, I found out that it was this piece of shit, which pissed me off!

So I looked up the principle of limit, emmm, change it! Must change!

So the initial code is:


SELECT * FROM phome_ecms_news  ORDER BY id DESC LIMIT 1275480,20;

Changed it to:


SELECT * FROM phome_ecms_news  WHERE id>1275480 ORDER BY id DESC LIMIT 20;

Let me briefly talk about the principle of LIMIT here. This is based on LIMIT N,M: LIMIT first searches for N+M rows, and then takes M rows from N rows. Then such SQL should be expensive to query 1275500 operations at a time. For optimizations such as LIMIT, the first goal is to make N as small as possible or not use it.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

sqlite uses PDO to execute SQL statements exec(), query()

sqlite uses PDO to execute SQL statements exec(), query() Language Notes mySql

In PHP scripts, executing SQL queries using PDO to interact with a database can be done through three different approaches; the choice of which method to use depends on the specific operation you intend to perform. 1. Using the PDO::exec() method: When executing queries such as INSERT, UPDATE, or DELETE that do not return a result set, use the exec() method on a PDO object to execute the query. Upon successful execution, this method returns the number of affected rows...
👁 323
SQL statement to truncate the database

SQL statement to truncate the database Language Notes mySql

The TRUNCATE command can be used to clear a table; however, if you need to clear an entire database, you must clear each table individually. Below is an example SQL statement for clearing an entire database: SET foreign_key_checks = 0; SELECT CONCAT('TRUNCATE TABLE `',table_name,'`;') FR...
👁 297
Query error: #1075-Incorrect table definition; there can be only one auto column, and it must be defined as a key.

Query error: #1075-Incorrect table definition; there can be only one auto column, and it must be defined as a key. Language Notes mySql

This error message indicates that you have defined multiple auto-increment columns when creating a table, or that you have not defined an auto-increment column as a primary key or a unique key; as a result, MySQL is unable to create the table. In MySQL, there can be only one auto-increment column, and it must be defined as a primary key or a unique key. Here are some possible ways to resolve this issue: Ensure that there is only one auto-increment column: You should check your table definition to confirm that only one column is defined as an auto-increment column. If you need...
👁 409

Recommended reading

Responsive Wealth Management Insurance Website Template 1169

Responsive Wealth Management Insurance Website Template 1169 Practical Collection Yiyou template

An EyouCMS responsive website template designed for the wealth management and insurance industries. Its professional financial design style effectively showcases wealth management services, insurance products, investment solutions, and success stories, helping financial institutions attract high-net-worth clients online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (E...
👁 55
(Adaptive mobile version) Black blog website template – IT technology news website source code download – 0932

(Adaptive mobile version) Black blog website template – IT technology news website source code download – 0932 Practical Collection pbootcms Template

A black-themed PbootCMS website template for technology and IT news sites, compatible with both PC and WAP devices. Features a stylish information-feed design ideal for technology blogs and IT news websites sharing industry updates. Helps technology media outlets attract online readers and build their influence. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 48
Combine multiple Python articles into a single article.

Combine multiple Python articles into a single article. Language Notes python

A friend mentioned needing to combine multiple Markdown-format files or articles into a single document. The requirement is quite simple: merge several TXT files from a folder into one document in sequential order. The output format should be as follows: <h3>Document 1 – File Name</h3> – Document 1 Content <h3>Document 2 – File Name</h3> – Document 2 Content <h3>Document 3 – File Name...
👁 201
Responsive wireless payment card reader website template – 1170

Responsive wireless payment card reader website template – 1170 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the wireless payment and card reader industry, featuring a modern, tech-driven financial design style perfect for showcasing POS terminal products, mobile payment systems, technical specifications, and commercial applications. It enables payment device manufacturers to present their products online and attract merchants and financial clients. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Questions About EyouCMS Installation...
👁 34
(Adaptive mobile version) Responsive personal blog website template – Download source code for blue-themed news and information websites – 0933

(Adaptive mobile version) Responsive personal blog website template – Download source code for blue-themed news and information websites – 0933 Practical Collection pbootcms Template

A responsive personal blog and Blue News PbootCMS website template compatible with both PC and WAP devices. The clean and modern design makes it ideal for personal bloggers or news site administrators to build content-driven websites. It enables creators to establish their personal brand or content-sharing platforms at low cost and with high efficiency. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 47
Use PHP regular expressions to replace specified content – replace it only once.

Use PHP regular expressions to replace specified content – replace it only once. Language Notes PHP

To replace specific content with regular expressions in PHP, but only once, you can use the `preg_replace_callback()` function. This function accepts three parameters: the string to be replaced, the replacement string, and a callback function. The callback function is a custom function that is executed during the regular expression search and replacement process. Here is an example: $string = "Hello, world...";
👁 208