mysql - Huge dataset, ORDER BY date and limit -


I have a MySQL table, which has ~ 3.5 MOO lines. I want to iterate on each line since I have all 3.5 The MOO does not want to load the lines, so I divided it into separate queries. I'm using the date field for division.

The problem is now: when I select from the table with a large number of dates from a specified date, it still looks after every date, puts them in the temporary list and cut 90% entries In comparison, I only want small parts.

How can I make my query so that my computer is fully loaded?

The answer in brief is to ensure that your ORDER BY Rather than operating the file, it can be satisfied using an index.

You can select the explanation to get a query plan.

  Explain select T. * From mytable T-Force Index for order (mytable_IX1) where T.created_at & gt; @last_created_at or t.created_at = @last_created_at and t.id & gt; @last_id ORDER BY t.created_at, t.id LIMIT 1000 id select_type table type possible_keys key key_len referee row additional - ----------- ----------- --- - --------- ----------- ------- ------ ---- ------------ - 1 Simple T Range mytable_IX1 mytable_IX1 13 (faucet) 1000 Where to use; Using the index   

On the first execution, you only do not need t.created_at predicate Later on the death penalty, you get the column from the last line you have received The values ​​will pass, so that you can start your next query from that point.

Comments