mysql limit 百万数据分页

mysql> select *  from credit_coupon limit 3700000, 1;
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+
| id      | vocher_record_id | user_id | vocher_lottery_id | credit_num | par_value | type | status | start_date | end_date   | add_time            | lottery_id |
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+
| 3704467 |           898239 | 3871220 |                 0 |       2000 |        20 | D    |      1 | 2015-12-22 | 2016-08-31 | 2015-12-22 10:59:06 |          3 |
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+
1 row in set (3.52 sec)

#索引覆盖,不回行
mysql> select id  from credit_coupon limit 3700000, 1;
+---------+
| id      |
+---------+
| 2223197 |
+---------+
1 row in set (1.10 sec)

#数据是完整的,但是相对速度慢
mysql> select * from credit_coupon as c inner join (select id  from credit_coupon limit 3700000, 1) as d on c.id = d.id;
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+---------+
| id      | vocher_record_id | user_id | vocher_lottery_id | credit_num | par_value | type | status | start_date | end_date   | add_time            | lottery_id | id      |
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+---------+
| 2223197 |                0 | 3502876 |            576734 |        500 |         5 | E    |      1 | 2015-12-15 | 2016-08-31 | 2015-12-15 13:09:59 |          6 | 2223197 |
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+---------+
1 row in set (1.26 sec)

#速度最快,但是数据有可能不是完整的
mysql> select * from credit_coupon where id > 3700000 limit 1;
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+
| id      | vocher_record_id | user_id | vocher_lottery_id | credit_num | par_value | type | status | start_date | end_date   | add_time            | lottery_id |
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+
| 3700001 |           897160 | 3870142 |                 0 |       3000 |        30 | C    |      1 | 2015-12-22 | 2016-08-31 | 2015-12-22 10:23:29 |          3 |
+---------+------------------+---------+-------------------+------------+-----------+------+--------+------------+------------+---------------------+------------+
1 row in set (0.00 sec)


你可能感兴趣的:(mysql limit 百万数据分页)