oracle 效能最佳化操作十二: 用Case語句合并多重掃描,oraclecase

來源:互聯網
上載者:User

oracle 效能最佳化操作十二: 用Case語句合并多重掃描,oraclecase

我們常常必須基於多組資料表計算不同的聚集。例如下例通過三個獨立查詢:

select count(*) from emp where sal<1000;select count(*) from emp where sal between 1000 and 5000;select count(*) from emp where sal>5000;

這樣我們需要進行三次全表查詢,但是如果我們使用case語句:

select count (sale when sal <1000then 1 else null end)              count_poor,count (sale when between 1000 and 5000then 1 else null end)              count_blue_collar,count (sale when sal >5000then 1 else null end)              count_poorfrom emp;

這樣查詢的結果一樣,但是執行計畫只進行了一次全表查詢。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.