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.