深入理解Oracle索引(15):日期轉換函式的格式參數大小寫規則對函數索引的影響

來源:互聯網
上載者:User

     規則如下:

                      

     依據這個規則、只有 3 種輸出:大寫、小寫、首字母大寫
     
     測試如下:

sys@ORCL> select to_char(sysdate,'Month') from dual;TO_CHAR(SYSDATE,'MONTH')------------------------------------Junesys@ORCL> select to_char(sysdate,'MOnth') from dual;TO_CHAR(SYSDATE,'MONTH')------------------------------------JUNEsys@ORCL> select to_char(sysdate,'month') from dual;TO_CHAR(SYSDATE,'MONTH')------------------------------------june

     下面做個測試、確認這個規則對函數索引的影響:

sys@ORCL> drop table t purge;Table dropped.sys@ORCL> create table t as select object_id,sysdate+rownum as create_date from dba_objects where rownum<=5000;Table created.sys@ORCL> analyze table t compute statistics;Table analyzed.sys@ORCL> set autot trace expsys@ORCL> select * from t where to_char(create_date,'yyyy-mm-dd')='2011-06-02';Execution Plan----------------------------------------------------------Plan hash value: 1601196873--------------------------------------------------------------------------| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |--------------------------------------------------------------------------|   0 | SELECT STATEMENT  |      |    50 |   500 |     5  (20)| 00:00:01 ||*  1 |  TABLE ACCESS FULL| T    |    50 |   500 |     5  (20)| 00:00:01 |--------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   1 - filter(TO_CHAR(INTERNAL_FUNCTION("CREATE_DATE"),'yyyy-mm-dd')='20              11-06-02')sys@ORCL> create index idx_t on t (to_char(create_date,'YYYY-MM-DD'));Index created.sys@ORCL> analyze index idx_t validate structure;Index analyzed.sys@ORCL> select * from t where to_char(create_date,'yyyy-mm-dd')='2013-06-02';Execution Plan----------------------------------------------------------Plan hash value: 1601196873--------------------------------------------------------------------------| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |--------------------------------------------------------------------------|   0 | SELECT STATEMENT  |      |    50 |   500 |     5  (20)| 00:00:01 ||*  1 |  TABLE ACCESS FULL| T    |    50 |   500 |     5  (20)| 00:00:01 |--------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   1 - filter(TO_CHAR(INTERNAL_FUNCTION("CREATE_DATE"),'yyyy-mm-dd')='20              13-06-02')sys@ORCL> set autot offsys@ORCL> create index idx_t_001 on t (to_char(create_date,'yyyy-mm-dd'));Index created.sys@ORCL> analyze index idx_t_001 validate structure;Index analyzed.sys@ORCL> select * from t where to_char(create_date,'yyyy-mm-dd')='2013-06-02';no rows selectedsys@ORCL> set autot trace exp第一種情況:小寫sys@ORCL> select * from t where to_char(create_date,'yyyy-mm-dd')='2013-06-02';Execution Plan----------------------------------------------------------Plan hash value: 512271049-----------------------------------------------------------------------------------------| Id  | Operation                   | Name      | Rows  | Bytes | Cost (%CPU)| Time     |-----------------------------------------------------------------------------------------|   0 | SELECT STATEMENT            |           |    50 |   500 |     2   (0)| 00:00:01 ||   1 |  TABLE ACCESS BY INDEX ROWID| T         |    50 |   500 |     2   (0)| 00:00:01 ||*  2 |   INDEX RANGE SCAN          | IDX_T_001 |    20 |       |     1   (0)| 00:00:01 |-----------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   2 - access(TO_CHAR(INTERNAL_FUNCTION("CREATE_DATE"),'yyyy-mm-dd')='2013-06-02'              )第二種情況:首字母大寫sys@ORCL> select * from t where to_char(create_date,'yyyy-mm-Dd')='2013-06-02';Execution Plan----------------------------------------------------------Plan hash value: 1601196873--------------------------------------------------------------------------| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |--------------------------------------------------------------------------|   0 | SELECT STATEMENT  |      |    50 |   500 |     5  (20)| 00:00:01 ||*  1 |  TABLE ACCESS FULL| T    |    50 |   500 |     5  (20)| 00:00:01 |--------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   1 - filter(TO_CHAR(INTERNAL_FUNCTION("CREATE_DATE"),'yyyy-mm-Dd')='20              13-06-02')第三種情況:大寫sys@ORCL> select * from t where to_char(create_date,'yyyy-mm-DD')='2013-06-02';Execution Plan----------------------------------------------------------Plan hash value: 1601196873--------------------------------------------------------------------------| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |--------------------------------------------------------------------------|   0 | SELECT STATEMENT  |      |    50 |   500 |     5  (20)| 00:00:01 ||*  1 |  TABLE ACCESS FULL| T    |    50 |   500 |     5  (20)| 00:00:01 |--------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   1 - filter(TO_CHAR(INTERNAL_FUNCTION("CREATE_DATE"),'yyyy-mm-DD')='20              13-06-02')

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.