来自农村的老实娃
分类: Oracle
2011-08-03 14:23:46
为了全面理解 Oracle RAC 环境中结果缓存特性的行为,先讨论前两种方法然后再深入讨论结果缓存一定会很有意思。
在一个四节点集群中(图 2),在实例 1 (SSKY1) 中执行查询时,如 10046 跟踪输出所示,通过对 ORDERS 和 ORDER_LINE 这两个表进行索引快速全扫描来执行查询。该操作从磁盘(物理 I/O)读取 345,361 个数据块,并执行另外 345,447 个逻辑 I/O 操作。最终结果集为 300 行,随后将发回给用户。
注意:10046 跟踪可使用 - alter session set events '10046 trace name context forever, level 12' 启用,可使用 - alter session set events '10046 trace name context off' 禁用。将在参数 user_dump_dest 定义的位置生成跟踪输出。
SELECT OL_W_ID, OL_D_ID, OL_NUMBER, sum(OL_AMOUNT),sum(OL_QUANTITY)
FROM
ORDER_LINE OL, ORDERS ORD WHERE OL.OL_O_ID = ORD.O_ID AND OL.OL_W_ID =
ORD.O_W_ID AND OL.OL_D_ID = ORD.O_D_ID GROUP BY OL_NUMBER, OL_W_ID,OL_D_ID
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.01 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 21 18.42 77.41 345361 345447 0 300
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 23 18.43 77.42 345361 345447 0 300
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 89 (schema name)
Rows Row Source Operation
------- ---------------------------------------------------
300 HASH GROUP BY (cr=345447 pr=345361 pw=0 time=149 us cost=126413 size=4950 card=150)
21349787 HASH JOIN (cr=345447 pr=345361 pw=0 time=59061480 us cost=125703 size=680920944 card=20633968)
2134685 INDEX FAST FULL SCAN ORDERS_I2 (cr=11248 pr=11219 pw=0 time=258291 us cost=2743 size=22694870 card=2063170)(object id 86234)
21349787 INDEX FAST FULL SCAN IORDL (cr=334199 pr=334142 pw=0 time=47799580 us cost=87415 size=453947296 card=20633968)(object id 86202)
如果此查询是在实例 2 (SSKY2) 上执行的,将再次执行完整的操作(执行计划完全相同),包括物理 I/O 和逻辑操作在内,之后将获得 300 行的完整结果。
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.01 0.01 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 21 31.74 74.34 345361 345447 0 300
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 23 31.76 74.36 345361 345447 0 300
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 89 (schema name)
Rows Row Source Operation
------- ---------------------------------------------------
300 HASH GROUP BY (cr=345447 pr=345361 pw=0 time=299 us cost=126413 size=4950 card=150)
21349787 HASH JOIN (cr=345447 pr=345361 pw=0 time=62985040 us cost=125703 size=680920944 card=20633968)
2134685 INDEX FAST FULL SCAN ORDERS_I2 (cr=11248 pr=11219 pw=0 time=490345 us cost=2743 size=22694870 card=2063170)(object id 86234)
21349787 INDEX FAST FULL SCAN IORDL (cr=334199 pr=334142 pw=0 time=42913972 us cost=87415 size=453947296 card=20633968)(object id 86202)
分析来自两个实例的跟踪输出和下面列出的等待事件,我们注意到,不存在数据的缓存同步。如前所述,Oracle Database 11g 第 2 版 RAC 中的情况是全新的(不同于 Oracle Database 10g),本地 I/O 操作(bypass reader 算法)将更有益,因为避免了通过互连传输数据。
实例 1 (SSKY1) |
|
实例 2 (SSKY2) |
|
其上等待的事件 |
等待 |
其上等待的事件 |
等待 |
-------------------------------- |
时间 |
------------------------------ |
时间 |
ges message buffer allocation |
466 |
ges message buffer allocation |
135 |
library cache lock |
2 |
library cache pin |
2 |
row cache lock |
14 |
row cache lock |
18 |
SQL*Net message to client |
21 |
SQL*Net message to client |
21 |
Disk file operations I/O |
3 |
Disk file operations I/O |
1 |
os thread startup |
1 |
os thread startup |
1 |
KSV master wait |
2 |
KSV master wait |
2 |
ASM file metadata operation |
1 |
ASM file metadata operation |
1 |
db file sequential read |
6 |
db file sequential read |
6 |
db file parallel read |
1 |
db file parallel read |
96 |
db file scattered read |
2762 |
db file scattered read |
2667 |
asynch descriptor resize |
1 |
asynch descriptor resize |
1 |
gc current grant busy |
206 |
|
|
gc cr block 2-way |
50 |
gc cr block 2-way |
21 |
SQL*Net message from client |
21 |
SQL*Net message from client |
21 |
|
|
gc cr multi block request |
112 |
|
|
gc cr block 3-way |
22 |
在一个使用 Oracle Database 10g 第 2 版的类似的四节点 Oracle RAC 集群中,执行前述查询时,集群中实例间将存在大量缓存同步。
实例 1:
10g 第 2 版数据库中查询生成的执行计划表明,该查询执行了约 214,682 次磁盘 I/O 操作和 42,907,485 次逻辑 I/O 操作才生成 300 行的结果集。
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.01 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 21 248.08 288.49 214682 42907485 0 300
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 23 248.09 288.51 214682 42907485 0 300
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 462 (TPCC)
Rows Row Source Operation
------- ---------------------------------------------------
300 HASH GROUP BY (cr=42907485 pr=214682 pw=0 time=288494487 us)
21349787 NESTED LOOPS (cr=42907485 pr=214682 pw=0 time=320320093 us)
21349787 INDEX FULL SCAN IORDL (cr=207908 pr=208355 pw=0 time=85453357 us)(object id 616250)
21349787 INDEX UNIQUE SCAN ORDERS_I1 (cr=42699577 pr=6327 pw=0 time=156657073 us)(object id 616287)