【效能優化】直方圖
SQL>
SQL> begin
2 for i in 1..10000 loop
3 insert into hist values (i, i);
4 end loop;
5 commit;
6 end;
7 /
PL/SQL 過程已成功完成。
SQL> update hist set b=5 where b between 6 and 9995;
已更新9990行。
SQL> commit;
提交完成。
SQL> create index i_hist_b on tab(b);
索引已建立。
然後分析表,強制使列B不產生直方圖。
BEGIN
DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => USER,
TABNAME => 'HIST',
CASCADE => TRUE,
METHOD_OPT => 'FOR COLUMNS B SIZE 1 ');
END;
檢視檢視USER_TAB_HISTOGRAMS,列B上只有最大值,最小值兩條記錄分別對應端點號(endpoint_number)0和1,這種顯示說明列B沒有直方
圖資訊。
SQL>SELECT table_name,column_name,endpoint_number,endpoint_value FROM USER_TAB_HISTOGRAMS WHERE TABLE_NAME='TAB' ;
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
------------------------------ ---------------------------------------- --------------- --------------
HIST B 0 1
HIST B 1 10000
在沒有直方圖的情況下,在B列上進行等值查詢的時候,都是索引範圍掃描。
-----------------------------------------------------------------
SQL> select * from hist where b =1;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1911084455
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1000 | 6000 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| HIST | 1000 | 6000 | 4 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | I_HIST_B | 1000 | | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("B"=1)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
570 bytes sent via SQL*Net to client
492 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select * from hist where b =5;
9991 rows selected.
Elapsed: 00:00:00.07
Execution Plan
----------------------------------------------------------
Plan hash value: 1911084455
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1000 | 6000 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| HIST | 1000 | 6000 | 4 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | I_HIST_B | 1000 | | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("B"=5)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1369 consistent gets
0 physical reads
0 redo size
212165 bytes sent via SQL*Net to client
7818 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9991 rows processed
-----生成直方圖 再次收集統計資訊時 務必清除之前的統計資訊。否則執行計劃會利用原來的統計資訊
SQL> BEGIN
2 DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => user,
3 TABNAME => 'HIST',
4 CASCADE => TRUE,
5 METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO ');
6 END;
7 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.28
SQL> select * from hist where b=1;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1911084455
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| HIST | 1 | 6 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | I_HIST_B | 1 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("B"=1)
Statistics
----------------------------------------------------------
150 recursive calls
0 db block gets
24 consistent gets
0 physical reads
0 redo size
570 bytes sent via SQL*Net to client
492 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select * from hist where b =5;
9991 rows selected.
Elapsed: 00:00:00.06
Execution Plan
----------------------------------------------------------
Plan hash value: 1745918543
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9991 | 59946 | 6 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| HIST | 9991 | 59946 | 6 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("B"=5)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
688 consistent gets
0 physical reads
0 redo size
212165 bytes sent via SQL*Net to client
7818 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9991 rows processed
-------------------------------------------
SQL> SELECT TABLE_NAME, COLUMN_NAME, ENDPOINT_NUMBER, ENDPOINT_VALUE FROM USER_TAB_HISTOGRAMS
2 WHERE TABLE_NAME = 'HIST';
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER ENDPOINT_VALUE
----------- ------------ -------------- -------------- ---
HIST B 1 1
HIST B 2 2
HIST B 3 3
HIST B 4 4
HIST B 9995 5
HIST B 9996 9996
HIST B 9997 9997
HIST B 9998 9998
HIST B 9999 9999
HIST B 10000 10000
HIST A 0 1
HIST A 1 10000
12 rows selected.
Elapsed: 00:00:00.00
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-672508/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 直方圖均衡化直方圖
- OpenCV之影象直方圖均衡化OpenCV直方圖
- OpenCV計算機視覺學習(9)——影像直方圖 & 直方圖均衡化OpenCV計算機視覺直方圖
- [20210205]警惕toad下優化直方圖相關sql語句.txt優化直方圖SQL
- 直方圖均衡化原理與實現直方圖
- 灰度直方圖均衡化及其實現直方圖
- 前端效能優化 --- 圖片優化前端優化
- Android效能優化——圖片優化(二)Android優化
- 效能優化04-圖片優化優化
- 直方圖學習直方圖
- [20210205]警惕toad下優化直方圖相關sql語句3.txt優化直方圖SQL
- iOS 圖形效能優化iOS優化
- halcon-直方圖均衡直方圖
- 直方圖中最大矩形直方圖
- python如何畫直方圖Python直方圖
- [Python影象處理] 十一.灰度直方圖概念及OpenCV繪製直方圖Python直方圖OpenCV
- 影像演算法之直方圖均衡化(灰度影像)演算法直方圖
- iOS效能優化 - 網路圖片載入優化iOS優化
- Matplotlib直方圖繪製技巧直方圖
- elasticsearch 之 histogram 直方圖聚合ElasticsearchHistogram直方圖
- 前端效能優化之路——圖片篇。前端優化
- 效能優化 (五) 長圖優化,仿微博載入長圖方式優化
- 【前端效能優化】vue效能優化前端優化Vue
- 淺析MySQL 8.0直方圖原理MySql直方圖
- 【沃趣科技】直方圖系列1直方圖
- 你知道直方圖都能幹啥?直方圖
- 一文搞懂直方圖均衡直方圖
- [20221227]Adaptive Cursor Sharing & 直方圖.txtAPT直方圖
- 聊一聊MySQL的直方圖MySql直方圖
- opencv——影像直方圖與反向投影OpenCV直方圖
- python資料視覺化-matplotlib入門(4)-條形圖和直方圖Python視覺化直方圖
- 一張Web效能優化參考圖Web優化
- 【16位RAW影像處理三】直方圖均衡化及區域性直方圖均衡用於16點陣圖像的細節增強。直方圖
- 柱狀圖、直方圖、散點圖、餅圖講解直方圖
- 一文搞懂 Prometheus 的直方圖Prometheus直方圖
- 深度學習(模型引數直方圖)深度學習模型直方圖
- matplotlib的直方圖繪製(筆記)直方圖筆記
- 效能優化優化
- [譯]Web 效能優化: 圖片優化讓網站大小減少 62%Web優化網站