MYSQLÖÐͳ¼Æ²éѯ½á¹û×ÜÐÐÊýµÄ±ã½Ý·½·¨¡¾×ªÔØ¡¿
ת×Ô£ºhttp://ginew.blog.163.com/
½ñÌìÔĶÁ wordpress´úÂëʱ£¬·¢ÏÖÒ»¸öMYSQLµÄ¹Ø¼ü´Ê SQL_CALC_FOUND_ROWS ²é¿´ÊÖ²áºó·¢Ïִ˹ؼü´ÊµÄ×÷ÓÃÊÇÔÚ²éѯʱͳ¼ÆÂú×ã¹ýÂËÌõ¼þºóµÄ½á¹ûµÄ×ÜÊý£¨²»ÊÜ Limit µÄÏÞÖÆ£©
ÀýÈ磺 SELECT SQL_CALC_FOUND_ROWS tid from cdb_threads WHERE fid=14 LIMIT 1,10;
¼ÙÉèÂú×ãÌõ¼þµÄÓÐ1000Ìõ£¬ÕâÀï·µ»Ø10Ìõ¡£Á¢¼´Ê¹Óà SELECT found_rows() AS rowcount; Ôò·µ»ØµÄ rowcount Ϊ1000£»
ÕâÑù½ÚÊ¡ÁËSELECT count(*) AS rowcountµÄÖظ´²éѯ£¬¿ÉÒÔ½ÚÊ¡±È½Ï¿É¹ÛµÄʱ¼ä
===============================
ÒÔÏÂÊǸ÷ÅÔÚÔÚÓÎζÖеÄÓ¦Óãº
function mail_list_sent($uid, $start)
{
// ×¢ÒâSQL_CALC_FOUND_ROWS uidÖ®¼äûÓжººÅ
$query = "SELECT SQL_CALC_FOUND_ROWS uid, real_name, current_city, msg_uid, sender_flag, msg_title, msg_content from ".TT_DBTABLEPRE."mailbox as mb1, ".TT_DBTABLEPRE."user as usr1 WHERE mb1.sender_id=usr1.uid AND mb1.sender_id=$uid AND sender_flag > 0 LIMIT $start, ".TT_PAGESIZE;
$mails = $this->db->fetch_all($query);
//²éѯSELECTÖÐÂú×ãÌõ¼þµÄÐÐÊý£¬ÓëLIMIT×Ó¾äÎÞ¹Ø
$max_count = $this->db->fetch_first("SELECT found_rows() AS rowcount");
$tmp['state_code'] = 200;
$tmp['info'] = "OK";
$tmp['list'] = $mails;
$data = json_encode($tmp);
return $data;
}
¸Ðл×÷Õß·ÖÏí£¡
Ïà¹ØÎĵµ£º
1¡¢´ò¿ªMyEclipse6.6
2¡¢Ñ¡Ôñ²Ëµ¥£ºWindow/Open Perspective/MyEclipse Database Explorer£¬µã»÷OK£¬ÔÚ×ó±ß´ò¿ªDB Brower´°¿Ú¡£
3¡¢ÔÚDB Brower´°¿ÚÄÚÈÎÒâ¿Õ°×´¦»÷ÓÒ¼ü£¬Ñ¡ÔñNewÃüÁµ¯³öDatabase Driver´°¿Ú
4¡¢±¾´°¿Ú¸÷Ïî˵Ã÷£º
Driver template: MySQL Connector/J Ñ¡ÔñÇý¶¯Ä£°å
& ......
mysql> create table testdate(
-> id int not null auto_increment primary key,
-> time date);
Query OK, 0 rows affected (0.30 sec)
mysql> insert into testdate(time) values('2010-4-23');
Q ......
1¡¢MySQL³£ÓÃÃüÁî
create database name; ´´½¨Êý¾Ý¿â
use databasename; Ñ¡ÔñÊý¾Ý¿â
drop database name Ö±½Óɾ³ýÊý¾Ý¿â£¬²»ÌáÐÑ
show tables; ÏÔʾ±í
describe tablename; ±íµÄÏêϸÃèÊö
select ÖмÓÉÏdistinctÈ¥³ýÖظ´×Ö¶Î
......
http://immike.net/blog/2007/04/09/how-not-to-optimize-a-mysql-query/
ÕâƪÎÄÕ½¨Ò飺
£¨1£©²»ÒªÊ¹ÓÃһЩmysqlµÄtip£¬È磺SQL_SMALL_RESULT, HIGH/LOW_PRIORITY, and INSERT DELAYED£¬STRAIGHT_JOIN£¬³ý·ÇûÓÐÆäËû·½·¨£¬ÒòΪÕâÑùʧȥÁËSQLµÄ¿ÉÒÆÖ²ÐÔ
£¨2£©Êʵ±¶Ô±í½øÐÐË÷Òý
£¨3£©±ÜÃâ¶Ô²»±ØÒªÊý¾ÝµÄ²éѯ
£¨4£©´¦Àí× ......