我有一个效率相当低的 MySQL 查询,直到最近随着数据库规模的扩大,它一直运行良好。我正在尝试使用 ORDER BY RAND() 语法选择一个随机记录,但它非常慢(30 多秒)并导致我的 PHP 脚本出现问题。有没有更有效的方法来编写这个查询?
SELECT * FROM accountcampaign, accounts WHERE
accountcampaign.status='ACTIVE'
AND accountcampaign.dateLocked IS NULL
AND accountcampaign.campaignID='1'
AND ( (accountcampaign.lockedIPAddress IS NULL)
OR (accountcampaign.lockedIPAddress='')
)
AND ( (accountcampaign.dateLastEntry IS NULL)
OR (DATE(accountcampaign.dateLastEntry) < DATE(NOW()))
)
ORDER BY RAND() LIMIT 1