本案例参考《SQL优化核心思想》(罗炳森,黄超,钟侥著)。
有听说这是某大公司的面试题,大家有什么更好的建议,欢迎留言评论。谢谢。
8.2.1 构造数据环境
drop table test1;
create table test1 as select * from dba_objects;
create index ix_test1_01 on test1(object_id);
8.2.2 问题SQL
select min(t1.object_id),max(t1.object_id) from test1 t1;
8.2.3 优化改写
select min(id) as min_id,max(id) as max_id from
(select min(t1.object_id) as id from test1 t1
union all
select max(t1.object_id) from test1 t1);