今天"表姐"有個比較緊急的工作,有一張歷史費用報表下班前必須查詢出來,已經倒騰2個小時了,查詢并發數已經加到40個,報表還是查詢不出來,而且這個報表每月都會折磨表姐,
眼看就要下班了,時間緊近,緊急求助。
經常被單位各位"表姐"騷擾,而且還特別緊急。。。。DBA的苦,好吧,放下手頭工作,先幫"表姐"處理問題。。。。
2、問題分析
DBA:
你的SQL發我看看?
表姐
:
select /*+ parallel(T 40)*/* FROM ht.ht_tab_fy T
WHERE EXISTS (SELECT 1 FROM ht2.ht_DEPT M WHERE T.DEPT_ID = M.DEPT_ID AND M.DEPT_TREE LIKE '%611002%')
AND T.DATA_MONTH = '201709' ;
DBA
:
這個查詢結果發我看看?
explain plan for
select * FROM ht.ht_tab_fy T
WHERE EXISTS (SELECT 1 FROM ht2.ht_DEPT M WHERE T.DEPT_ID = M.DEPT_ID AND M.DEPT_TREE LIKE '%611002%')
AND T.DATA_MONTH = '201709' ;
select * from table(dbms_xplan.display());
表姐
:
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 25466 | 3531K| 80186 (2)|
| 1 | HASH JOIN RIGHT SEMI| | 25466 | 3531K| 80186 (2)|
| 2 | TABLE ACCESS FULL | ht_DEPT | 58 | 2494 | 8 (0)|
| 3 | TABLE ACCESS FULL | ht_tab_fy | 118K| 11M| 80176 (2)|
-------------------------------------------------------------------------------
DBA
:
這兩個查詢結果給我
select version from v$instance;
select name,value from v$parameter where name like '%multiblock%';
SQL> select name,value from v$parameter where name like '%multiblock%';
SQL> select version from v$instance;
VERSION
-----------------
10.2.0.5.0
NAME
VALUE
-------------------------------------------------- --------------------------------------------------
db_file_multiblock_read_count
16
3、
優化方案
DBA
:
從新收集下統計信息:
exec dbms_stats.gather_table_stats(ownname=>'ht2',tabname=>'ht_DEPT',estimate_percent=>100,method_opt=>'for all columns size repeat',no_invalidate=>false,degree=>8,cascade=>true);
exec dbms_stats.gather_table_stats(ownname=>'ht',tabname=>'ht_tab_fy',estimate_percent=>100,method_opt=>'for all columns size repeat',no_invalidate=>false,degree=>8,cascade=>true);
然后再執行你的語句:
alter session set db_file_multiblock_read_count=128; --前面加一條
select * FROM ht.ht_tab_fy T
WHERE EXISTS (SELECT 1 FROM ht2.ht_DEPT M WHERE T.DEPT_ID = M.DEPT_ID AND M.DEPT_TREE LIKE '%611002%')
AND T.DATA_MONTH = '201709' ;
4、優化結果
表姐
:
結果秒出,太感謝了,眼淚嘩嘩的!!!!
5、現在問題來了?
表姐的語句為什么得到了優化?原理是什么?