如表: id 商品类型 商品属性 属性内容 商品店ID,排序ID
  id typeid attr content  shopid,orderid
  1 2 颜色 联想 Y470 ITH   1,99
  2 2 长度 联想 Y470 -ITH  1,100
....
  300 1 宽度 联想 G460       2,99
  301 3 长度 联想 E40        2,100
...
  500 3 颜色 联想 Y470(ITH)  3,99
  501 1 颜色 DELL Y470(ITH)  3,100
...  
 我的网站的表,如上所示,商品类型1,2,3,4..分另表示电脑,家电,商品店ID分另表示不同的商家,排序ID也是从99-1000之间,记录中可能都有重复的字段,一共数据可达500W以上条,现在是网站一开,就说占MYSQL100%,大家有好的处理方法没,加个索引,听说能提高效率

解决方案 »

  1.   

    1.我经常会查找那个content一般用like通配,(where)
    2.排序用goruby shopid,orderid
    3.子版快是用type来区分的
    所以是加三个索引,还是加在那个索引最合适,谢谢高手
      

  2.   

    索引优化,是针对特定查询实现的如果你的语句是  where content like '%xxxx%' 则无法优化。
    建议你给你的SQL语句,然后再进行分析讨论。
      

  3.   

    1.我经常会查找那个content一般用like通配,(where)
    SQL语句是什么,如果是%内容%,无法用到索引2.排序用goruby shopid,orderid
    在这3个字段上建立索引3.子版快是用type来区分的你的SQL语句是什么,EXPLAIN SQL语句
      

  4.   

    应该问“你使用频率最大的SQL语句是什么?,你能不能确定哪些SQL语句需要优化?”因为你网站已运行,表设计级的优化已经不可行。因此只能针对SQL语句做个别的优化。
      

  5.   

    主页页面常用:select dg_shoplist.shopname ,dg_gwsosoitems.* from dg_gwsosoitems,dg_shoplist  where dg_gwsosoitems.shopid = dg_shoplist.id and dg_gwsosoitems.nzk < 90 and dg_gwsosoitems.itemtype = 2 and dg_gwsosoitems.newprice < 999900 and dg_gwsosoitems.shopid > $SqlGetShopid group by dg_gwsosoitems.shopid LIMIT 6,20搜索页面常用:select dg_shoplist.id,dg_shoplist.shopname ,dg_shoplist.comenttime ,dg_gwsosoitems.* from dg_gwsosoitems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id and buytext LIKE '%".$keyword."%' order by dg_gwsosoitems.ngroupid ,dg_gwsosoitems.shopid ASC  LIMIT $n_page, $page_size分类菜单常用:select dg_shoplist.shopname,dg_gwsosoitems.shopid  from dg_gwsosoitems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id and dg_gwsosoitems.shopid =  $shopid group by dg_gwsosoitems.shopid  LIMIT 39发上两个表dg_gwsosoitems跟最上面所示结构差不多,也是商店ID,评论时间,物品价格,物品URL,物品详细(查找关键字的字段),图片URL,还有什么折扣,排序(ngroupid)之类的shoplist的主键ID对应dg_gwsosoitems的shopid(不是主键)itemtype是分类,当然还要子分类
    ,谢谢楼上两位兄弟的建议
      

  6.   

    dg_shoplist只对诮1500个商家记录,dg_gwsosoitems的数据则大300W以上,优化主要对应这个表
      

  7.   

    其实我的SQL是可以改,可问题是我不知道从何下手,呵呵,以前搞编程应用程序界面的多,数据库这快比较少接触
      

  8.   

    TO:jiahehao
    网站已运行,表设计级的优化已经不可行?这个我可以改的,因为现在用户访问量不是很多,而且我的数据我本机可以传一到两天,我的主页也是两天更新一次,这个不是问题,表设计我想是优先考虑,比如弄个索引,要不建表优化,这快有什么建议,欢迎告知,谢谢
      

  9.   

    EXPLAIN SQL?我装的是PHPNOW,开发环境,没有MYSQL命令行,可能我不知道在那,呵呵,在PHP里可以查看的出结果不,我查查,说不定是好方法,我试一下
      

  10.   

    TO,楼上,那怎么优化了,就是这点我不太懂啊,表优化,我查了,好像说是对索引优化能大改善,,那我现在主要是优化,那group用到的字段,还是where中用到的字段,这些改进,还有其它法子不,高手大侠请指教啊
      

  11.   

    那我现在主要是优化,那group用到的字段,还是where中用到的字段寻建立复合索引,再用EXPLAIN SQL语句,看看结果
      

  12.   

    显然这个查询中用到了两张表,和你在一开始说明的表已经不相同的。建议提问时尽可能描述清楚。针对这个查询创建如下索引。
    create index xxx1 on dg_gwsosoitems(shopid,itemtype,nzk);
    create index xxx2 on dg_gwsosoitems(shopid,itemtype,newprice);
      

  13.   


    create index xxx3 on dg_gwsosoitems(ngroupid,shopid)
      

  14.   

    谢谢楼上的ACMNIN高手和WWWA和所有回复的大侠,我在PHPNOW下用了,显示如下
    39 rows in set (9.86 sec)mysql> EXPLAIN select dg_shoplist.shopname,dg_gwsosoitems.shopid from dg_gwsosoi
    tems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id group by dg_gwsos
    oitems.shopid LIMIT 39;
    +----+-------------+----------------+--------+---------------+---------+--------
    -+----------------------------------+--------+---------------------------------+| id | select_type | table          | type   | possible_keys | key     | key_len
     | ref                              | rows   | Extra                           |+----+-------------+----------------+--------+---------------+---------+--------
    -+----------------------------------+--------+---------------------------------+|  1 | SIMPLE      | dg_gwsosoitems | ALL    | NULL          | NULL    | NULL
     | NULL                             | 539008 | Using temporary; Using filesort ||  1 | SIMPLE      | dg_shoplist    | eq_ref | PRIMARY       | PRIMARY | 4
     | sq_ing9988.dg_gwsosoitems.shopid |      1 |                                 |+----+-------------+----------------+--------+---------------+---------+--------
    -+----------------------------------+--------+---------------------------------+2 rows in set (0.17 sec)
      

  15.   

    create index xxx3 on dg_gwsosoitems(ngroupid,shopid)
    xxx3(这个什么意思啊)我真是一步一步都要问,没法子啊,希望大家不要嫌我烦啊,自己的网站,只能用心做了不会我就要向大家学习了
      

  16.   

    不用管它什么意思,直接执行就行了。
    如果有兴趣学习,则可以查看MYSQL手册中的CREATE INDEX语法说明。  MYSQL手册可以从官网下载,是免费的。
      

  17.   

    上面的好长,不过很有帮助,我收集下慢慢看
    EXPLAIN select dg_shoplist.shopname,dg_gwsosoitems.shopid from dg_gwsosoitems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id group by dg_gwsosoitems.shopid,dg_gwsosoitems.ngroupid LIMIT 39;
    执行时间8.7秒EXPLAIN select dg_shoplist.shopname,dg_gwsosoitems.shopid from dg_gwsosoitems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id group by dg_gwsosoitems.shopid LIMIT 39;(dg_gwsosoitems.ngroupid)执行时间22秒
    我是不是没有成功建索引啊
    alert table dg_gwsosoitems add INDEX `sosoindex1` ('ngroupid','shopid') ;
    alert table dg_gwsosoitems add INDEX `sosoindex2` ('shopid','itemtype','newprice') ;
    alert table dg_gwsosoitems add INDEX `sosoindex3` ('shopid','itemtype','nzk') ;
      

  18.   

    alert table dg_gwsosoitems add INDEX `sosoindex1` ('ngroupid','shopid') ;
    alert table dg_gwsosoitems add INDEX `sosoindex1` (ngroupid,shopid) ;
    两个都不成功啊原来要create index sosoindex1 on dg_gwsosoitems(ngroupid,shopid);的才行啊,看来哥还嫩了点,谢谢ACMAIN_CHM大侠啊
      

  19.   

    怎么回事,建了索引,发觉一个速度快了好多,另一个却变慢了?
    select dg_shoplist.shopname,dg_gwsosoitems.shopid from dg_gwsosoitems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id group by dg_gwsosoitems.shopid LIMIT 39;
    只要1sec不到
    select dg_shoplist.shopname,dg_gwsosoitems.shopid from dg_gwsosoitems ,dg_shoplist where dg_gwsosoitems.shopid = dg_shoplist.id group by dg_gwsosoitems.shopid , dg_gwsosoitems.ngroupid LIMIT 39;却多花了时间