MySQL : retrieve a large select by chunks

前端 未结 3 651
深忆病人
深忆病人 2020-12-05 00:57

I have select with more then

70 milion rows

I\'d like to save the selected data into the one large csv file on win2012 R2

3条回答
  •  独厮守ぢ
    2020-12-05 01:10

    The LIMIT OFFSET approach slows query down when a size of the data is very large. Another approach is to use something called Keyset pagination. It requires a unique id in your query, which you can use as a bookmark to point to the last row of the previous page. The next page is fetched using the last bookmark. For instance:

    SELECT user_id, name, date_created
    FROM users
    WHERE user_id > 0
    ORDER BY user_id ASC
    LIMIT 10 000;
    

    If the resultset above returns the last row with user_id as 12345, you can use it to fetch the next page as follows:

    SELECT user_id, name, date_created
    FROM users
    WHERE user_id > 12345
    ORDER BY user_id ASC
    LIMIT 10 000;
    

    For more details, you may take a look at this page.

提交回复
热议问题