select username 
  from (select distinct substr(c.circuitname, 
                               0, 
                               (instr(c.circuitname, '_', 1, 1)) - 1) username 
          from node n, userinfo u, device d, portinfo p, circuit c 
         where u.netuserid = 'admin' 
           and n.nodefullcode like '%' || u.nodecode || '%' 
           and d.nodecode = n.nodecode 
           and d.changetype = 0 
           and c.changetype = 0 
           and p.deviceid = d.deviceid 
           and ((c.adeviceid = d.deviceid and c.aintdescr = p.portdescr) or 
               (c.bdeviceid = d.deviceid and c.bintdescr = p.portdescr))) 
where username is not null//加了这句后比不加慢了几十倍,请教各位高手,谢谢 

解决方案 »

  1.   

    username is not null 不走索引
      

  2.   

    nvl(username,'')='' //这个也是不走索引的吧。好像没什么好方法。
      

  3.   

    有什么方法吗?我现在想着放到java里循环判断得了
      

  4.   

    username是个字符串类型的吧 
    先把所有为空的数据刷成‘0’
    然后加上where username > '0'
    这样就可以临时处理了后期的话,在check里给这个username附一个默认值,保证非空就可以了
      

  5.   

    条件加在子查询里 c.circuitname is not null 试试呢?
      

  6.   

    我感觉应该是判断是否为null这个步骤的消耗比较大
      

  7.   

    null是不走索引的,总和考虑下,是否有必要建立个函数索引,这样null也能走索引。
      

  8.   

    from node n, userinfo u, device d, portinfo p, circuit c 你怎么可以一个from中出现多个表那,这样速度很慢的
    要两个两个的拼接,,这样效率应该可以提高很多
      

  9.   

     我看了之后呢 觉得 是 有 两个原因 引起的 1.是 你 select 子连接 查询 而且 有用了 好多个 wher 条件 效率  本来就很低 ,你现在有 增加 了 条件 is not null  他们 这个 语句是有 执行顺序的 ,而且 这个 语句 本来 的 效率 也是 比较低的 ,他从数据库 中 取一个 比一个 肯定是 慢了。
      

  10.   

    请把增加where条件和不加where条件的2中sql 执行计划贴出来看看?
      

  11.   

    username  = decode(username,null,-1,username)