服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > 数据库技术 > Oracle技术 > Oracle开发 > 查看文档

oracle数据库中的timestamp和date类型

【赛迪网-it技术报道】问题:where timestamp>date 这种子句是走索引吗?

下面我们针对这个问题做一个试验:

c:>sqlplus / as sysdba

sys@eos >create table test as select table_name,to_timestamp(last_analyzed) date_test from dba_tables;

表已创建。

sys@eos> create index idx_test_date on test (date_test);

索引已创建。

sys@eos> desc test

名称 是否为空? 类型

------------------------- -------- ----------------

table_name not null varchar2(30)

date_test timestamp(0)

sys@eos> select date_test from test where date_test > to_date('2007-11-5 00:00:00','yyyy-mm-dd hh24:mi:ss');

执行计划

----------------------------------------------------------

plan hash value: 944171586

-------------------------------------------------------------------------------- --

| id | operation | name | rows | bytes | cost (%cpu)| time |

-------------------------------------------------------------------------------- --

| 0 | select statement | | 1 | 22 | 1 (0)| 00:00:01 |

|* 1 | index range scan| idx_test_date | 1 | 22 | 1 (0)| 00:00:01 |

-------------------------------------------------------------------------------- --

predicate information (identified by operation id):

---------------------------------------------------

1 - access("date_test">timestamp'2007-11-05 00:00:00')

note

-----

- dynamic sampling used for this statement

统计信息

----------------------------------------------------------

7 recursive calls

0 db block gets

18 consistent gets

0 physical reads

0 redo size

280 bytes sent via sql*net to client

374 bytes received via sql*net from client

1 sql*net roundtrips to/from client

0 sorts (memory)

0 sorts (disk)

0 rows processed

从上文中大家可以清楚地看到,timestamp>date情况下,走索引。

另外,date类型一般很少用,建议大家在产品里面所有的date数据类型全部改为timestamp。

扫描关注微信公众号