Baidu consulted some information, combined with some of its own experience, and adopted the following solution:
Copy code The code is as follows:
$idlist='';
for($i=1;$i<=20;$i++){
if($i==1){
$idlist=mt_rand(3,25216) ;
}
else{
$idlist=$idlist.','.mt_rand(3,25216);
}
}
$query="select * from table where id in ($idlist) LIMIT 0,10";
The principle is actually very simple. It is to generate a set of random IDs and then retrieve the records corresponding to this set of IDs. After this optimization, the page opening speed It is obviously much faster, and the CPU usage is so small that it is almost 0. Haha~ By the way, I also used this idea to optimize the sqlserver site!
Speed comparison:
It takes more than 400 milliseconds to use rand() to get 10 random records, but it only takes about 0.6 milliseconds to use the above method. The difference is huge! ! !
http://www.bkjia.com/PHPjc/321896.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321896.htmlTechArticleBaidu reviewed some information, combined with some of its own experience, and adopted the following solution: Copy the code as follows: $ idlist=''; for($i=1;$i=20;$i++){ if($i==1){ $idlist=mt_rand(3,...