免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1139 | 回复: 0
打印 上一主题 下一主题

mysql 单表全文搜索测试 [复制链接]

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-12 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-11-18 11:50 |只看该作者 |倒序浏览
本帖最后由 yakczh_cu 于 2013-11-18 11:51 编辑

测试环境
Intel(R) Core(TM) i3-3210 CPU @ 3.20GHz
DDR3 mem 4g
ST500DM002-1BD142  500g
xp sp3
mysqld 5.6.13

建表
  1.   CREATE TABLE `test1` (
  2.   `id` bigint(20) NOT NULL AUTO_INCREMENT,
  3.   `subject` varchar(200) NOT NULL,
  4.   `content` text NOT NULL,
  5.   `ctime` int(10) NOT NULL,
  6.   PRIMARY KEY (`id`)
  7. ) ENGINE=MyISAM  DEFAULT CHARSET=utf8
复制代码
生成100w测试数据
  1. <?php
  2.    $id=1;
  3.    $flag=1;

  4.   $db=mysqli_connect("localhost:3306",'root','','bench');

  5.   

  6. while( $id <  100 * 10000  ){  
  7.      $rand=rand(10000,99999);

  8.    $now=time();
  9.     $sql = "insert into  test1  (id,subject,content,ctime) values($id,'测试标题_$rand','测试内容_$rand',$now);";  

  10.         if($flag){
  11.         mysqli_query($db,'set names utf8');
  12.         $flag=0;
  13.     }
  14.                 //echo $sql;
  15.    mysqli_query($db,$sql);
  16.     $id++;
  17.    }

  18.    
  19.    mysqli_close($db);
复制代码
用like 查询
  1. <?php



  2. $start=microtime(true);

  3.   $db=mysqli_connect("localhost:3306",'root','','bench');


  4.   mysqli_query($db,'SET NAMES UTF8');
  5. $rand=rand(10000,99999);

  6. $sql="SELECT * from test1 where subject like '%$rand';";

  7. echo $sql;

  8. if ($result = mysqli_query($db,$sql)) {
  9.     printf("Select returned %d rows.\n", $result->num_rows);

  10.      //print_r($result);
  11.      while($row=  mysqli_fetch_array($result)){

  12.              print_r($row['content']);
  13.      }
  14.     /* free result set */
  15.     $result->close();
  16. }

  17. echo "\n elapse ";
  18. echo microtime(true)-$start;
复制代码
测试结果
在200万条数据以内,查询时间在1s以内

然后以200w以步长增加数据,查询时间基本上是线性增长

200w 1.03s

400w 2.34s

600w 3.25s

800w 4.02s

1000w 4.76s

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP