Mysql limit ÓÅ»¯£¬°ÙÍòÖÁǧÍò¼¶¿ìËÙ·ÖÒ³£¬--¸´ºÏË÷ÒýµÄÒýÓò¢Ó¦ÓÃÓÚÇáÁ¿¼¶¿ò¼Ü
MySql ÐÔÄܵ½µ×ÄÜÓжà¸ß£¿ÓÃÁËphp°ëÄê¶à£¬ÕæÕýÈç´ËÉîÈëµÄȥ˼¿¼Õâ¸öÎÊÌ⻹ÊÇ´ÓÇ°Ì쿪ʼ¡£ÓйýÍ´¿àÓйý¾øÍû£¬µ½ÏÖÔÚ³äÂúÐÅÐÄ£¡MySql
Õâ
¸öÊý¾Ý¿â¾ø¶ÔÊÇÊʺÏdba¼¶µÄ¸ßÊÖÈ¥ÍæµÄ£¬Ò»°ã×öÒ»µã1ÍòƪÐÂÎŵÄСÐÍϵͳÔõôд¶¼¿ÉÒÔ£¬ÓÃxx¿ò¼Ü¿ÉÒÔʵÏÖ¿ìËÙ¿ª·¢¡£¿ÉÊÇÊý¾ÝÁ¿µ½ÁË10Íò£¬°ÙÍòÖÁǧ
Íò£¬ËûµÄÐÔÄÜ»¹ÄÜÄÇô¸ßÂð£¿Ò»µãССµÄʧÎ󣬿ÉÄÜÔì³ÉÕû¸öϵͳµÄ¸Äд£¬ÉõÖÁ¸ü±¾ÏµÍ³ÎÞ·¨Õý³£ÔËÐУ¡ºÃÁË£¬²»ÄÇô¶à·Ï»°ÁË¡£ÓÃÊÂʵ˵»°£¬¿´Àý×Ó£º
Êý¾Ý±í collect ( id, title ,info ,vtype) ¾ÍÕâ4¸ö×ֶΣ¬ÆäÖÐ title Óö¨³¤£¬info ÓÃtext, id
ÊÇÖð½¥£¬vtypeÊÇtinyint£¬vtypeÊÇË÷Òý¡£ÕâÊÇÒ»¸ö»ù±¾µÄÐÂÎÅϵͳµÄ¼òµ¥Ä£ÐÍ¡£ÏÖÔÚÍùÀïÃæÌî³äÊý¾Ý£¬Ìî³ä10ÍòƪÐÂÎÅ¡£
×îºócollect Ϊ 10ÍòÌõ¼Ç¼£¬Êý¾Ý¿â±íÕ¼ÓÃÓ²ÅÌ1.6G¡£OK ,¿´ÏÂÃæÕâÌõsqlÓï¾ä£º
select id,title from collect limit 1000,10; ºÜ¿ì£»»ù±¾ÉÏ0.01Ãë¾ÍOK£¬ÔÙ¿´ÏÂÃæµÄ
select id,title from collect limit 90000,10; ´Ó9ÍòÌõ¿ªÊ¼·ÖÒ³£¬½á¹û£¿
8-9ÃëÍê³É£¬my god ÄijöÎÊÌâÁË£¿£¿£¿£¿ÆäʵҪÓÅ»¯ÕâÌõÊý¾Ý£¬ÍøÉÏÕҵõ½´ð°¸¡£¿´ÏÂÃæÒ»ÌõÓï¾ä:
select id from collect order by id limit 90000,10; ºÜ¿ì£¬0.04Ãë¾ÍOK¡£
Ϊʲô£¿ÒòΪÓÃÁËidÖ÷¼ü×öË÷Òýµ±È»¿ì¡£ÍøÉϵĸķ¨ÊÇ£º
select id,title from collect where id>=(select id from collect order by id
limit 90000,1) limit 10;
Õâ¾ÍÊÇÓÃÁËid×öË÷ÒýµÄ½á¹û¡£¿ÉÊÇÎÊÌ⸴ÔÓÄÇôһµãµã£¬¾ÍÍêÁË¡£¿´ÏÂÃæµÄÓï¾ä
select id from collect where vtype=1 order by id limit 90000,10;
ºÜÂý£¬ÓÃÁË8-9Ã룡
µ½ÁËÕâÀïÎÒÏàÐźܶàÈË»áºÍÎÒÒ»Ñù£¬ÓбÀÀ£¸Ð¾õ£¡vtype ×öÁËË÷ÒýÁË°¡£¿Ôõô»áÂýÄØ£¿vtype×öÁËË÷ÒýÊDz»´í£¬ÄãÖ±½Ó select id from
collect where vtype=1 limit 1000,10;
ÊǺܿìµÄ£¬»ù±¾ÉÏ0.05Ã룬¿ÉÊÇÌá¸ß90±¶£¬´Ó9Íò¿ªÊ¼£¬ÄǾÍÊÇ0.05*90=4.5ÃëµÄËÙ¶ÈÁË¡£ºÍ²âÊÔ½á¹û8-9Ãëµ½ÁËÒ»¸öÊýÁ¿¼¶¡£´ÓÕâÀ↑ʼÓÐÈËÌá³öÁË·Ö±íµÄ˼·£¬Õâ¸öºÍdiscuz
ÂÛ̳ÊÇÒ»ÑùµÄ˼·¡£Ë¼Â·ÈçÏ£º
½¨Ò»¸öË÷Òý±í£º t (id,title,vtype) ²¢ÉèÖóɶ¨³¤£¬È»ºó×ö·ÖÒ³£¬·ÖÒ³³ö½á¹ûÔÙµ½ collect ÀïÃæÈ¥ÕÒinfo ¡£
ÊÇ·ñ¿ÉÐÐÄØ£¿ÊµÑéϾÍÖªµÀÁË¡£
10ÍòÌõ¼Ç¼µ½ t(id,title,vtype) ÀÊý¾Ý±í´óС20M×óÓÒ¡£ÓÃ
select id from t where vtype=1 order by id limit 90000,10;
ºÜ¿ìÁË¡£»ù±¾ÉÏ0.1-0.2Ãë¿ÉÒÔÅÜÍꡣΪʲô»áÕâÑùÄØ£¿ÎÒ²ÂÏëÊÇÒòΪcollect Êý¾ÝÌ«¶à£¬ËùÒÔ·ÖÒ³ÒªÅܺܳ¤µÄ·¡£limit
ÍêÈ«ºÍÊý¾Ý±íµÄ´óСÓйصġ£ÆäʵÕâÑù×ö»¹ÊÇÈ«±íɨÃ裬ֻÊÇÒòΪÊý¾ÝÁ¿Ð¡£¬Ö»ÓÐ10Íò²Å¿ì¡£OK£¬ À´¸ö·è¿ñµÄʵÑ飬¼Óµ½100ÍòÌõ£¬²âÊÔÐÔÄÜ¡£
¼ÓÁË10±¶µÄÊý¾Ý£¬ÂíÉÏt±í¾Íµ½ÁË200¶àM£¬¶øÇÒÊǶ¨³¤¡£»¹ÊǸղŵIJéѯÓï¾ä£¬Ê±¼äÊÇ0.1-0.2ÃëÍê³É£¡·Ö±íÐÔÄÜûÎÊÌ⣿´í£¡ÒòΪÎÒÃǵÄlimit»¹ÊÇ9Íò£¬ËùÒÔ¿ì¡£¸ø¸ö´óµÄ£¬90Íò¿ªÊ¼
select id from t where vtype=1 order by id limit 900000,10; ¿´¿´½á¹û£¬Ê±¼äÊÇ1-2Ã룡
why ?? ·Ö±íÁËʱ¼ä»¹ÊÇÕâô³¤£¬·Ç³£Ö®ÓôÃÆ£¡ÓÐÈË˵¶¨³¤»áÌá¸ßlimitµÄÐÔÄÜ£¬¿ªÊ¼ÎÒÒ²ÒÔΪ£¬ÒòΪһÌõ¼Ç¼µÄ³¤¶ÈÊǹ̶¨µÄ£¬mysql
Ó¦¸Ã¿ÉÒÔËã³ö90ÍòµÄλÖòŶ԰¡£¿ ¿ÉÊÇÎÒÃǸ߹ÀÁËmysql µÄÖÇÄÜ£¬Ëû²»ÊÇÉÌÎñÊý¾Ý¿â£¬ÊÂʵ֤Ã÷¶¨³¤ºÍ·Ç¶¨³¤¶ÔlimitÓ°Ïì²»´ó£¿ ¹Ö²»µÃÓÐÈË˵
discuzµ½ÁË100ÍòÌõ¼Ç¼¾Í»áºÜÂý£¬ÎÒÏàÐÅÕâÊÇÕæµÄ£¬Õâ¸öºÍÊý¾Ý¿âÉè¼ÆÓйأ¡
ÄѵÀMySQL ÎÞ·¨Í»ÆÆ100ÍòµÄÏÞÖÆÂ𣿣¿£¿µ½ÁË100ÍòµÄ·ÖÒ³¾ÍÕæµÄµ½Á˼«ÏÞ£¿£¿£¿
´ð°¸ÊÇ£º NO !!!!
ΪʲôͻÆƲ»ÁË100ÍòÊÇÒòΪ²»»áÉè¼ÆmysqlÔì³ÉµÄ¡£ÏÂÃæ½éÉÜ·Ç·Ö±í·¨£¬À´¸ö·è¿ñµÄ²âÊÔ£¡Ò»Õűí¸ã¶¨100Íò¼Ç¼£¬²¢ÇÒ10G
Êý¾Ý¿â£¬ÈçºÎ¿ìËÙ·ÖÒ³£¡
ºÃÁË£¬ÎÒÃǵIJâÊÔÓֻص½ collect±í£¬¿ªÊ¼²âÊÔ½áÂÛÊÇ£º
30ÍòÊý¾Ý£¬ÓÃ·Ö±í·¨¿ÉÐУ¬³¬¹ý30ÍòËûµÄËٶȻáÂýµÀÄãÎÞ·¨ÈÌÊÜ£¡µ±È»Èç¹ûÓ÷ֱí+ÎÒÕâÖÖ·½·¨£¬ÄÇÊǾø¶ÔÍêÃÀµÄ¡£µ«ÊÇÓÃÁËÎÒÕâÖÖ·½·¨ºó£¬²»Ó÷ֱíÒ²¿ÉÒÔÍêÃÀ½â¾ö£¡
´ð°¸¾ÍÊÇ£º¸´ºÏË÷Òý£¡ ÓÐÒ»´ÎÉè¼ÆmysqlË÷ÒýµÄʱºò£¬ÎÞÒâÖз¢ÏÖË÷ÒýÃû×Ö¿ÉÒÔÈÎÈ¡£¬¿ÉÒÔÑ¡Ôñ¼¸¸ö×ֶνøÀ´£¬ÕâÓÐʲôÓÃÄØ£¿¿ªÊ¼µÄselect id from
collect order by id limit 90000,10; Õâô¿ì¾ÍÊÇÒòΪ×ßÁËË÷Òý£¬¿ÉÊÇÈç¹û¼ÓÁËwhere ¾Í²»×ßË÷ÒýÁË¡£±§×ÅÊÔÊÔ¿´µÄÏë·¨¼ÓÁË
search(vtype,id) ÕâÑùµÄË÷Òý¡£È»ºó²âÊÔ
select id from collect where vtype=1 limit 90000,10; ·Ç³£¿ì£¡0.04ÃëÍê³É£¡
ÔÙ²âÊÔ: select id ,title from collect where vtype=1 limit 90000,10;
·Ç³£Òź¶£¬8-9Ã룬û×ßsearchË÷Òý£¡
ÔÙ²âÊÔ£ºsearch(id,vtype)£¬»¹ÊÇselect id Õâ¸öÓï¾ä£¬Ò²·Ç³£Òź¶£¬0.5Ãë¡£
×ÛÉÏ£ºÈç¹û¶ÔÓÚÓÐwhere Ìõ¼þ£¬ÓÖÏë×ßË÷ÒýÓÃlimitµÄ£¬±ØÐëÉè¼ÆÒ»¸öË÷Òý£¬½«where
·ÅµÚһ룬limitÓõ½µÄÖ÷¼ü·ÅµÚ2룬¶øÇÒÖ»ÄÜselect Ö÷¼ü£¡
ÍêÃÀ½â¾öÁË·ÖÒ³ÎÊÌâÁË¡£¿ÉÒÔ¿ìËÙ·µ»Øid¾ÍÓÐÏ£ÍûÓÅ»¯limit £¬ °´ÕâÑùµÄÂß¼£¬°ÙÍò¼¶µÄlimit Ó¦¸ÃÔÚ0.0xÃë¾Í¿ÉÒÔ·ÖÍê¡£¿´À´mysql
Óï¾äµÄÓÅ»¯ºÍË÷Òýʱ·Ç³£ÖØÒªµÄ£¡
ºÃÁË£¬»Øµ½ÔÌ⣬ÈçºÎ½«ÉÏÃæµÄÑо¿³É¹¦¿ìËÙÓ¦ÓÃÓÚ¿ª·¢ÄØ£¿Èç¹ûÓø´ºÏ²éѯ£¬ÎÒµÄÇáÁ¿¼¶¿ò¼Ü¾ÍûµÄÓÃÁË¡£·ÖÒ³×Ö·û´®»¹µÃ×Ô¼ºÐ´£¬ÄǶàÂé·³£¿ÕâÀïÔÙ¿´Ò»¸öÀý×Ó£¬Ë¼Â·¾Í³öÀ´ÁË£º
select * from collect where id in (9000,12,50,7000); ¾¹È» 0Ãë¾Í¿ÉÒÔ²éÍ꣡
mygod £¬mysql µÄË÷Òý¾¹È»¶ÔÓÚinÓï¾äͬÑùÓÐЧ£¡¿´À´ÍøÉÏ˵inÎÞ·¨ÓÃË÷ÒýÊÇ´íÎóµÄ£¡
ÓÐÁËÕâ¸ö½áÂÛ£¬¾Í¿ÉÒԺܼòµ¥µÄÓ¦ÓÃÓÚÇáÁ¿¼¶¿ò¼ÜÁË£º
´úÂëÈçÏ£º
$db=dblink();
$db->pagesize=20;
$sql="select id from collect where vtype=$vtype";
$db->execute($sql);
$strpage=$db->strpage();
//½«·ÖÒ³×Ö·û´®±£´æÔÚÁÙʱ±äÁ¿£¬·½±ãÊä³ö
while($rs=$db->fetch_array()){
$strid.=$rs['id'].',';
}
$strid=substr($strid,0,strlen($strid)-1);
//¹¹Ôì³öid×Ö·û´®
$db->pagesize=0;
//ºÜ¹Ø¼ü£¬ÔÚ²»×¢ÏúÀàµÄÇé¿öÏ£¬½«·ÖÒ³Çå¿Õ£¬ÕâÑùÖ»ÐèÒªÓÃÒ»´ÎÊý¾Ý¿âÁ¬½Ó£¬²»ÐèÒªÔÙ¿ª£»
$db->execute("select
id,title,url,sTime,gTime,vtype,tag from collect where id in ($strid)");
<?php while($rs=$db->fetch_array()): ?>
<tr>
<td> <?php echo $rs['id'];?></td>
<td> <?php echo $rs['url'];?></td>
<td> <?php echo $rs['sTime'];?></td>
<td> <?php echo $rs['gTime'];?></td>
<td> <?php echo $rs['vtype'];?></td>
<td> <a href="?act=show&id=<?php echo $rs['id'];?>"
target="_blank"><?php echo $rs['title'];?></a></td>
<td> <?php echo
$rs['tag'];?></td>
</tr>
<?php endwhile;
?>
</table>
<?php
echo $strpage;
ͨ¹ý¼òµ¥µÄ±ä»»£¬Æäʵ˼·ºÜ¼òµ¥£º1£©Í¨¹ýÓÅ»¯Ë÷Òý£¬ÕÒ³öid£¬²¢Æ´³É "123,90000,12000" ÕâÑùµÄ×Ö·û´®¡£2£©µÚ2´Î²éѯÕÒ³ö½á¹û¡£
ССµÄË÷Òý+Ò»µãµãµÄ¸Ä¶¯¾Íʹmysql ¿ÉÒÔÖ§³Ö°ÙÍòÉõÖÁǧÍò¼¶µÄ¸ßЧ·ÖÒ³£¡
ͨ¹ýÕâÀïµÄÀý×Ó£¬ÎÒ·´Ë¼ÁËÒ»µã£º¶ÔÓÚ´óÐÍϵͳ£¬PHPǧÍò²»ÄÜÓÿò¼Ü£¬ÓÈÆäÊÇÄÇÖÖÁ¬sqlÓï¾ä¶¼¿´²»µ½µÄ¿ò¼Ü£¡ÒòΪ¿ªÊ¼¶ÔÓÚÎÒµÄÇáÁ¿¼¶¿ò¼Ü¶¼²îµã±À
À££¡Ö»ÊʺÏСÐÍÓ¦ÓõĿìËÙ¿ª·¢£¬¶ÔÓÚERP,OA£¬´óÐÍÍøÕ¾£¬Êý¾Ý²ã°üÀ¨Âß¼²ãµÄ¶«Î÷¶¼²»ÄÜÓÿò¼Ü¡£Èç¹û³ÌÐòԱʧȥÁ˶ÔsqlÓï¾äµÄ°Ñ¿Ø£¬ÄÇÏîÄ¿µÄ·çÏÕ½«
»á³É¼¸ºÎ¼¶ÊýÔö¼Ó£¡ÓÈÆäÊÇÓÃmysql
µÄʱºò£¬mysql Ò»¶¨ÐèҪרҵµÄdba ²Å¿ÉÒÔ·¢»ÓËûµÄ×î¼ÑÐÔÄÜ¡£Ò»¸öË÷ÒýËùÔì³ÉµÄÐÔÄܲî±ð¿ÉÄÜÊÇÉÏǧ±¶£¡
PS:
¾¹ýʵ¼Ê²âÊÔ£¬µ½ÁË100ÍòµÄÊý¾Ý£¬160ÍòÊý¾Ý£¬15G±í£¬190MË÷Òý£¬¾ÍËã×ßË÷Òý£¬limit¶¼µÃ0.49Ãë¡£ËùÒÔ·ÖÒ³×îºÃ±ðÈñðÈË¿´µ½10ÍòÌõÒÔºóµÄÊý¾Ý£¬Òª²»È»»áºÜÂý£¡¾ÍËãÓÃË÷Òý¡£¾¹ýÕâÑùµÄÓÅ»¯£¬mysqlµ½ÁË°ÙÍò¼¶·ÖÒ³ÊǸö¼«ÏÞ£¡µ«ÓÐÕâÑùµÄ³É¼¨ÒѾºÜ²»´í£¬Èç¹ûÄãÊÇÓÃsqlserver¿Ï¶¨¿¨ËÀ£¡¶ø160ÍòµÄÊý¾ÝÓÃ
id in (str) ºÜ¿ì£¬»ù±¾»¹ÊÇ0Ãë¡£Èç¹ûÕâÑù£¬Ç§Íò¼¶µÄÊý¾Ý£¬mysqlÓ¦¸ÃÒ²ºÜÈÝÒ×Ó¦¸¶¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ