Pages: 13/46 First page Previous page 8 9 10 11 12 13 14 15 16 17 Next page Final page [ View by Articles | List ]
     下面是最常用的Mysql内置函数,今天记录下来,方便日后查阅

mysql索引优化之Using filesort

[不指定 2009/02/24 18:54 | by askwan ]
      用Explain分析SQL语句的时候,经常发现有的语句在Extra列会出现Using filesort,根据mysql官方文档对他的描述:
Quotation
MySQL must do an extra pass to find out how to retrieve the rows in sorted order. The sort is done by going through all rows according to the join type and storing the sort key and pointer to the row for all rows that match the WHERE clause.

中文手册上翻译的很别扭:
Quotation
“Mysql需要额外的一次传递,以找出如何按排序顺序检索行,通过根据联接类型浏览所有行并为所有匹配where子句的行保存排序关键字和行的指针来完成排序,然后关键字被排序,并按排序顺序检索行。”


总的来说,Using filesort 是Mysql里一种速度比较慢的外部排序,如果能避免是最好的了,很多时候,我们可以通过优化索引来尽量避免出现Using filesort,从而提高速度。

这里举个简单的例子:

CREATE TABLE `testing` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `room_number` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `room_number` (`room_number`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8


写个存储过程askwan,插入10万条测试数据

Memcached的Php测试实现

[不指定 2009/02/20 15:40 | by askwan ]
      关于Memcached的原理,安装,配置等这里就省了,一搜一堆,今天我写了个PHP简单脚本做了个Memcached缓存数据库查询结果的测试。

测试的数据,我这有现成的,PW论坛数据库的pw_members表,取最后注册的十条数据:
mysql> select uid,username,password,gender from pw_members order by uid desc limit 10;  
+--------+-----------+----------------------------------+--------+
| uid    | username  | password                         | gender |
+--------+-----------+----------------------------------+--------+
| 751490 | a62986233 | 8d03f56ad2c48d494cd4b73b3ba64dca |      0 |
| 751489 | hldhoxbh  | 25d55ad283aa400af464c76d713c07ad |      0 |
| 751488 | wuhan0088 | ba2206cbae7c1bfe33a54ff161943bab |      0 |
| 751487 | anrron    | b206e95a4384298962649e58dc7b39d4 |      0 |
| 751486 | hldjxlkx  | 9c98df872d24244696c393a1d26ab749 |      0 |
| 751485 | 1394afjh  | 25d55ad283aa400af464c76d713c07ad |      0 |
| 751484 | yesi808   | 32baeaa3c422413843b015919c0be999 |      0 |
| 751483 | IDC010pw  | 25f9e794323b453885f5181f1b624d0b |      0 |
| 751482 | ebay360v  | a36b9e764318d31b4810d7d18096e6e7 |      0 |
| 751481 | ppgqsvgv  | 9c98df872d24244696c393a1d26ab749 |      0 |
+--------+-----------+----------------------------------+--------+
10 rows in set (0.00 sec)


脚本代码





第一次读取数据是直接从Mysql数据库中取数据:如:

Open in new window

以后访问就直接从Memcached Server中取数据了:

Open in new window

测试的目的达到,有时间再对Memcached的分布式功能测试一番。

-------------END-------------
Tags: , ,

google-perftools的TCMalloc

[不指定 2009/02/19 10:31 | by askwan ]
       我这两天在一台DB上的实际应用测试,发现和不使用之前负载降低30%左右,可以理解为性能提高了30%!TCMalloc号称最快的Malloc,果然不虚,以前出来这个东西的时候,没实际测试,今天真实体验了一把。效果还是不错的。

     因为开始不知道对于64位的系统,要先安装libunwind库,折腾了不少时间,给提个醒。
最新版本是1.0了

下载:
http://google-perftools.googlecode.com/files/google-perftools-1.0.tar.gz

项目主页:
http://code.google.com/p/google-perftools/

相关文章:
http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html
Pages: 13/46 First page Previous page 8 9 10 11 12 13 14 15 16 17 Next page Final page [ View by Articles | List ]