为什么这两个语句的cpu cost相差10倍呢??
select col1 from a where col2 = 1 order by col1;select * from (select col1 from a where col2=1) order by col1;--这个执行计划明显的小些。。
select col1 from a where col2 = 1 order by col1;select * from (select col1 from a where col2=1) order by col1;--这个执行计划明显的小些。。
select col1 from a where col2 = 1 order by col1;
select * from (select col1 from a where col2=1) order by col1;--这个执行计划明显的小些。。
这个问题要从全局考虑。
显然你得出的结论要从你的当前环境以及测试数据量上做分析。个人觉得什么情况对应用什么写法这才是最优,而不是单纯的看语句怎么写。如果那样SQL就显得太死板了。