情况这样2张表A表 10W+的数据 24个字段, 需要用到 url area 这2个字段  这2个都加了索引B表  40W+的数据 4个字段, 需要用到 url name 这2个字段  都加索引B表的 name 有43种  随机分摊到每个URL,每个name对应的url的数量有数千到2W不等,并且存在重复的可能,所以还需要祛重
假设abc这个name对应100个URL的量,但实际祛重后只有50条urlselect a.area,count(distinct a.url) from tableA a ,tableB bwhere  a.url=b.urland b.name="adasd"group by a.areaorder by count(distinct a.url) desc目的是循环B表的name  把43个name 都按这个SQL算一遍
现在的情况是 SQL运行速度狂慢  1个小时只能跑2个name的计算求高速的.............

解决方案 »

  1.   

    show index from a;看一下,然后贴一下你的explain 结果是什么?跨两表的优化比较复杂
      

  2.   

    index 都是通过工具加的 没问题的应该结果贴不了  下面是抄的
    1 、simole 、b 、ref 、B表url,B表name 、B表name 、768 、const 、32184 、using where;using temporary 、using filesort
    1 、simole 、a 、ref 、A表url,A表area 、A表url 、768 、裤.b.url 、1 、using where
      

  3.   

    一般来说,
    需要以下索引
    B表复合索引(name,url)
    A表复合索引(url,area)
      

  4.   

    试试这样效率是否高点:
    select A.area, count(B.url) from A, (select distinct url from B where name='adasd') as B group by A.area order by B.url desc