1. 程式人生 > >[20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

[20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

connect hash tar buck actual date validate block sql_id

[20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

--//昨天看了https://jonathanlewis.wordpress.com/2017/06/01/histogram-upgrade-2/,提到了直方圖的問題,
--//特別是FOR ALL COLUMNS SIZE repeat引起的問題,在一些特殊情況要註意.

1.環境:
[email protected]> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- ---------------------------------------------------------------------------- ------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0

create table t (id number,pad varchar2(20),flag varchar2(1));
insert into t select rownum,lpad(‘a‘,20,‘a‘) ,‘a‘ from dual connect by level<=2e4;
insert into t select rownum+2e4,lpad(‘d‘,20,‘d‘) ,‘d‘ from dual connect by level<=2;
commit ;

[email protected]

/* */> exec dbms_stats.Gather_table_stats(ownname => user, tabname => ‘T‘,method_opt => ‘FOR ALL COLUMNS ‘);
PL/SQL procedure successfully completed.

[email protected]> SELECT flag, COUNT(*) FROM t GROUP BY flag;
F COUNT(*)
- ----------
d 2
a 20000

select * from DBA_TAB_COL_STATISTICS where owner=user and table_name=‘T‘ and column_name=‘FLAG‘;

Record View
As of: 2017/6/12 20:38:56

OWNER: SCOTT
TABLE_NAME: T
COLUMN_NAME: FLAG
NUM_DISTINCT: 2
LOW_VALUE: 61
HIGH_VALUE: 64
DENSITY: 0.000024997500249975
NUM_NULLS: 0
NUM_BUCKETS: 2
LAST_ANALYZED: 2017/6/12 20:37:55
SAMPLE_SIZE: 20002
GLOBAL_STATS: YES
USER_STATS: NO
NOTES:
AVG_COL_LEN: 2
HISTOGRAM: FREQUENCY
SCOPE: SHARED

--//建立了直方圖.bucket=2.

[email protected]
/* */> set numw 36
[email protected]> select * from USER_TAB_HISTOGRAMS where column_name=‘FLAG‘;
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A ENDPOINT_ACTUAL_VALU ENDPOINT_REPEAT_COUNT SCOPE
---------- ----------- --------------- ------------------------------------ ---------- -------------------- --------------------- -------
T FLAG 20000 503652795277878000000000000000000000 0 SHARED
T FLAG 20002 519229685853483000000000000000000000 0 SHARED
--//如果應用模式發生變化,加入了2種值.

insert into t select rownum+2e4+2,lpad(‘b‘,20,‘b‘) ,‘b‘ from dual connect by level<=2e4;
insert into t select rownum+4e4+2,lpad(‘c‘,20,‘c‘) ,‘c‘ from dual connect by level<=2;
commit ;

[email protected]
/* */> exec dbms_stats.Gather_table_stats(ownname => user, tabname => ‘T‘,method_opt => ‘FOR ALL COLUMNS size repeat‘,No_Invalidate => false);
PL/SQL procedure successfully completed.
--//加入No_Invalidate => false,主要使執行計劃能馬上使用新的統計信息.

select * from DBA_TAB_COL_STATISTICS where owner=user and table_name=‘T‘ and column_name=‘FLAG‘;

Record View
As of: 2017/6/12 20:42:29

OWNER: SCOTT
TABLE_NAME: T
COLUMN_NAME: FLAG
NUM_DISTINCT: 4
LOW_VALUE: 61
HIGH_VALUE: 64
DENSITY: 0.25
NUM_NULLS: 0
NUM_BUCKETS: 2
LAST_ANALYZED: 2017/6/12 20:42:01
SAMPLE_SIZE: 5463
GLOBAL_STATS: YES
USER_STATS: NO
NOTES:
AVG_COL_LEN: 2
HISTOGRAM: HYBRID
SCOPE: SHARED

--//因為bucket桶沒有變化,直方圖變成了HYBRID.

[email protected]> select * from USER_TAB_HISTOGRAMS where table_name=‘T‘ and column_name=‘FLAG‘;
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A ENDPOINT_ACTUAL_VALU ENDPOINT_REPEAT_COUNT SCOPE
---------- ----------- --------------- ------------------------------------ ---------- -------------------- --------------------- -------
T FLAG 2760 503652795277878000000000000000000000 2760 SHARED
T FLAG 5463 519229685853483000000000000000000000 1 SHARED

[email protected]> alter session set statistics_level=all;
Session altered.

[email protected]> SELECT flag, COUNT(*) FROM t GROUP BY flag order by 1;
F COUNT(*)
- ---------
a 20000
b 20000
c 2
d 2

[email protected]> select * from t where flag=‘c‘;
ID PAD F
----- -------------------- -
40003 cccccccccccccccccccc c
40004 cccccccccccccccccccc c

[email protected]> @ dpc ‘‘ ‘‘
PLAN_TABLE_OUTPUT
--------------------------------------
SQL_ID g3pmd0h5vnw5r, child number 0
-------------------------------------
select * from t where flag=‘c‘
Plan hash value: 1601196873
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 68 (100)| | 2 |00:00:00.01 | 205 |
|* 1 | TABLE ACCESS FULL| T | 1 | 6598 | 180K| 68 (0)| 00:00:01 | 2 |00:00:00.01 | 205 |
--------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / [email protected]$1
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("FLAG"=‘c‘)
23 rows selected.

--//可以發現E-rows 與 A-rows 存在很大的差距,正是業務模式發生了變化,導致method_opt => ‘FOR ALL COLUMNS size repeat‘存在問題.
--//而這個問題在11G是不存在的,在使用method_opt => ‘FOR ALL COLUMNS size repeat‘,會增加bucket的數量.
--//如果應用不存在這樣的問題,估計關系不大.

--//簡單的使用如下命令可以確定,"可能"有問題的直方圖.
SELECT *
FROM DBA_TAB_COL_STATISTICS
WHERE owner = USER
AND table_name = ‘T‘
AND num_distinct < 255
AND histogram NOT LIKE ‘%FREQUENCY%‘;

Record View
As of: 2017/6/12 20:46:36

OWNER: SCOTT
TABLE_NAME: T
COLUMN_NAME: FLAG
NUM_DISTINCT: 4
LOW_VALUE: 61
HIGH_VALUE: 64
DENSITY: 0.25
NUM_NULLS: 0
NUM_BUCKETS: 2
LAST_ANALYZED: 2017/6/12 20:42:01
SAMPLE_SIZE: 5463
GLOBAL_STATS: YES
USER_STATS: NO
NOTES:
AVG_COL_LEN: 2
HISTOGRAM: HYBRID
SCOPE: SHARED

--//如果不指定repeat.
[email protected]> exec dbms_stats.Gather_table_stats(ownname => user, tabname => ‘T‘,method_opt => ‘FOR ALL COLUMNS ‘,No_Invalidate => false);
PL/SQL procedure successfully completed.

[email protected]> select * from USER_TAB_HISTOGRAMS where table_name=‘T‘ and column_name=‘FLAG‘;
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE ENDPOINT_A ENDPOINT_ACTUAL_VALU ENDPOINT_REPEAT_COUNT SCOPE
---------- -------------------- --------------- ------------------------------------ ---------- -------------------- --------------------- -------
T FLAG 20000 503652795277878000000000000000000000 0 SHARED
T FLAG 40000 508845092136413000000000000000000000 0 SHARED
T FLAG 40002 514037388994948000000000000000000000 0 SHARED
T FLAG 40004 519229685853483000000000000000000000 0 SHARED
--//分析使用No_Invalidate => false,這樣重新執行會重新分析.

select * from DBA_TAB_COL_STATISTICS where owner=user and table_name=‘T‘ and column_name=‘FLAG‘;

Record View
As of: 2017/6/12 20:49:27

OWNER: SCOTT
TABLE_NAME: T
COLUMN_NAME: FLAG
NUM_DISTINCT: 4
LOW_VALUE: 61
HIGH_VALUE: 64
DENSITY: 0.0000124987501249875
NUM_NULLS: 0
NUM_BUCKETS: 4
LAST_ANALYZED: 2017/6/12 20:47:21
SAMPLE_SIZE: 40004
GLOBAL_STATS: YES
USER_STATS: NO
NOTES:
AVG_COL_LEN: 2
HISTOGRAM: FREQUENCY
SCOPE: SHARED
--//這樣建立的直方圖=FREQUENCY.

[email protected]> select * from t where flag=‘c‘;
ID PAD F
----- -------------------- -
40003 cccccccccccccccccccc c
40004 cccccccccccccccccccc c

[email protected]> @ dpc ‘‘ ‘‘
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID g3pmd0h5vnw5r, child number 0
-------------------------------------
select * from t where flag=‘c‘
Plan hash value: 1601196873
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 68 (100)| | 2 |00:00:00.01 | 205 |
|* 1 | TABLE ACCESS FULL| T | 1 | 2 | 56 | 68 (0)| 00:00:01 | 2 |00:00:00.01 | 205 |
--------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / [email protected]$1

Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("FLAG"=‘c‘)

--//這樣就ok了.
--//對於這樣的情況最佳的方式手工設置分析方式

BEGIN
dbms_stats.Set_table_prefs(user, ‘T‘, ‘METHOD_OPT‘=>‘FOR ALL COLUMNS SIZE 1, FOR COLUMNS SIZE AUTO flag‘);
END;
/

--//避免這個問題. 總之12c要註意分析方法METHOD_OPT‘=>‘FOR ALL COLUMNS SIZE repeat‘帶來的問題.
--//特別是一些應用模式發生變化的情況.而11g前面的測試不存在這個問題.

[20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

相關推薦

[20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

connect hash tar buck actual date validate block sql_id [20170612]FOR ALL COLUMNS SIZE repeat(12c).txt--//昨天看了https://jonathanlewis.wordp

[20170612]FOR ALL COLUMNS SIZE repeat(11g).txt

ets session ogr bject ber procedure glob 註意 com [20170612]FOR ALL COLUMNS SIZE repeat(11g).txt--//昨天看了https://jonathanlewis.wordpress.com

live555: The input frame data was too large for our buffer size

rtsp采用Live555作為流媒體服務器端,進行RTSP的請求的時候,會出現如下的提示:MultiFramedRTPSink::afterGettingFrame1(): The input frame data was too large for our buffer size (100452). 13

[GeeksForGeeks] Populate inorder successor for all nodes in a binary search tree

stack iter pro get root following sin ice nod Given a binary search tree with the following tree node definition. next points to a node‘s

PL/SQL Developer登錄出現——Using a filter for all users can lead to poor performance!

objects default devel http mage eve 配置 tool cnblogs 用PL/SQL Developer登錄Oracle時提示:Using a filter for all users can lead to poor performan

How to Add “Open with Notepad” to the Windows Context Menu for All Files

If you want to open a file type not registered with Notepad, you have to click through several options to make it happen. This can be a hassle, so

Latest Ripple News for All the Ripple Crypto Fans

Ripple has always been the most controversial virtual currency. You must have continuously heard about much good news and bad news about

mycat執行報錯:java.sql.SQLException: java.lang.IllegalArgumentException: all columns in order by clause

普通sql語句: SELECT REC_ID,ORDER_UPDATE_RULE,ACTIVITY_ID FROM PLT_ACTIVITY_INFO WHERE ((ORDER_GEN_RULE = 1 OR ORDER_GEN_RULE = 2 ) AND TE

make[1]: Nothing to be done for `all-am'.

1.這句提示是說明你已經編譯好了,而且沒有對程式碼進行任何改動。 若想重新編譯,可以先刪除以前編譯產生的目標檔案: make clean make 2.也可以 make clean all make

Ask HN: Is the startup incentivisation valid for all national R&D strategies?

I'm a Spaniard, and startups are still in fashion. However, I still doubt if in all areas are suitable or there's any evidence of the increase in innovatio

One place for all your web apps | Hacker News

Hi HN,We're Alex and Julien, the founders of Station (https://getstation.com/). Our free desktop app unifies all your work applications in one neat interfa

Latin American Exchange Buda.com Adds Lightning Network Payments for All

As many of you already know, the main feature of the Lightning Network is that, in addition to being a way to pay Bitcoins with very low fees and practical

A searchable archive for all things infosec | Hacker News

We are a small group of security researchers. We are building a site to make everything searchable in the area of infosec.Every year there are more than a

Android Shared-Element Transitions for all

Android Shared-Element Transitions for allWe all want our apps to have its personality beyond material and, activitytransitions are a great way to make our

R語言︱函式使用技巧(迴圈、if族/for、switch、repeat、ifelse、stopifnot)

每每以為攀得眾山小,可、每每又切實來到起點,大牛們,緩緩腳步來俺筆記葩分享一下吧,please~———————————————————————————後續加更內容:應用一:if族有哪些成員呢?——if/ifelse/stopifnot應用二:如何在迴圈中,實時輸出時間消耗?—

對於不能join的表,使用for all entries in語句將該表與內表串聯。

像bseg這樣的表不是transparent table所以不能做inner join。在這種情況下,可以先從其他表中選出資料放到itab中,然後使用for all entries 語句來串聯。 如下:   SELECT bseg~kunnr bseg~lifnr bseg~

all for one,one for all

常用格式: 1. *斜體* or _斜體_:一個星號或者一個下劃線包裹為斜體,例如 斜體,斜體 2. **強調** or __強調__:使用兩個星號或者兩個下滑線,例如:重點強調 即加粗

For all entries使用中注意的問題

1.SELECT CARRID CONNID FLDATE PRICE FROM SFLIGHT INTO TABLE GT_tab FOR ALL ENTRIES IN GT_SFLIGHT WHERE CARRID = GT_SFLIGHT-CARRID AND CONNID = GT_SFLIGHT-

Accept a BAA with AWS for all accounts in your organization

I’m excited to announce to our healthcare customers and partners that you can now accept a single AWS Business Associate Addendum (BAA) for all ac

Python-selenium:Protected Mode settings are not the same for all zones.

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">編碼環境:</span><span style="f