通过rand查询订单问题

时间:2011-01-10 08:28:15

标签: 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?

2 个答案:

答案 0 :(得分:2)

见Bill Karwin的演讲。向前滑动142.

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

答案 1 :(得分:0)

检查一下...... $ limit = 10; $ start = 0; $ sql =“SELECT  posts.Tags作为标签,  posts.OwnerUserId作为postsid,  posts.Id as postid,  posts.Body作为身体,  posts.Title as title,  users.Id as userid,  users.DisplayName作为用户名
来自帖子 JOIN用户ON posts.OwnerUserId = users.Id 在哪里posts.Title!=''由rand()asc limit命令。$ start。“,”。$ limit;

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