mysql - order by rand 的查询问题

标签 mysql performance

$totalrows = 10;

$sql = "SELECT 
 posts.Tags as tags, 
 posts.OwnerUserId as postsid, 
 posts.Id as postid, 
 posts.Body as body, 
 posts.Title as title, 
 users.Id as userid, 
 users.DisplayName as usersname  
FROM posts 
JOIN users ON posts.OwnerUserId = users.Id 
WHERE posts.Title != '' order by rand() asc limit " .  $totalrows;

$r = mysql_query($sql) or die(mysql_error());

有什么加速 php 的建议吗?

最佳答案

请参阅 Bill Karwin 的演示文稿。幻灯片 142 及以后。

http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back

关于mysql - order by rand 的查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4644871/

相关文章:

php - 加载mysql时先显示主要内容然后显示菜单

MySQL 基于 IF 条件从两个表之一进行 JOIN

c++ - 找到其他节点的最快方法

mysql - 优化 "COUNT(DISTINCT col) WHERE othercol = ?"速度

python - Python 子列表的时间复杂度

c++ - 包装函数参数?

php - Openssl加密随 secret 钥&IV-存储在数据库中

php - 插入不起作用,准备、绑定(bind)和执行,但不起作用

mysql - SQL查询以根据计数过滤出结果

performance - ASP.NET MVC : Store data in OnActionExecuting and retrieve it in OnActionExecuted in a controller