How to optimize when there are too many pages in SQL?

when there are too many SQL pages (for example, limit 1000000,20), the efficiency will be significantly reduced. How to optimize it? Here, take mysql as an example


SELECT * FROM product WHERE ID > = (select id from product limit 1000000,1) limit 20;


SELECT * FROM product WHERE ID > = (select id from product limit 1000000,1) limit 20;


I have a solution here. I learned this before by reading the materials. I forgot exactly where I did. if you have a better idea, you can exchange it.
create an index table , which provides sequential relationships related to keys in the target table, you can join this index table to the target table, and use the where clause to get the desired rows more efficiently.

CREATE TABLE test (
   test_no int not null auto_increment,
   id int not null,
   primary key(test_no),
   unique(id)
);

TRUNCATE test;
INSERT INTO test (id) SELECT id FROM mytable ORDER BY id;

SELECT mytable.* 
FROM mytable 
INNER JOIN seq USING(id)
WHERE test.test_no BETWEEN 1000000 AND 1000020;
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9dd23-1984.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9dd23-1984.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?