explain 
select t.Id,c.role  from
(select distinct t1.Id, t1.ip, t1.lastaccess,
from SessionLog t1, SessionLog t2
where  
and t1.ip=t2.ip
and t1.id != t2.id) as t, 
role c 
where 
 t.Id=c.id请这条语句到底有什么问题, 得不到执行计划
在linux 写着(copy to tmp)

解决方案 »

  1.   

    explain 
    select t.Id,c.role  from
    (select distinct t1.Id, t1.ip, t1.lastaccess,
    from SessionLog t1, SessionLog t2
    where  
    and t1.ip=t2.ip
    and t1.id != t2.id) as t, 
    role c 
    where 
     t.Id=c.id
    语法错误。
    
      

  2.   

    explain 
    select t.Id,c.role  from 
    (select distinct t1.Id, t1.ip, t1.lastaccess, 
    from SessionLog t1, SessionLog t2 
    where  t1.ip=t2.ip 
    and t1.id != t2.id) as t, 
    role c 
    where 
    t.Id=c.id 我去掉了好多内容, 这些东西是不能直接拿出来的哦   总体就是这样的哦
      

  3.   

    依旧是括号不匹配。explain 
    select t.Id,c.role  from 
    (select distinct t1.Id, t1.ip, t1.lastaccess, 
    from SessionLog t1, SessionLog t2 
    where  t1.ip=t2.ip 
    and t1.id != t2.id) as t, 
    role c 
    where 
    t.Id=c.id 
      

  4.   

    select t.Id,c.role  from 
    (select distinct t1.Id, t1.ip, t1.lastaccess, from SessionLog t1, SessionLog t2 where  
    t1.ip=t2.ip and t1.id != t2.id) as t, role c 
    where 
    t.Id=c.id 没有啦, 请看  那是一个查询 表 ,  是对称的哦
      

  5.   

    select t.Id,c.role  from 
    (select distinct t1.Id, t1.ip, t1.lastaccess, from SessionLog t1, SessionLog t2 where  
    t1.ip=t2.ip and t1.id != t2.id) as t, role c 
    where 
    t.Id=c.id 
      

  6.   

    多了个逗号,建议你给个可执行的SQL语句,先自己测试一下再贴出来!select t.Id,c.role  from 
    (select distinct t1.Id, t1.ip, t1.lastaccessfrom SessionLog t1, SessionLog t2 where  
    t1.ip=t2.ip and t1.id != t2.id) as t, role c 
    where 
    t.Id=c.id 
      

  7.   

    不是语法问题的哦 select t.Id,c.role  from 
    (select distinct t1.Id, t1.ip, t1.lastaccess from SessionLog t1, SessionLog t2 where  
    t1.ip=t2.ip and t1.id != t2.id) as t, role c 
    where 
    t.Id=c.id 重新编译 还是不知道真么回事,处于等待中
      

  8.   

    反复测试  发现原因 在于
    (select distinct t1.Id, t1.ip, t1.lastaccess from SessionLog t1, SessionLog t2 where  
    t1.ip=t2.ip and t1.id != t2.id) as t
    特别是这个distinct  导致执行计划基本失败 他不能找到对应的计划 只会 (copy to tmp table)
    楼上,这是根本原因
      

  9.   

    从以前的帖子发现mysql对 distinct支持很差  ,用到这个基本不走索引
    甚至强加索引 也大大慢于group 语句 
      

  10.   

    贴出你的create table SessionLog / role 的语句,这样,我可以测试一下,看结果是否与你一致。你的
    explain 
    select t.Id,c.role  
    from (
    select distinct t1.Id, t1.ip, t1.lastaccess 
    from SessionLog t1, SessionLog t2 
    where t1.ip=t2.ip 
    and t1.id != t2.id
    ) as t, role c 
    where t.Id=c.id 显示结果是什么?
      

  11.   

    没有  等待中  , 在linux 用命令看 (copy to tmp table)
    无休止等待
      

  12.   

    唉,让你提供一下你的建表语句你又不肯。这样,我也没办法来模拟你的问题。自己检查一下lock的情况吧。SHOW PROCESSLIST ;回你这个贴子太费时间了。猜来猜去的。