[转帖]update 与 物理读 引起的性能问题_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 4047 | 回复: 0   主题: [转帖]update 与 物理读 引起的性能问题        下一篇 
derek
注册用户
等级:中校
经验:1550
发帖:209
精华:0
注册:2011-7-21
状态:离线
发送短消息息给derek 加好友    发送短消息息给derek 发消息
发表于: IP:您无权察看 2011-9-2 14:18:06 | [全部帖] [楼主帖] 楼主

昨天数据库 io 忽然变的非常高,造成系统性能下降严重;经过排查发发现一个update操作的物理读竟然非常高;解决过程记录一下;下面的数据是进行的测试;

构造表一个测试表

scott@192.168.0.123:ORCL>select count(1) from emptest;
COUNT(1)
----------
14028


查看表的block数

scott@192.168.0.123:ORCL>select t.segment_name,t.bytes,t.blocks from dba_segments t where t.segment_name='EMPTEST';
SEGMENT_NA     BYTES    BLOCKS
---------- ---------- ----------
EMPTEST       786432        96


确保在buffer cache中没有相关的缓存:

scott@192.168.0.123:ORCL>alter system flush buffer_cache;


系统已更改。

查看全部扫描的执行计划:

scott@192.168.0.123:ORCL>alter system flush buffer_cache;


系统已更改。

scott@192.168.0.123:ORCL>set autot trace exp
scott@192.168.0.123:ORCL>select * from scott.emptest;


执行计划

----------------------------------------------------------
Plan hash value: 1471160681
-----------------------------------------------------------------------------
| Id | Operation        | Name   | Rows | Bytes | Cost (%CPU)| Time    |
-----------------------------------------------------------------------------
|  0 | SELECT STATEMENT |        | 14028 |  506K|   27  (4)| 00:00:01 |
|  1 | TABLE ACCESS FULL| EMPTEST | 14028 |  506K|   27  (4)| 00:00:01 |
-----------------------------------------------------------------------------


刷出buffer cache;

Alter system flush buffer_cache;


此时做update并查看执行计划

scott@192.168.0.123:ORCL>alter system flush buffer_cache;


系统已更改。

scott@192.168.0.123:ORCL>set autot off
scott@192.168.0.123:ORCL>set autot on
scott@192.168.0.123:ORCL>alter system flush buffer_cache;


系统已更改。

scott@192.168.0.123:ORCL>update scott.emptest set empno=9999 where rownum=1;


已更新1行。

执行计划

----------------------------------------------------------
Plan hash value: 2944935809
-------------------------------------------------------------------------------
| Id | Operation          | Name   | Rows | Bytes | Cost (%CPU)| Time    |
-------------------------------------------------------------------------------
|  0 | UPDATE STATEMENT   |        |    1 |   13 |   26  (0)| 00:00:01 |
|  1 | UPDATE            | EMPTEST |      |      |           |         |
|* 2 |  COUNT STOPKEY    |        |      |      |           |         |
|  3 |   TABLE ACCESS FULL| EMPTEST | 14028 |  178K|   26  (0)| 00:00:01 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(ROWNUM=1)


统计信息

----------------------------------------------------------
17 recursive calls
3 db block gets
8 consistent gets
9 physical reads
484 redo size
673 bytes sent via SQL*Net to client
586 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
scott@192.168.0.123:ORCL>


第二次再更新:

scott@192.168.0.123:ORCL>update scott.emptest set empno=9999 where rownum=1;


已更新1行。

执行计划

----------------------------------------------------------
Plan hash value: 2944935809
-------------------------------------------------------------------------------
| Id | Operation          | Name   | Rows | Bytes | Cost (%CPU)| Time    |
-------------------------------------------------------------------------------
|  0 | UPDATE STATEMENT   |        |    1 |   13 |   26  (0)| 00:00:01 |
|  1 | UPDATE            | EMPTEST |      |      |           |         |
|* 2 |  COUNT STOPKEY    |        |      |      |           |         |
|  3 |   TABLE ACCESS FULL| EMPTEST | 14028 |  178K|   26  (0)| 00:00:01 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(ROWNUM=1)


统计信息

----------------------------------------------------------
0 recursive calls
4 db block gets
4 consistent gets
0 physical reads
0 redo size
675 bytes sent via SQL*Net to client
586 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
scott@192.168.0.123:ORCL>
Select * from scott.emptest;


将所有block缓存:

已选择14028行。

执行计划

----------------------------------------------------------
Plan hash value: 1471160681
-----------------------------------------------------------------------------
| Id | Operation        | Name   | Rows | Bytes | Cost (%CPU)| Time    |
-----------------------------------------------------------------------------
|  0 | SELECT STATEMENT |        | 14028 |  506K|   27  (4)| 00:00:01 |
|  1 | TABLE ACCESS FULL| EMPTEST | 14028 |  506K|   27  (4)| 00:00:01 |
-----------------------------------------------------------------------------


统计信息

----------------------------------------------------------
0 recursive calls
0 db block gets
1021 consistent gets
83 physical reads
0 redo size
718562 bytes sent via SQL*Net to client
10670 bytes received via SQL*Net from client
937 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14028 rows processed


再次:

scott@192.168.0.123:ORCL>update scott.emptest set empno=9999 where rownum=1;


已更新1行。

执行计划

----------------------------------------------------------
Plan hash value: 2944935809
-------------------------------------------------------------------------------
| Id | Operation          | Name   | Rows | Bytes | Cost (%CPU)| Time    |
-------------------------------------------------------------------------------
|  0 | UPDATE STATEMENT   |        |    1 |   13 |   26  (0)| 00:00:01 |
|  1 | UPDATE            | EMPTEST |      |      |           |         |
|* 2 |  COUNT STOPKEY    |        |      |      |           |         |
|  3 |   TABLE ACCESS FULL| EMPTEST | 14028 |  178K|   26  (0)| 00:00:01 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(ROWNUM=1)


统计信息

----------------------------------------------------------
0 recursive calls
4 db block gets
4 consistent gets
0 physical reads
608 redo size
678 bytes sent via SQL*Net to client
586 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
scott@192.168.0.123:ORCL>


所以有缓存时会降低物理读;在某些情况下,可以使用keep pool,将全表缓存,以提升性能;





赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论