场景:1000多万条记录的用户表members,查询起来非常之慢,同事的做法是将其散列到100个表中,分别从members0到members99,然后根据mid分发记录到这些表中,牛逼的代码大概是这样子:
<?php for($i=0;$i< 100; $i++ ){ //echo "CREATE TABLE db2.members{$i} LIKE db1.members<br>"; echo "INSERT INTO members{$i} SELECT * FROM members WHERE mid%100={$i}<br>"; } ?>