About me:Oracle ACE pro,optimistic,passionate and harmonious.
Focus on ORACLE,MySQL and other database programming,peformance tuning,db design, j2ee,Linux/AIX,Architecture tech,etc
统计信息对CBO优化器很重要,而直方图又是统计信息中非常重要的内容,对于列倾斜数据(skew data),如果没有直方图,ORACLE可能会选择错误的执行计划,从而影响效率。本文主要讲解如何通过执行计划观察是直方图引起的性能问题。 构造数据如下: DROP TABLE t; CREATE TABLE t AS SELECT LEVEL ID, trunc(100 * dbms_random.normal) val, rpad('1',10,'1') padding FROM dual CONNECT BY LEVEL<1000000;
SQL> select padding,count(*) from t group by padding;
--构造skew data INSERT INTO t VALUES(1000000,12345,'2345678'); INSERT INTO t VALUES(1000001,12345,'123456'); INSERT INTO t VALUES(1000001,12345,'56789'); --创建索引 CREATE INDEX idx_t ON t(padding); 1.采用dbms_stats收集,参数采用默认值
SQL> explain plan for
2 SELECT * FROM t WHERE padding LIKE '56%';