oracle 效能最佳化操作十一: like子句盡量前端匹配,oracle子句

來源:互聯網
上載者:User

oracle 效能最佳化操作十一: like子句盡量前端匹配,oracle子句

因為like參數使用的非常頻繁,因此如果能夠對like子句使用索引,將很高的提高查詢的效率。

例:

select * from city where name like ‘%S%’;

以上查詢的執行計畫用了全表掃描(TABLE ACCESS FULL),如果能夠修改為:

select * from city where name like ‘S%’;

那麼查詢的執行計畫將會變成(INDEX RANGE SCAN),成功的利用了name欄位的索引。

這意味著Oracle SQL最佳化器會識別出用於索引的like子句,只要該查詢的匹配端是具體值。

因此我們在做like查詢時,應該盡量使查詢的匹配端是具體值,即使用like ‘S%’。

相關文章

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.