在收集統計資訊時指定method_opt=>.. size auto 時,有可能不收集直方圖
DBMS_STATS With METHOD_OPT =>'..SIZE auto' May Not Collect Histograms (文件 ID 557594.1)
在收集統計資訊時指定method_opt=>.. size auto 時,有可能不收集直方圖。
APPLIES TO:
Oracle Server - Enterprise Edition - Version 10.2.0.1 and later
Information in this document applies to any platform.
SYMPTOMS
After stats are first gathered using DBMS_STATS with METHOD_OPT =>'FOR all COLUMNS SIZE auto', query runs poorly.
Histograms are not collected properly on the columns. After re-gathering the stats with the same procedure, the query runs fine.
症狀:
第一次用size auto收集統計資訊,查詢緩慢
原因直方圖沒有被收集,用同樣的過程重新收集後,查詢速度變快
CAUSE
When 'SIZE AUTO' is specified, histograms are considered by information of col_usage$. If a column (mycol in this case) has its column statistics and it is used in predicates of SQL statements, then col_usage$ is updated to show that the column has been used as predicates. When DBMS_STATS.GATHER_TABLE_STATS is executed with 'SIZE AUTO' specified, it checks col_usage$ to see whether the column has been used as predicates or not . If it has, histogram is considered for that column.
size auto收集直方圖的條件:
1.列的資料傾斜。
2.列在查詢語句中做謂語
測試:
SQL> create table hurp (mycol number);
Table created.
--插入1000條-1
begin
for i in 1 .. 100000 loop
insert into hurp values (-1);
commit;
end loop;
for i in 1 .. 1000 loop
insert into hurp values (0);
commit;
end loop;
for i in 1 .. 100 loop
insert into hurp values(7);
commit;
end loop;
end;
/
PL/SQL procedure successfully completed.
---建立索引對列mycol
SQL> create index indx_hurp on hurp(mycol);
Index created.
--對列索引列收集統計資訊
begin
dbms_stats.gather_table_stats(ownname =>'SYS',
tabname =>'HURP',
method_opt =>'for all indexed columns size auto',
cascade =>TRUE);
end;
/
select lpad(owner,5) owner,
lpad(table_name,5)table_name,
column_name,
endpoint_value,
endpoint_number
from dba_histograms
where owner='SYS'
and table_name='HURP';
OWNER LPAD(TABLE COLUMN_NAME ENDPOINT_VALUE ENDPOINT_NUMBER
---------- ---------- ------------------------------ -------------- ---------------
SYS HURP MYCOL -1 0
SYS HURP MYCOL 7 1
-- Update col_usage$
SQL> select count(*) from hurp where mycol = 1;
COUNT(*)
----------
0
---重新收集統計資訊
SQL> begin
2 dbms_stats.gather_table_stats(ownname =>'SYS',
3 tabname =>'HURP',
4 method_opt =>'for all indexed columns size auto',
5 cascade =>TRUE);
6 end;
7 /
PL/SQL procedure successfully completed.
---檢視發現已經有了直方圖
SQL> select lpad(owner,5) owner,
2 lpad(table_name,5)table_name,
3 column_name,
4 endpoint_value,
5 endpoint_number
6 from dba_histograms
7 where owner='SYS'
8 and table_name='HURP';
OWNER TABLE_NAME COLUMN_NAME ENDPOINT_VALUE ENDPOINT_NUMBER
---------- ---------- ------------------------------ -------------- ---------------
SYS HURP MYCOL -1 5419
SYS HURP MYCOL 0 5472
SYS HURP MYCOL 7 5480
select count(*)from hurp where mycol=-1;
-----測試資料不傾斜
drop table hurp purge;
create table hurp(mycol number);
begin
for i in 1 .. 10000 loop
insert into hurp values(-1);
commit;
end loop;
for i in 1 .. 10000 loop
insert into hurp values(0);
commit;
end loop;
for i in 1 .. 10000 loop
insert into hurp values(7);
commit;
end loop;
end;
/
create index indx_hurp on hurp(mycol);
select count(*) from hurp where mycol=1;
exec dbms_stats.flush_database_monitoring_info;
begin
dbms_stats.gather_table_stats(ownname=>'SYS',
tabname=>'HURP',
method_opt=>'for all indexed columns size auto',
cascade=>true);
end;
/
select lpad(owner,5) owner,lpad(table_name,5) table_name,column_name,endpoint_value,endpoint_number from dba_histograms where owner='SYS' and table_name='HURP';
begin
dbms_stats.gather_table_stats(ownname =>'SYS',
tabname =>'TEST',
method_opt =>'for all columns size auto',
cascade =>TRUE);
end;
/
select lpad(owner,5) owner,lpad(table_name,5) table_name,column_name,endpoint_value,endpoint_number from dba_histograms where owner='SYS' and table_name='TEST';
SELECT OWNER,TABLE_NAME,BU
在收集統計資訊時指定method_opt=>.. size auto 時,有可能不收集直方圖。
APPLIES TO:
Oracle Server - Enterprise Edition - Version 10.2.0.1 and later
Information in this document applies to any platform.
SYMPTOMS
After stats are first gathered using DBMS_STATS with METHOD_OPT =>'FOR all COLUMNS SIZE auto', query runs poorly.
Histograms are not collected properly on the columns. After re-gathering the stats with the same procedure, the query runs fine.
症狀:
第一次用size auto收集統計資訊,查詢緩慢
原因直方圖沒有被收集,用同樣的過程重新收集後,查詢速度變快
CAUSE
When 'SIZE AUTO' is specified, histograms are considered by information of col_usage$. If a column (mycol in this case) has its column statistics and it is used in predicates of SQL statements, then col_usage$ is updated to show that the column has been used as predicates. When DBMS_STATS.GATHER_TABLE_STATS is executed with 'SIZE AUTO' specified, it checks col_usage$ to see whether the column has been used as predicates or not . If it has, histogram is considered for that column.
size auto收集直方圖的條件:
1.列的資料傾斜。
2.列在查詢語句中做謂語
測試:
SQL> create table hurp (mycol number);
Table created.
--插入1000條-1
begin
for i in 1 .. 100000 loop
insert into hurp values (-1);
commit;
end loop;
for i in 1 .. 1000 loop
insert into hurp values (0);
commit;
end loop;
for i in 1 .. 100 loop
insert into hurp values(7);
commit;
end loop;
end;
/
PL/SQL procedure successfully completed.
---建立索引對列mycol
SQL> create index indx_hurp on hurp(mycol);
Index created.
--對列索引列收集統計資訊
begin
dbms_stats.gather_table_stats(ownname =>'SYS',
tabname =>'HURP',
method_opt =>'for all indexed columns size auto',
cascade =>TRUE);
end;
/
select lpad(owner,5) owner,
lpad(table_name,5)table_name,
column_name,
endpoint_value,
endpoint_number
from dba_histograms
where owner='SYS'
and table_name='HURP';
OWNER LPAD(TABLE COLUMN_NAME ENDPOINT_VALUE ENDPOINT_NUMBER
---------- ---------- ------------------------------ -------------- ---------------
SYS HURP MYCOL -1 0
SYS HURP MYCOL 7 1
-- Update col_usage$
SQL> select count(*) from hurp where mycol = 1;
COUNT(*)
----------
0
---重新收集統計資訊
SQL> begin
2 dbms_stats.gather_table_stats(ownname =>'SYS',
3 tabname =>'HURP',
4 method_opt =>'for all indexed columns size auto',
5 cascade =>TRUE);
6 end;
7 /
PL/SQL procedure successfully completed.
---檢視發現已經有了直方圖
SQL> select lpad(owner,5) owner,
2 lpad(table_name,5)table_name,
3 column_name,
4 endpoint_value,
5 endpoint_number
6 from dba_histograms
7 where owner='SYS'
8 and table_name='HURP';
OWNER TABLE_NAME COLUMN_NAME ENDPOINT_VALUE ENDPOINT_NUMBER
---------- ---------- ------------------------------ -------------- ---------------
SYS HURP MYCOL -1 5419
SYS HURP MYCOL 0 5472
SYS HURP MYCOL 7 5480
select count(*)from hurp where mycol=-1;
-----測試資料不傾斜
drop table hurp purge;
create table hurp(mycol number);
begin
for i in 1 .. 10000 loop
insert into hurp values(-1);
commit;
end loop;
for i in 1 .. 10000 loop
insert into hurp values(0);
commit;
end loop;
for i in 1 .. 10000 loop
insert into hurp values(7);
commit;
end loop;
end;
/
create index indx_hurp on hurp(mycol);
select count(*) from hurp where mycol=1;
exec dbms_stats.flush_database_monitoring_info;
begin
dbms_stats.gather_table_stats(ownname=>'SYS',
tabname=>'HURP',
method_opt=>'for all indexed columns size auto',
cascade=>true);
end;
/
select lpad(owner,5) owner,lpad(table_name,5) table_name,column_name,endpoint_value,endpoint_number from dba_histograms where owner='SYS' and table_name='HURP';
begin
dbms_stats.gather_table_stats(ownname =>'SYS',
tabname =>'TEST',
method_opt =>'for all columns size auto',
cascade =>TRUE);
end;
/
select lpad(owner,5) owner,lpad(table_name,5) table_name,column_name,endpoint_value,endpoint_number from dba_histograms where owner='SYS' and table_name='TEST';
SELECT OWNER,TABLE_NAME,BU
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29446986/viewspace-1173584/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 微課sql最佳化(7)、統計資訊收集(5)-關於直方圖SQL直方圖
- 手動收集——收集統計資訊
- ORACLE19c新特性-實時統計資訊收集Oracle
- Oracle收集統計資訊Oracle
- 收集統計資訊方案
- 收集全庫統計資訊
- 微課sql最佳化(3)、統計資訊收集(2)-如何收集統計資訊SQL
- 6 收集資料庫統計資訊資料庫
- 【統計資訊】Oracle常用的收集統計資訊方式Oracle
- oracle 統計資訊檢視與收集Oracle
- 資訊收集
- Oracle統計資訊的收集和維護Oracle
- Oracle運維指令碼-收集統計資訊Oracle運維指令碼
- 啟用與禁用統計資訊自動收集
- [統計資訊系列7] Oracle 11g的自動統計資訊收集Oracle
- 文字分析在收集產品反饋時的作用
- Linux本地資訊收集Linux
- 資訊收集流程
- 資訊收集11——nmap
- 內網資訊收集內網
- 微課sql最佳化(8)、統計資訊收集(6)-統計資訊查詢SQL
- Linux常用資訊收集命令Linux
- kali常用的資訊收集
- Oracle多列統計資訊與直方圖對有關聯多列查詢影響Oracle直方圖
- GUI程式設計--班級資訊收集系GUI程式設計
- GUI程式設計--班級資訊收集系..GUI程式設計
- Nebula Graph 特性講解——RocksDB 統計資訊的收集和展示
- 【TUNE_ORACLE】定製化收集統計資訊SQL參考OracleSQL
- postgresql 定時收集表和索引統計資訊 轉發:https://blog.csdn.net/weixin_33711641/article/details/89752462SQL索引HTTPAI
- 網路安全中資訊收集是什麼?資訊收集分為哪幾類?
- 收集 Kubernetes 資源統計資料的新工具
- ORACLE analyse table方式收集表統計資訊導致SQL執行計劃不準確而效能下降OracleSQL
- 滲透測試-資訊收集
- 滲透測試------資訊收集
- powershell滲透-資訊收集命令
- 滲透測試——資訊收集
- test資訊收集11(mimikatz使用)
- MySQL對所有表收集統計資訊(Python 2指令碼)MySqlPython指令碼
- 最佳實踐:解讀GaussDB(DWS) 統計資訊自動收集方案