深入理解Oracle索引(15):日期转换函数的格式参数大小写规则对函数索引的影响
2013-06-02 21:11
519 查看
规则如下:
依据这个规则、只有 3 种输出:大写、小写、首字母大写
测试如下:
sys@ORCL> select to_char(sysdate,'Month') from dual;
TO_CHAR(SYSDATE,'MONTH')
------------------------------------
June
sys@ORCL> select to_char(sysdate,'MOnth') from dual;
TO_CHAR(SYSDATE,'MONTH')
------------------------------------
JUNE
sys@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 exp
sys@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 off
sys@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 selected
sys@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')
依据这个规则、只有 3 种输出:大写、小写、首字母大写
测试如下:
sys@ORCL> select to_char(sysdate,'Month') from dual;
TO_CHAR(SYSDATE,'MONTH')
------------------------------------
June
sys@ORCL> select to_char(sysdate,'MOnth') from dual;
TO_CHAR(SYSDATE,'MONTH')
------------------------------------
JUNE
sys@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 exp
sys@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 off
sys@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 selected
sys@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')
相关文章推荐
- Oracle日期转换函数的格式参数大小写规则【转自ITPUB】
- Oracle日期转换函数的格式参数大小写规则【转自ITPUB】
- 深入理解Oracle索引(18):函数索引的陷阱以及如何避免索引被污染
- 深入理解Oracle索引(18):函数索引的陷阱以及如何避免索引被污染
- 深入理解Oracle索引(18):函数索引的陷阱以及如何避免索引被污染
- 理解 Delphi 的类(十) - 深入方法[15] - 调用其他单元的函数
- 深入理解MySQL 5.7 GTID系列(七)binlog_gtid_simple_recovery参数的影响总结
- 字符串格式参数的日期比较函数
- 深入理解python中函数传递参数是值传递还是引用传递
- 深入理解Oracle索引(25):一招鲜、吃遍天之单字段索引创建思路
- 深入理解JavaScript系列(15):函数(Functions)
- 深入理解Oracle索引(17):Cost 值相同 CBO 对索引的选择
- 深入理解Oracle索引(10):索引列字符类型统计信息的32位限制
- 深入理解JS函数的参数(arguments)的使用
- 深入理解C++中函数参数——传值与传址详解
- 字符串格式参数的日期比较函数
- 深入理解Oracle索引(25):一招鲜、吃遍天之单字段索引创建思路
- 深入理解JavaScript系列(15):函数(Functions)
- 深入理解python中函数传递参数是值传递还是引用传递
- 【转】深入理解C++的动态绑定和静态绑定 & 不要重定义虚函数中的默认参数