oracle效能問題:sql語句優化
四川同事反映,前臺業務處理任務排隊嚴重,資料插入和查詢反應時間太長。大約影響時間一個小時左右。現已恢復正常,請協助查詢問題原因。發生時間上午10點-11點之間。
問題點應該在資料庫端了,由於是前天的事情,考慮執行一個awr報告。檢視一下資料庫當時的效能情況。
注意到Top 10 SQL 報告裡一條語句明顯異常,根據SQL Id連結到完整的語句項上,看到delete from t_check_retail_bill_record where operator_id='dfhq_n' and type='01' and checkdate='20121226';這是業務對賬功能的語句,正常情況不應該在這個時段出現該功能語句,而且是delete功能,初步判斷是維護人員操作失誤,要清除掉資料。這一時間段共執行了16次同樣型別的SQL,每次執行都用耗費64秒的時間,共耗費約17分鐘的時間。select t1.sql_text
from DBA_HIST_SQLTEXT t1,dba_hist_sqlstat t2
where t1.sql_text like 'delete from t_check_retail_bill_record%'
and t2.sql_id=t1.sql_id and t2.snap_id=33091;
很明顯以上語句出現了鎖等待以及效能下降,經初步分析此時間段內的效能資料, 發現類似以下的SQL耗用了大量的時間, 對系統造成了很大的壓力。
原因找到了,如何避免悲劇重演?
SQL> select num_rows from dba_tables where table_name='T_CHECK_RETAIL_BILL_RECORD' and wner='HQCHECK';
NUM_ROWS
----------
14309740
這個表有14309740條記錄,佔用了1576MB的空間,算是個巨大表;
看看索引情況:
SQL> select OWNER,INDEX_NAME,TABLE_NAME from dba_indexes where WNER='HQCHECK' and TABLE_NAME='T_CHECK_RETAIL_BILL_RECORD';
沒有建立index,因此上面的SQL每次都會全表掃描;
SQL> select 1 from HQCHECK.t_check_retail_bill_record t where t.operator_id='B00A' and t.type='03' and t.checkdate='20121226';
no rows selected
Elapsed: 00:00:25.37
Execution Plan
----------------------------------------------------------
Plan hash value: 3096934412
------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 44395 (1)| 00:08:53 |
|* 1 | TABLE ACCESS FULL| T_CHECK_RETAIL_BILL_RECORD | 1 | 20 | 44395 (1)| 00:08:53 |
------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("T"."OPERATOR_ID"='B00A' AND "T"."CHECKDATE"='20121226' AND
"T"."TYPE"='03')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
194848 consistent gets
194769 physical reads
0 redo size
270 bytes sent via SQL*Net to client
389 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
建立索引:create index HQCHECK.chk_bill_idx on HQCHECK.t_check_retail_bill_record(checkdate,operator_id,type) nologging;
SQL> select 1 from HQCHECK.t_check_retail_bill_record where operator_id='B00A' and type='03' and checkdate='20121226';
no rows selected
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 3950944362
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 3 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| CHK_BILL_IDX | 1 | 20 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("CHECKDATE"='20121226' AND "OPERATOR_ID"='B00A' AND
"TYPE"='03')
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
270 bytes sent via SQL*Net to client
389 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
問題得以解決。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28985005/viewspace-764371/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sql語句效能優化SQL優化
- 對sql語句的優化問題SQL優化
- Oracle之sql語句優化OracleSQL優化
- 資料庫效能優化之SQL語句優化資料庫優化SQL
- Oracle SQL語句優化之UNIONOracleSQL優化
- SQLServer效能優化之改寫SQL語句SQLServer優化
- SQL語句優化SQL優化
- ORACLE SQL語句優化技術分析OracleSQL優化
- SQL Server優化之SQL語句優化SQLServer優化
- MySQL 52個SQL效能優化策略SQL語句彙總MySql優化
- merge語句導致的效能問題緊急優化優化
- ORACLE SQL語句優化技術分析(zt)OracleSQL優化
- ORACLE SQL語句優化技術分析(轉)OracleSQL優化
- MYSQL SQL語句優化MySql優化
- SQL語句的優化SQL優化
- 求助:SQL語句優化SQL優化
- 利用Oracle 10g SQL優化器(STA)優化語句Oracle 10gSQL優化
- sql語句執行順序與效能優化(1)SQL優化
- Mysql 52條SQL語句效能優化策略彙總MySql優化
- 優化SQL查詢:如何寫出高效能SQL語句優化SQL
- 效能優化查詢語句優化
- oracle資料庫:耗cpu sql語句優化Oracle資料庫SQL優化
- Oracle SQL效能優化OracleSQL優化
- 對sql語句的最佳化問題SQL
- MySQL之SQL語句優化MySql優化
- SQL語句優化(轉載)SQL優化
- 常用SQL語句優化技巧SQL優化
- SQL 語句的優化方法SQL優化
- jivejdon sql語句問題SQL
- SQL Server 2008 優化MERGE語句效能SQLServer優化
- 【效能優化】查詢繫結變數的sql語句優化變數SQL
- oracle優化sql語句的一些建議Oracle優化SQL
- ORACLE優化SQL語句,提高效率(1)Oracle優化SQL
- ORACLE優化SQL語句,提高效率(2)Oracle優化SQL
- ORACLE優化SQL語句,提高效率(3)Oracle優化SQL
- 使用SQL調整顧問進行語句優化SQL優化
- 一個SQL效能問題的優化探索SQL優化
- Oracle效能優化-SQL優化(案例一)Oracle優化SQL