Oracle允许指定TIMESTAMP
表中类型的精度- SECOND
日期时间字段的小数部分中的位数.指定最大精度有什么缺点TIMESTAMP(9)
吗?
我能想到的一个原因是这些信息可能会被Oracle工具用于更漂亮的输出.
最多9个数字表示该字段存储为4字节整数,因此它不应该有任何性能影响,如果我在这里错了,请更正.
Jon*_*ler 15
没有缺点,如果有意义,请使用时间戳(9).
时间戳(9)和时间戳(1)使用相同的空间量,并且它们的性能相同.我只能找到一个存在性能差异的情况,在这种情况下,时间戳(9)实际上比时间戳(1)更快.
(我将为您省去插入时间戳(1)和时间戳(9)列的多行无聊代码,并比较它们的不同操作.)
这表明它们使用相同数量的空间(插入许多值并比较dba_segments):
--Create tables with timestamps and populate them with the same data (with different precision)
--Set initial and next to a low value so we can closely check the segment size)
create table timestamp1 (t1 timestamp(1), t2 timestamp(1), t3 timestamp(1), t4 timestamp(1), t5 timestamp(1))
storage(initial 65536 next 65536);
insert into timestamp1
select current_timestamp(1), current_timestamp(1), current_timestamp(1), current_timestamp(1), current_timestamp(1)
from dual connect by level <= 100000;
create table timestamp9 (t1 timestamp(9), t2 timestamp(9), t3 timestamp(9), t4 timestamp(9), t5 timestamp(9))
storage(initial 65536 next 65536);
insert into timestamp9
select current_timestamp(9), current_timestamp(9), current_timestamp(9), current_timestamp(9), current_timestamp(9)
from dual connect by level <= 100000;
--Segment size is identical
select segment_name, bytes from dba_segments where segment_name in ('TIMESTAMP1', 'TIMESTAMP9');
--SEGMENT_NAME BYTES
--TIMESTAMP1 8388608
--TIMESTAMP9 8388608
Run Code Online (Sandbox Code Playgroud)
当使用current_timestamp时,这是timestamp(9)更快的地方,您可能需要在某个时刻使用它来生成数据.但是我们只讨论慢速桌面上大约0.175和0.25秒之间的差异,以生成100K时间戳.我不确定为什么timestamp(9)更快,也许时间戳总是生成为timestamp(9)然后四舍五入到其他精度?
--current_timestamp(9) is slightly faster than current_timestamp(1)
select count(*) from
(
select *
from dual
--where current_timestamp(9) = current_timestamp(9)
where current_timestamp(1) = current_timestamp(1)
connect by level <= 100000
);
Run Code Online (Sandbox Code Playgroud)
编辑:性能差异存在于10g但不是11g.
归档时间: |
|
查看次数: |
8492 次 |
最近记录: |