代码之家  ›  专栏  ›  技术社区  ›  Leonid

在Oracle中选择更高的时间戳精度有什么缺点?

  •  12
  • Leonid  · 技术社区  · 16 年前

    TIMESTAMP 在表格中键入 SECOND 日期时间字段。指定最大精度有什么缺点吗 TIMESTAMP(9)

    我能想到的一个原因是,这些信息可能被Oracle工具用于更漂亮的输出。

    最多9位数字表示该字段存储为4字节整数,因此它不应具有任何性能影响,如果我在此处出错,请更正。

    4 回复  |  直到 16 年前
        1
  •  15
  •   Jon Heller TenG    16 年前

    没有缺点,如果有意义,使用时间戳(9)。

    时间戳(9)和时间戳(1)使用相同的空间量,并且它们的性能相同。我只能找到一个存在性能差异的情况,在这种情况下,时间戳(9)实际上比时间戳(1)快。

    (我将为您省去插入timestamp(1)和timestamp(9)列并比较不同的 对它们的操作。)

    --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
    

    --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
    );
    

        2
  •  0
  •   usr-local-ΕΨΗΕΛΩΝ    16 年前

    但是,如果由于某种原因(即实时系统日志记录)需要更高的精度,则必须使用更高的精度,从而导致性能下降。如果你的服务器没有处理大量的tps,你几乎没有性能影响,但如果你不需要精度,你是在浪费内存。

    希望能有所帮助。如果您想与我们分享您的数据库需求,我们可能会帮助您选择最佳折衷方案。

        3
  •  0
  •   Greg Buehler    16 年前

    区别不在于时间戳数据类型的技术使用,而在于应用程序。FERC和NERC在标记应用时通常需要一定的精度 critical infrastructure

    CIP-002 through CIP-009

        4
  •  0
  •   Hugo R    9 年前

    如果您总是将数据用作Oracle内部和中间层的“日期/时间戳”数据类型,则没有缺点,但是您必须了解整个应用程序/解决方案如何使用该列。

    • 在显示数据之前是否先截断数据?
    • 是否将该列转换为字符串以将其与另一列进行比较?
    • 这是审核还是订单捕获的要求?

    不要太担心读写性能的差异,它们可以忽略不计,从整体上评估从存储到UI的总体需求。