Oracle性能提升特性:Zone Map和Attribute Clustering

Posted dingdingfish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle性能提升特性:Zone Map和Attribute Clustering相关的知识,希望对你有一定的参考价值。

概念

Zone Map和Attribute Clustering都是12.1.0.2的新特性。

按照Oracle Database Features的说法,Zone Map的描述为:

For full table access, zone maps allow I/O pruning of data based on the physical location of the data on disk, acting like an anti-index (索引的目的在于快速定位数据,而auti-index在于快速排除数据).

Zone Map的好处在于:

Accessing only the relevant data optimizes the I/O necessary to satisfy a query, increasing the performance significantly and reducing the resource consumption.
仅访问相关数据可优化满足查询所需的 I/O,显着提高性能并减少资源消耗。

Attribute clustering的描述为:

Attribute clustering is a table-level directive that clusters data in close physical proximity based on the content of certain columns. This directive applies to any kind of direct path operation, such as a bulk insert or a move operation.
属性聚类是一种表级指令,它根据某些列的内容对物理上接近的数据进行聚类。 该指令适用于任何类型的直接路径操作,例如批量插入或移动操作。

Attribute clustering的好处在于:

Storing data that logically belongs together in close physical proximity can greatly reduce the amount of data to be processed and can lead to better compression ratios.
将逻辑上属于一起的数据存储在物理上接近的位置可以大大减少要处理的数据量,并可以提高压缩率。

Zone Map只支持Exadata,但Attribute clustering数据库企业版就行。Zone Map虽然可以不依赖于Attribute clustering,但如果结合Attribute clustering,则可以排除掉更多的数据(因为数据更加物理集中)。
如果在非Exadata上创建Zone Map,将报错如下:

ERROR at line 1:
ORA-31969: ZONEMAP not supported for table stored in tablespace of this storage type

系统用户创建的表也不支持Zone Map:

ORA-31956: construct or object 'system table' not allowed for zonemap

建议阅读文章

关于这两个特性的文章,建议看一下Oracle产品经理Nigel Bayliss的2篇文章:

  1. Optimizing Queries with Attribute Clustering
  2. Optimizing Table Scans with Zone Maps

动手实验

此实验需要设置以下隐含参数,以模拟Exadata存储:

alter system set "_exadata_feature_on"=TRUE scope=spfile;
shutdown immediate
startup

创建测试表:

CREATE TABLE sales_zm (sale_id NUMBER(10), customer_id NUMBER(10));

-- 插入800万行,约30秒
DECLARE
  i NUMBER(10);
BEGIN
  FOR i IN 1..80
  LOOP
    INSERT INTO sales_zm
    SELECT ROWNUM, MOD(ROWNUM,1000)
    FROM   dual
    CONNECT BY LEVEL <= 100000;
    COMMIT;
  END LOOP;
END;
/

-- 更新统计信息
EXEC dbms_stats.gather_table_stats(ownname=>NULL, tabname=>'SALES_ZM');

SET AUTOTRACE ON STATISTIC

多次运行以下语句,注意consistent gets,基本稳定在15000左右:

SELECT COUNT(DISTINCT sale_id)
FROM   sales_zm
WHERE  customer_id = 50;

COUNT(DISTINCTSALE_ID)
----------------------
                   100

Elapsed: 00:00:00.18

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
      15344  consistent gets
          0  physical reads
          0  redo size
        582  bytes sent via SQL*Net to client
         52  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

创建带Attribute clustering的Zone Map:

ALTER TABLE sales_zm ADD CLUSTERING BY LINEAR ORDER (customer_id)
WITH MATERIALIZED ZONEMAP;

ALTER TABLE sales_zm MOVE;

重新多次运行相同的语句。查询时间下降1半以上,consistent gets从15000降到1000左右,效果明显:

SELECT COUNT(DISTINCT sale_id)
FROM   sales_zm
WHERE  customer_id = 50;

Elapsed: 00:00:00.07

Statistics
----------------------------------------------------------
         14  recursive calls
          0  db block gets
       1032  consistent gets
          0  physical reads
          0  redo size
        582  bytes sent via SQL*Net to client
         52  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

进阶实验

  1. Oracle Database 12c Attribute Clusters and Zone Maps
  2. https://github.com/oracle/dw-vldb-samples/tree/master/att_clu_zone_map

以上是关于Oracle性能提升特性:Zone Map和Attribute Clustering的主要内容,如果未能解决你的问题,请参考以下文章

Oracle Database 12c Attribute Cluster 和 Zone Map 高阶实验

Oracle Database 12c Attribute Cluster 和 Zone Map 高阶实验

BLE入门 19 ATT MTU 提升BLE数据传输率

在Angular中使用zone来提升性能

MySQL8.0新特性抢先看,性能又双叒提升了,真香啊

Linux上MySQL优化提升性能 哪些可以优化的关闭NUMA特性