Oracle - 如何查看表中使用了多少块

时间:2016-05-10 10:00:47

标签: oracle

使用Oracle时我的经验非常有限,而且我想的是一个相当简单的查询。我有一个包含100万行的表,我试图证明压缩数据使用的空间更少,但我不知道如何做到这一点,根据下面的表创建,有人可以告诉我我需要写什么来看看之前/之后使用的块?

CREATE TABLE OrderTableCompressed(OrderID, StaffID, CustomerID, TotalOrderValue)
as (select level, ceil(dbms_random.value(0, 1000)), 
                  ceil(dbms_random.value(0,10000)), 
                  round(dbms_random.value(0,10000),2) 
    from dual 
    connect by level <= 1000000);

ALTER TABLE OrderTableCompressed ADD CONSTRAINT OrderID_PKC PRIMARY KEY (OrderID);

--QUERY HERE THAT SHOWS BLOCKS USED/TIME TAKEN
SELECT COUNT(ORDERID) FROM OrderTableCompressed;

ALTER TABLE OrderTableCompressed COMPRESS;

--QUERY HERE THAT SHOWS BLOCKS USED/TIME TAKEN WHEN COMPRESSED
SELECT COUNT(ORDERID) FROM OrderTableCompressed;

我知道压缩是如何工作的......它只是应用代码来证明我的理论。谢谢你的帮助

1 个答案:

答案 0 :(得分:2)

--QUERY HERE THAT SHOWS BLOCKS USED
SELECT blocks, bytes/1024/1024 as MB 
FROM user_segments 
where segment_name = 'ORDERTABLECOMPRESSED';

现在压缩表:(注意move。没有它你只需更改表的属性,随后的直接路径插入将创建压缩块)

ALTER TABLE OrderTableCompressed MOVE COMPRESS;

验证阻止:

--QUERY HERE THAT SHOWS BLOCKS USED TAKEN WHEN COMPRESSED
SELECT blocks, bytes/1024/1024 as MB 
FROM user_segments 
where segment_name = 'ORDERTABLECOMPRESSED';