select art.article_id,art.article_title,aps.adminaccount from article art,powerscope aps where aps.adminaccount='zhangsan' and aps.funcnodepath in('A001')  and art.column_id=aps.scopestr其中我分别将条件赋值给
aps.adminaccount='张三',符合此记录的大约1000条
aps.adminaccount='李四',符合此记录的大约100条但为什么当条件是“李四”的时候执行的速度要比条件是"张三"的时候慢的多。
难道这个和数据在表中的分布有关系?

解决方案 »

  1.   

    你把别的条件都去掉,只留aps.adminaccount='张三'看看
      

  2.   

    select art.article_id,art.article_title,aps.adminaccount from article art,powerscope aps where aps.adminaccount='zhangsan' and aps.funcnodepath in('A001')  and art.column_id=aps.scopestr 这个语句的效率比较差。
    你这个只是简单的一个sql句。光从sql句的角度来看我觉得主要注意两点:
    1)表的顺序。ORACLE采用自右向左的顺序解析FROM表。FROM子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表
    2)条件的顺序。ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,
       表之间的连接必须写在其他WHERE条件之前, 那些可以过滤掉最大数量记录的条件必须写在WHERE子句的末尾。
    select art.article_id,art.article_title,aps.adminaccount from article art,powerscope aps where art.column_id=aps.scopestr and aps.funcnodepath='A001' and aps.adminaccount='zhangsan' 数据多的话,效率应该能提高一些。
      

  3.   

    这个观点在早期版本的Oracle确实存在,
    Oracle 10g中一般是会有差异的,Oracle最重要的工作就是
    确定表的顺序,Oracle会用用原来的统计信息,做出合理的执行计划。
    所以,我想,执行顺序存在问题的可能性不大。
    除非你特意使用leading改变它。不太赞同。
      

  4.   

    把别的条件都去掉,只留aps.adminaccount='张三'还是一样的
      

  5.   

    可能是这样,当条件是张三时,aps返回的纪录大于art标的,不过可以改成这样 
    select art.article_id,art.article_title,aps.adminaccount 
    from   article art,powerscope aps 
    where  art.column_id=aps.scopestr 
    and    aps.funcnodepath ='A001'
    and    aps.adminaccount='zhangsan'