【发布时间】:2014-04-24 16:02:14
【问题描述】:
如果压缩被标记为压缩,这个查询会告诉我
Select *
From All_Tab_Partitions
在讨论中提出,如果使用 FAST_LOAD 加载,标记为压缩的分区实际上可以包含未压缩的数据。
我只想对未压缩的分区发出压缩命令。
如何查看分区内的数据是否被压缩?
【问题讨论】:
标签: oracle compression partitioning
如果压缩被标记为压缩,这个查询会告诉我
Select *
From All_Tab_Partitions
在讨论中提出,如果使用 FAST_LOAD 加载,标记为压缩的分区实际上可以包含未压缩的数据。
我只想对未压缩的分区发出压缩命令。
如何查看分区内的数据是否被压缩?
【问题讨论】:
标签: oracle compression partitioning
压缩可以在分区上启用,但只有在数据是从直接路径插入创建的情况下使用。使用采样和函数 DBMS_COMPRESSION.GET_COMPRESSION_TYPE 估计行的百分比 按分区压缩。
架构
create table compression_test
(
a number,
b varchar2(100)
) partition by range(a)
(
partition p_all_compressed values less than (2) compress,
partition p_none_compressed values less than (3) compress,
partition p_half_compressed values less than (4) compress
);
insert /*+ append */ into compression_test partition (p_all_compressed)
select 1, '0123456789' from dual connect by level <= 100000;
commit;
insert into compression_test partition (p_none_compressed)
select 2, '0123456789' from dual connect by level <= 100000;
commit;
insert /*+ append */ into compression_test partition (p_half_compressed)
select 3, '0123456789' from dual connect by level <= 50000;
commit;
insert into compression_test partition (p_half_compressed)
select 3, '0123456789' from dual connect by level <= 50000;
commit;
估算代码
--Find percent compressed from sampling each partition.
declare
v_percent_compressed number;
begin
--Loop through partitions.
for partitions in
(
select table_owner, table_name, partition_name
from dba_tab_partitions
--Enter owner and table_name here.
where table_owner = user
and table_name = 'COMPRESSION_TEST'
) loop
--Dynamic SQL to sample a partition and test for compression.
execute immediate '
select
round(sum(is_compressed)/count(is_compressed) * 100) percent_compressed
from
(
--Compression status of sampled rows.
--
--Numbers are based on constants from:
--docs.oracle.com/cd/E16655_01/appdev.121/e17602/d_compress.htm
--Assumption: Only basic compression is used.
--Assumption: Partitions are large enough for 0.1% sample size.
select
case dbms_compression.get_compression_type(
user,
'''||partitions.table_name||''',
rowid,
'''||partitions.partition_name||'''
)
when 4096 then 1
when 1 then 0
end is_compressed
from '||partitions.table_owner||'.'||partitions.table_name||'
partition ('||partitions.partition_name||') sample (0.1)
)
' into v_percent_compressed;
dbms_output.put_line(rpad(partitions.partition_name||':', 31, ' ')||
lpad(v_percent_compressed, 3, ' '));
end loop;
end;
/
样本输出
P_ALL_COMPRESSED: 100
P_HALF_COMPRESSED: 55
P_NONE_COMPRESSED: 0
【讨论】: