11G新特性 -- Multicolumn Statistics (Column groups)
默认oracle会收集表中各个列的统计信息,但是会忽略列之间的关联关系。在大多情况下,优化器假设在复杂查询中的列之间是独立的。当where子句后指定了一个表的多个列条件时,优化器通常会将多个列的选择性(selectivity)相乘得到where语句的选择性,导致优化器做出错误判断!
Oracle 11g引入了多列统计信息概念,如果上面情况列关联性很好,可以做多列统计信息收集,让优化器做出正确判断。
在oracle 10g中,只有在一些特殊场合,优化器才会考虑列之间的关联关系:
-The optimizer used the number of distinct keys in an index to estimate selectivity provided all columns of a conjunctive predicate match all columns of a concatenated index key. In addition, the predicates must be equalities used in equijoins.
- If you set DYNAMIC_SAMPLING to level 4, the optimizer used dynamic sampling to estimate the selectivity of predicates involving multiple columns from a table. Because the sampling size is quite small, the results are dubious in most cases.
创建Column Groups:
DECLARE
cg_name varchar2();
BEGIN
cg_name := dbms_stats.create_extended_stats(null,'customers', '(cust_state_province,country_id)');
END;
/
查看Column Groups:
SQL> select extension_name, extension from dba_stat_extensions where table_name='CUSTOMERS'; EXTENSION_NAME EXTENSION
------------------------------ --------------------------------------------------------------------------------
SYS_STU#S#WF25Z#QAHIHE#MOFFMM_ ("CUST_STATE_PROVINCE","COUNTRY_ID") 或者
SQL> select sys.dbms_stats.show_extended_stats_name ('sh','customers','(cust_state_province,country_id)') col_group_name from dual; COL_GROUP_NAME
--------------------------------------------------
SYS_STU#S#WF25Z#QAHIHE#MOFFMM_
删除:
SQL> exec dbms_stats.drop_extended_stats('sh','customers','(cust_state_province, country_id)');
收集Column Groups的统计信息:
SQL> exec dbms_stats.gather_table_stats('sh','customers',method_opt =>'for all columns size skewonly for columns (cust_state_province,country_id) size skewonly');
监控Column Groups:
--查询多列统计信息
SQL> Select extension_name, extension from user_stat_extensions where table_name='CUSTOMERS'; EXTENSION_NAME EXTENSION
------------------------------ --------------------------------------------------------------------------------
SYS_STU#S#WF25Z#QAHIHE#MOFFMM_ ("CUST_STATE_PROVINCE","COUNTRY_ID") SQL>
--查看distinct数和柱状图使用情况
SQL> select e.extension col_group, t.num_distinct, t.histogram from user_stat_extensions e, user_tab_col_statistics t where e.extension_name = t.column_name and e.table_name = t.table_name and t.table_name = 'CUSTOMERS'; COL_GROUP NUM_DISTINCT HISTOGRAM
-------------------------------------------------------------------------------- ------------ ---------------
("CUST_STATE_PROVINCE","COUNTRY_ID") FREQUENCY SQL>
实验:
1)当不使用多列统计信息时,真实结果是3341,执行计划是1132.
SQL> exec dbms_stats.drop_extended_stats('sh','customers','(cust_state_province,country_id)');
PL/SQL procedure successfully completed.
SQL> select count(*) from sh.customers where CUST_STATE_PROVINCE = 'CA' and country_id=;
COUNT(*)
----------
Execution Plan
----------------------------------------------------------
Plan hash value:
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| | SELECT STATEMENT | | | | ()| :: |
| | SORT AGGREGATE | | | | | |
|* | TABLE ACCESS FULL| CUSTOMERS | | | ()| :: |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
- filter("CUST_STATE_PROVINCE"='CA' AND "COUNTRY_ID"=)
Statistics
----------------------------------------------------------
recursive calls
db block gets
consistent gets
physical reads
redo size
bytes sent via SQL*Net to client
bytes received via SQL*Net from client
SQL*Net roundtrips to/from client
sorts (memory)
sorts (disk)
rows processed
2)当使用多列统计信息时,真实结果是3341,执行计划是3437.
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS('SH','CUSTOMERS',METHOD_OPT =>'FOR ALL COLUMNS SIZE SKEWONLY FOR COLUMNS (CUST_STATE_PROVINCE,COUNTRY_ID) SIZE SKEWONLY');
PL/SQL procedure successfully completed.
SQL> select count(*) from sh.customers where CUST_STATE_PROVINCE = 'CA' and country_id=;
COUNT(*)
----------
Execution Plan
----------------------------------------------------------
Plan hash value:
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| | SELECT STATEMENT | | | | ()| :: |
| | SORT AGGREGATE | | | | | |
|* | TABLE ACCESS FULL| CUSTOMERS | | | ()| :: |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
- filter("CUST_STATE_PROVINCE"='CA' AND "COUNTRY_ID"=)
Statistics
----------------------------------------------------------
recursive calls
db block gets
consistent gets
physical reads
redo size
bytes sent via SQL*Net to client
bytes received via SQL*Net from client
SQL*Net roundtrips to/from client
sorts (memory)
sorts (disk)
rows processed
3)即以上情况,使用多列统计信息能让优化器得到更准确的判断!
11G新特性 -- Multicolumn Statistics (Column groups)的更多相关文章
- 11G新特性 -- Expression Statistics
当在查询中使用了function,返回值会受到影响. 比如: select count(*) from customers where lower(cust_state_province)='ca'; ...
- 11g新特性与12c新特性
1. 11g新特性概图 管理新特性> 开发新特性> 2. 12c 新特性概图
- 11g新特性-自动sql调优(Automatic SQL Tuning)
11g新特性-自动sql调优(Automatic SQL Tuning) 在Oracle 10g中,引进了自动sql调优特性.此外,ADDM也会监控捕获高负载的sql语句. 在Oracle 11g中, ...
- 使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard环境
Duplication Database 介绍 Duplicate database可以按照用途分为2种: duplicate database(复制出一个数据库) duplicate standby ...
- Oracle 11g 新特性 --SQL Plan Management 说明
Oracle 11g 新特性 --SQL Plan Management 说明 参见大神博主文章: http://blog.csdn.net/tianlesoftware/article/detail ...
- Oracle 11g 新特性 – HM(Hang Manager)简介
在这篇文章中我们会对oracle 11g 新特性—hang 管理器(Hang Manager) 进行介绍.我们需要说明,HM 只在RAC 数据库中存在. 在我们诊断数据库问题的时候,经常会遇到一些数据 ...
- 11G 新特性之 密码延迟认证
11G 新特性之 密码延迟认证 11G 新特性之 密码延迟认证 Table of Contents 1. 特性简述 2. 特性潜在引发问题 3. 关闭特性 1 特性简述 为了防止用户密码的暴力破解,从 ...
- 11G新特性 -- Statistics Preferences
Statistics Preferences新特性可以实现对指定对象进行信息收集. 可以在table.schema.database.global级别设置statistics preference. ...
- Oracle 11g新特性
文章转自网络 Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(I ...
随机推荐
- Codeforces Round #228 (Div. 1)
今天学长给我们挂了一套Div.1的题,难受,好难啊. Problem A: 题目大意:给你n个数字,让你叠成n堆,每个数字上面的数的个数不能超过这个数,如 3 上面最多放三个数字 问你,最少能放几堆. ...
- 第六章|网络编程-socket开发
1.计算机基础 作为应用开发程序员,我们开发的软件都是应用软件,而应用软件必须运行于操作系统之上,操作系统则运行于硬件之上,应用软件是无法直接操作硬件的,应用软件对硬件的操作必须调用操作系统的接口,由 ...
- 【LeetCode】157. Read N Characters Given Read4
Difficulty: Easy More:[目录]LeetCode Java实现 Description The API: int read4(char *buf) reads 4 charact ...
- (转)Java按指定行数读取文件
package test import java.io.File; import java.io.FileReader; import java.io.IOException; import java ...
- 配置多个数据源,spring profile 多环境配置管理
针对生产环境,测试环境,以及本地调试开发有时会配置多套数据库,在一个数据配置文件进行修改,往往有时发布到生成环境会忘记修改,或者本地调试时还是生产环境的库,会导致生产环境数据被污染. ps--刚开始配 ...
- 全排列-hdu1716
题目描述: 题目意思很简单,就是要我们输出全排列后的数据组成,但是要注意组成的数据是一个实数,并且千位数字相同的处在同一行中. 代码实现: #include<stdio.h> #inclu ...
- 洛谷 p1044 栈 【Catalan(卡特兰数)】【经典题】
题目链接:https://www.luogu.org/problemnew/show/P1044 转载于:https://www.luogu.org/blog/QiXingZhi/solution-p ...
- CF 633 F. The Chocolate Spree 树形dp
题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<ve ...
- BZOJ.3495.[PA2010]Riddle(2-SAT 前缀优化建图)
题目链接 每个城市要么建首都要么不建,考虑2-SAT 这样一个国家内城市两两连边是很显然的,但是边数为O(n^2) 每个国家中仅有一个建首都,考虑新建前缀S[i]=1/0这2n个点表示当前国家的[1, ...
- Xdebug、XHProf 、OneAPM 和 SocketLog
DevOps 生活变得美好的神器.分别是 Xdebug.XHProf .OneAPM 和 SocketLog 方法很简单,从 Xdebug 下载最新版的源代码. wget 解压: tar –zxvf ...