Get first part of result faster in sorting query on hundreds of millions of rows?
First, I have to ask what the client will do with 280M rows?  If it is a web page, that much data will crash the user's machine.

Here are two things to speed up getting data from that query:


Change the indexes to these:

PRIMARY KEY(moment, id),  -- to cluster the data in the order to be fetched
INDEX(id)   -- to keep AUTO_INCREMENT happy.



What you have now will fetch all the data, then sort it by moment, before delivering even the first row.  With the indexing change, the sort is gone, and the rest can be 'streamed' directly.  But will the client take advantage of that?  Well...


Change the fetching mechanism to receive the data in chunks instead of "all at once".  (The details of this choice are buried in the API of how the client talks to MySQL.  I only use the "all at once".  But I never ask for 280M rows.)


Drawbacks of "chunking":


The entire query takes longer.  (That is, more than 37 minutes.)
Other connections may be impacted by such a long-running query.


Consider this alternative:  SELECT ... INTO OUTFILE ... and then process the resulting file as you might process a CSV file.