mysql查询随机返回效率问题(使用join 和 rand() 耗时 0.001s)

使用join 和 rand() 耗时 0.001s

SELECT
    *
FROM
    `t_topic` AS t1
JOIN (
    SELECT
        ROUND(
            RAND() * (
                (SELECT MAX(id) FROM `t_topic`) - (SELECT MIN(id) FROM `t_topic`)
            ) + (SELECT MIN(id) FROM `t_topic`)
        ) AS id
) AS t2
WHERE
    t1.id >= t2.id
ORDER BY
    t1.id
LIMIT 10;

posted @ 2022-06-28 16:10  贵隆  阅读(26)  评论(0编辑  收藏  举报