Optimizing my mysql statement! - RAND() TOO SLOW

后端 未结 6 746
孤独总比滥情好
孤独总比滥情好 2020-12-11 03:26

So I have a table with over 80,000 records, this one is called system. I also have another table called follows.

I need my statement to randomly select records from

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 04:13

    Depending on how random your data needs to be it might be worth ordering the data and adding an extra "last used" datetime column and update this once you use the data. Then select the top n rows ordering by the last used field descending.

    If you wrap this in a prepared statement you can select one (semi) random result at a time without worrying about the logic.

    Alternatively give every row a sequential ID and generate the randomness in the code and pull back just the required rows. The problem is that the full recordset is being returned prior to being ordered.

提交回复
热议问题