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 the system table, where that id is not already listed within the follows table under the current userid.
So here is what I have:
SELECT system.id,
system.username,
system.password,
system.followed,
system.isvalid,
follows.userid,
follows.systemid
FROM system
LEFT JOIN follows ON system.id = follows.systemid
AND follows.userid = 2
WHERE system.followed = 0
AND system.isvalid = 1
AND follows.systemid IS NULL
ORDER BY RAND()
LIMIT 200
Now it wotks perfectly, except that it takes about a whole minute before it can even start processing the job at hand with the records it chosen. By this time the script usually times oout and nothing happens.
Can somebody show me how to rework this, so the same idea is done, but it is not using order by rand? This seems to slow things down a whole bunch.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…