免费注册 查看新帖 |

Chinaunix

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

对于MYSQL,提高查询性能的办法有哪些? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-07 21:36 |只看该作者 |倒序浏览
请各位MYSQL支招,分享一下你们使用过的提高查询性能的办法。

论坛徽章:
0
2 [报告]
发表于 2008-10-08 08:20 |只看该作者
优化语句:   
   
  测试过程:   
   
  环境:   
  PIII900   128M   
  win2000+sql   server2000企业版   
  table   name   :t_data   
  CLUSTERED   PRIMARY   KEY     :id   
  Rows:441000   
   
  语句1:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   60000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:390ms   
   
  语句2:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   100000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:4s   
   
  语句3:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   150000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:5s   
   
  语句4:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   200000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:6s   
   
  语句5:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   250000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:过了15m没有出来,中断   
   
  语句6:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   300000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:过了20m没有出来,中断   
   
  语句7:   
  select   top   60000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:20s   
   
  语句8:   
  select   top   100000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:21s   
   
  语句9:   
  select   top   150000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:23s   
   
  语句10:   
  select   top   200000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:24s   
   
  语句11:   
  select   top   250000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:26s   
   
  语句12:   
  select   top   300000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:28s   
   
  语句13:   
  select   top   400000   id     into   #a   from   t_data   order   by   id   asc   
   
  create   index   ind_a_base_id   on   #a(id)      
   
  select   *   from   t_data   where     
  id   in   (select   top   10   id     from   #a   order   by   id   desc)   
  order   by   id   asc   
   
  时间:29s   
   
  语句14:   
  select   *   from   t_data   where     
  id   in   
  (select   top   10   id     from   t_data   where   id   in   
  (select   top   250000   id     from   t_data   order   by   id   asc)   
  order   by   id   desc)   
  order   by   id   asc   
   
  时间:过了25m没有出来,还没有中断
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP