暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 空列所需的空间

ASKTOM 2019-11-22
147

问题描述

嗨,
我已经阅读了有关将空列放在此处的表格末尾的文字:
https://asktom.oracle.com/pls/apex/asktom.search?tag=null-columns-200503

我的问题是:

问题1:
请确认行末尾的空列分配恰好0个字节

问题2:
这种没有存储消耗的情况是否也适用于特定日期的其他类型?

达雷克

专家解答

我看到了您的评论,您将不得不分享完整的测试用例以显示您的工作。

正如医生所说:

Nulls are stored in the database if they fall between columns with data values. In these cases, they require 1 byte to store the length of the column (zero). Trailing nulls in a row require no storage because a new row header signals that the remaining columns in the previous row are null. For example, if the last three columns of a table are null, then no data is stored for these columns.

https://docs.oracle.com/en/database/oracle/oracle-database/19/cncpt/tables-and-table-clusters.html#GUID-FF28EE12-E161-4DAD-A0A2-027D72366EE6

稍微调整Tom的示例以包括其他数据类型,我得到了类似的结果; 末尾 (T1) 带有null的表明显小于没有 (T2) 的表:

declare
  l_stmt long := 'c1 int';
begin
  for i in 2 .. 999 loop
    l_stmt := l_stmt || ', c' || i || 
      case mod ( i, 3 ) 
        when 0 then ' int'
        when 1 then ' varchar2(100)'
        when 2 then ' date'
      end ;
  end loop;

  execute immediate 'create table t1 ( x int, ' || l_stmt || ')';
  execute immediate 'create table t2 ( ' || l_stmt || ', x int )';
end;
/

insert into t1 (x) select object_id from all_objects;

insert into t2 (x) select x from t1;
commit;

select segment_name, bytes from user_segments
where  segment_name in ( 'T1', 'T2' );

-- results from 19c
SEGMENT_NAME   BYTES      
T1                   917504 
T2                 88080384 

-- results from 11.2
SEGMENT_NAME   BYTES       
T1                   2097152 
T2                 109051904 


太棒了 ....

向我们展示您的SQL!
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论