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篇文章:
- Optimizing Queries with Attribute Clustering
- 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秒
DECLAREi NUMBER(10);
BEGINFOR i IN 1..80LOOPINSERT INTO sales_zmSELECT ROWNUM, MOD(ROWNUM,1000)FROM dualCONNECT 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)
----------------------100Elapsed: 00:00:00.18Statistics
----------------------------------------------------------0 recursive calls0 db block gets15344 consistent gets0 physical reads0 redo size582 bytes sent via SQL*Net to client52 bytes received via SQL*Net from client2 SQL*Net roundtrips to/from client0 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.07Statistics
----------------------------------------------------------14 recursive calls0 db block gets1032 consistent gets0 physical reads0 redo size582 bytes sent via SQL*Net to client52 bytes received via SQL*Net from client2 SQL*Net roundtrips to/from client0 sorts (memory)0 sorts (disk)1 rows processed
进阶实验
- Oracle Database 12c Attribute Clusters and Zone Maps
- https://github.com/oracle/dw-vldb-samples/tree/master/att_clu_zone_map
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
