日期:2014-05-16  浏览次数:20981 次

请教两个SQL语句不同Cost的原因
本帖最后由 sky88088 于 2013-11-21 16:04:34 编辑
有两个效果一样的SQL语句,产生的执行计划的cost不同,我想问问为什么会有这样的差别,原理是什么?
有两个表
table_A:
name1
name2

table_B:
name,有索引table_B_idx

第一段语句
select * from table_A a
where exists (select null from table_B where a.name1=b.name or a.name2=b.name);

执行计划为
Description                            Object name                            Cost
select statement                                                                  900822
    filter                                                  
        table accesses full                 table_A                              1993
        inlist iterator
            index range scan               table_B_idx                         1



第二段语句
select * from table_A a
where a.name1 in (select name from table_B) or  a.name2 in (select name from table_B);

执行计划为
Description                            Object name                 Cost
select statement                                                        1994
    filter                                                  
        table accesses full              table_A