Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

2135

积分

502

好友

184

主题
1#
发表于 2013-1-9 22:07:29 | 查看: 4124| 回复: 1
简述一个HASH JOIN的处理过程
  1. SQL> select * from v$version;

  2. BANNER
  3. ----------------------------------------------------------------
  4. Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
  5. PL/SQL Release 10.2.0.5.0 - Production
  6. CORE    10.2.0.5.0      Production
  7. TNS for Linux: Version 10.2.0.5.0 - Production
  8. NLSRTL Version 10.2.0.5.0 - Production


  9. alter system flush buffer_cache;

  10. alter session set events '10104 trace name context forever, level 2 : 10046 trace name context forever,level 8';



  11. select /*+ USE_HASH(E D) */ D.LOC
  12. from scott.emp E,scott.dept D
  13. where
  14. E.SAL>=200 and E.DEPTNO=D.DEPTNO;



  15. Execution Plan
  16. ----------------------------------------------------------
  17. Plan hash value: 615168685

  18. ---------------------------------------------------------------------------
  19. | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
  20. ---------------------------------------------------------------------------
  21. |   0 | SELECT STATEMENT   |      |    14 |   252 |     7  (15)| 00:00:01 |
  22. |*  1 |  HASH JOIN         |      |    14 |   252 |     7  (15)| 00:00:01 |
  23. |   2 |   TABLE ACCESS FULL| DEPT |     4 |    44 |     3   (0)| 00:00:01 |
  24. |*  3 |   TABLE ACCESS FULL| EMP  |    14 |    98 |     3   (0)| 00:00:01 |
  25. ---------------------------------------------------------------------------

  26. Predicate Information (identified by operation id):
  27. ---------------------------------------------------

  28.    1 - access("E"."DEPTNO"="D"."DEPTNO")
  29.    3 - filter("E"."SAL">=200)
  30.    
  31.    
  32.    Statistics
  33. ----------------------------------------------------------
  34.           0  recursive calls
  35.           0  db block gets
  36.          15  consistent gets
  37.           0  physical reads
  38.           0  redo size
  39.         712  bytes sent via SQL*Net to client
  40.         492  bytes received via SQL*Net from client
  41.           2  SQL*Net roundtrips to/from client
  42.           0  sorts (memory)
  43.           0  sorts (disk)
  44.          14  rows processed



  45.      1* select object_name from dba_objects where object_id=51573
  46. SQL> /

  47. OBJECT_NAME
  48. --------------------------------------------------------------------------------
  49. DEPT

  50. SQL> select object_name from dba_objects where object_id=51575;

  51. OBJECT_NAME
  52. --------------------------------------------------------------------------------
  53. EMP



  54. SQL> select count(*) from scott.dept;

  55.   COUNT(*)
  56. ----------
  57.          4

  58.    
  59.    
  60. 执行步骤:

  61. 1.

  62.    WAIT #1: nam='db file sequential read' ela= 48 file#=4 block#=11 blocks=1 obj#=51573 tim=1325917491675207
  63. WAIT #1: nam='db file scattered read' ela= 75 file#=4 block#=12 blocks=5 obj#=51573 tim=1325917491675589

  64. 51573  =》51573   先对DEPT表(BUILD TABLE)做全表扫描,无过滤和access, 如ID2



  65. 2.

  66. HASH JOIN BUILD HASH TABLE (PHASE 1) ***

  67. DEPT 共4行数据,共分成8个bucket


  68. 3,
  69. WAIT #1: nam='db file sequential read' ela= 32 file#=4 block#=27 blocks=1 obj#=51575 tim=1325917491676541
  70. WAIT #1: nam='db file scattered read' ela= 49 file#=4 block#=28 blocks=5 obj#=51575 tim=1325917491676748


  71. 51575=> EMP 全表扫描EMP探测表(probe table), 并过滤filter("E"."SAL">=200)


  72. 4.
  73. FETCH #1:c=2999,e=3355,p=12,cr=14,cu=0,mis=0,r=1,dep=0,og=1,tim=1325917491677239   ==》 返回1行
  74. FETCH #1:c=0,e=151,p=0,cr=1,cu=0,mis=0,r=13,dep=0,og=1,tim=1325917491678051        ==》 返回13行


  75. 共返回14行数据,注意




  76. 不要孤立的看步骤3和步骤4, 实际运行时探测表 扫描一部分 就会做一部分的HASH JOIN 并返回一部分的数据。




  77.    
  78.    

  79. =====================
  80. PARSING IN CURSOR #1 len=102 dep=0 uid=0 oct=3 lid=0 tim=1325917491673381 hv=3195267918 ad='a38af540'
  81. select /*+ USE_HASH(E D) */ D.LOC
  82. from scott.emp E,scott.dept D
  83. where
  84. E.SAL>=200 and E.DEPTNO=D.DEPTNO
  85. END OF STMT
  86. PARSE #1:c=3000,e=3091,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=1325917491673369
  87. EXEC #1:c=0,e=112,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1325917491673735
  88. WAIT #1: nam='SQL*Net message to client' ela= 9 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1325917491673812
  89. kxhfInit(): enter
  90. kxhfInit(): exit
  91. *** RowSrcId: 1 HASH JOIN STATISTICS (INITIALIZATION) ***
  92. Join Type: INNER join
  93. Original hash-area size: 4665563
  94. Memory for slot table: 2949120
  95. Calculated overhead for partitions and row/slot managers: 1716443
  96. Hash-join fanout: 8


  97. Number of partitions: 8
  98. Number of slots: 24
  99. Multiblock IO: 15
  100. Block size(KB): 8
  101. Cluster (slot) size(KB): 120
  102. Minimum number of bytes per block: 8160
  103. Bit vector memory allocation(KB): 128
  104. Per partition bit vector length(KB): 16
  105. Maximum possible row length: 48
  106. Estimated build size (KB): 0
  107. Estimated Build Row Length (includes overhead): 27
  108. # Immutable Flags:
  109.   Not BUFFER(execution) output of the join for PQ
  110.   Evaluate Left Input Row Vector
  111.   Evaluate Right Input Row Vector
  112. # Mutable Flags:
  113.   IO sync
  114. kxhfSetPhase: phase=BUILD
  115. WAIT #1: nam='db file sequential read' ela= 48 file#=4 block#=11 blocks=1 obj#=51573 tim=1325917491675207
  116. WAIT #1: nam='db file scattered read' ela= 75 file#=4 block#=12 blocks=5 obj#=51573 tim=1325917491675589
  117. kxhfAddChunk: add chunk 0 (sz=32) to slot table
  118. kxhfAddChunk: chunk 0 (lbs=0x7f5e9ff28b20, slotTab=0x7f5e9ff28ce8) successfuly added
  119. kxhfSetPhase: phase=PROBE_1
  120. qerhjFetch: max build row length (mbl=20)
  121. *** RowSrcId: 1 END OF BUILD (PHASE 1) ***
  122.   Revised row length: 19
  123.   Revised build size: 0KB
  124. kxhfResize(enter): resize to 12 slots (numAlloc=4, max=24)



  125. kxhfResize(exit): resized to 12 slots (numAlloc=4, max=12)
  126.   Slot table resized: old=24 wanted=12 got=12 unload=0
  127. *** RowSrcId: 1 HASH JOIN RESIZE BUILD (PHASE 1) ***
  128. Total number of partitions: 8
  129. Number of partitions which could fit in memory: 8
  130. Number of partitions left in memory: 8
  131. Total number of slots in in-memory partitions: 4
  132. kxhfResize(enter): resize to 10 slots (numAlloc=4, max=12)
  133. kxhfResize(exit): resized to 10 slots (numAlloc=4, max=10)
  134.   set work area size to: 2651K (10 slots)
  135. WAIT #1: nam='db file sequential read' ela= 32 file#=4 block#=27 blocks=1 obj#=51575 tim=1325917491676541
  136. WAIT #1: nam='db file scattered read' ela= 49 file#=4 block#=28 blocks=5 obj#=51575 tim=1325917491676748
  137. *** RowSrcId: 1 HASH JOIN BUILD HASH TABLE (PHASE 1) ***
  138. Total number of partitions: 8
  139. Number of partitions left in memory: 8
  140. Total number of rows in in-memory partitions: 4
  141.    (used as preliminary number of buckets in hash table)
  142. Estimated max # of build rows that can fit in avail memory: 122700
  143. ### Partition Distribution ###
  144. Partition:0    rows:1          clusters:1      slots:1      kept=1
  145. Partition:1    rows:0          clusters:0      slots:0      kept=1
  146. Partition:2    rows:1          clusters:1      slots:1      kept=1
  147. Partition:3    rows:0          clusters:0      slots:0      kept=1
  148. Partition:4    rows:0          clusters:0      slots:0      kept=1
  149. Partition:5    rows:1          clusters:1      slots:1      kept=1
  150. Partition:6    rows:0          clusters:0      slots:0      kept=1
  151. Partition:7    rows:1          clusters:1      slots:1      kept=1
  152. *** (continued) HASH JOIN BUILD HASH TABLE (PHASE 1) ***
  153. Revised number of hash buckets (after flushing): 4
  154. Allocating new hash table.
  155. *** (continued) HASH JOIN BUILD HASH TABLE (PHASE 1) ***
  156. Requested size of hash table: 1
  157. Actual size of hash table: 8


  158. Number of buckets: 8
  159. Match bit vector allocated: FALSE
  160. *** (continued) HASH JOIN BUILD HASH TABLE (PHASE 1) ***
  161. Total number of rows (may have changed): 4
  162. Number of in-memory partitions (may have changed): 8
  163. Final number of hash buckets: 8
  164. Size (in bytes) of hash table: 64
  165. qerhjBuildHashTable(): done hash-table on partition=7, index=4 last_slot#=0 rows=1 total_rows=1
  166. qerhjBuildHashTable(): done hash-table on partition=5, index=5 last_slot#=3 rows=1 total_rows=2
  167. qerhjBuildHashTable(): done hash-table on partition=2, index=6 last_slot#=1 rows=1 total_rows=3
  168. qerhjBuildHashTable(): done hash-table on partition=0, index=7 last_slot#=2 rows=1 total_rows=4
  169. kxhfIterate(end_iterate): numAlloc=4, maxSlots=10
  170. *** (continued) HASH JOIN BUILD HASH TABLE (PHASE 1) ***
  171. ### Hash table ###
  172. # NOTE: The calculated number of rows in non-empty buckets may be smaller
  173. #       than the true number.
  174. Number of buckets with   0 rows:          4
  175. Number of buckets with   1 rows:          4
  176. Number of buckets with   2 rows:          0
  177. Number of buckets with   3 rows:          0
  178. Number of buckets with   4 rows:          0
  179. Number of buckets with   5 rows:          0
  180. Number of buckets with   6 rows:          0
  181. Number of buckets with   7 rows:          0
  182. Number of buckets with   8 rows:          0
  183. Number of buckets with   9 rows:          0
  184. Number of buckets with between  10 and  19 rows:          0
  185. Number of buckets with between  20 and  29 rows:          0


  186. Number of buckets with between  30 and  39 rows:          0
  187. Number of buckets with between  40 and  49 rows:          0
  188. Number of buckets with between  50 and  59 rows:          0
  189. Number of buckets with between  60 and  69 rows:          0
  190. Number of buckets with between  70 and  79 rows:          0
  191. Number of buckets with between  80 and  89 rows:          0
  192. Number of buckets with between  90 and  99 rows:          0
  193. Number of buckets with 100 or more rows:          0
  194. ### Hash table overall statistics ###
  195. Total buckets: 8 Empty buckets: 4 Non-empty buckets: 4
  196. Total number of rows: 4
  197. Maximum number of rows in a bucket: 1
  198. Average number of rows in non-empty buckets: 1.000000
  199. FETCH #1:c=2999,e=3355,p=12,cr=14,cu=0,mis=0,r=1,dep=0,og=1,tim=1325917491677239
  200. WAIT #1: nam='SQL*Net message from client' ela= 511 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917491677839
  201. WAIT #1: nam='SQL*Net message to client' ela= 8 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917491677937
  202. qerhjFetch: max probe row length (mpl=0)
  203. *** RowSrcId: 1, qerhjFreeSpace(): free hash-join memory
  204. kxhfRemoveChunk: remove chunk 0 from slot table
  205. FETCH #1:c=0,e=151,p=0,cr=1,cu=0,mis=0,r=13,dep=0,og=1,tim=1325917491678051
  206. *** 2013-01-09 08:51:58.996
  207. WAIT #1: nam='SQL*Net message from client' ela= 7341414 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917499019584
  208. STAT #1 id=1 cnt=14 pid=0 pos=1 obj=0 op='HASH JOIN  (cr=15 pr=12 pw=0 time=3364 us)'
  209. STAT #1 id=2 cnt=4 pid=1 pos=1 obj=51573 op='TABLE ACCESS FULL DEPT (cr=7 pr=6 pw=0 time=1334 us)'
  210. STAT #1 id=3 cnt=14 pid=1 pos=2 obj=51575 op='TABLE ACCESS FULL EMP (cr=8 pr=6 pw=0 time=374 us)'
  211. WAIT #0: nam='SQL*Net message to client' ela= 24 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917499019933
  212. WAIT #0: nam='SQL*Net message from client' ela= 3073598 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917502093832
  213. WAIT #0: nam='SQL*Net message to client' ela= 10 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917502093935
  214. WAIT #0: nam='SQL*Net message from client' ela= 3006627 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917505100616
  215. WAIT #0: nam='SQL*Net message to client' ela= 11 driver id=1650815232 #bytes=1 p3=0 obj#=51575 tim=1325917505100737

复制代码
================================》



   
执行步骤:

1.

   WAIT #1: nam='db file sequential read' ela= 48 file#=4 block#=11 blocks=1 obj#=51573 tim=1325917491675207
WAIT #1: nam='db file scattered read' ela= 75 file#=4 block#=12 blocks=5 obj#=51573 tim=1325917491675589

51573  =》51573   先对DEPT表(BUILD TABLE)做全表扫描,无过滤和access, 如ID2



2.

HASH JOIN BUILD HASH TABLE (PHASE 1) ***

DEPT 共4行数据,共分成8个bucket


3,
WAIT #1: nam='db file sequential read' ela= 32 file#=4 block#=27 blocks=1 obj#=51575 tim=1325917491676541
WAIT #1: nam='db file scattered read' ela= 49 file#=4 block#=28 blocks=5 obj#=51575 tim=1325917491676748


51575=> EMP 全表扫描EMP探测表(probe table), 并过滤filter("E"."SAL">=200)


4.
FETCH #1:c=2999,e=3355,p=12,cr=14,cu=0,mis=0,r=1,dep=0,og=1,tim=1325917491677239   ==》 返回1行
FETCH #1:c=0,e=151,p=0,cr=1,cu=0,mis=0,r=13,dep=0,og=1,tim=1325917491678051        ==》 返回13行


共返回14行数据,注意




不要孤立的看步骤3和步骤4, 实际运行时探测表 扫描一部分 就会做一部分的HASH JOIN 并返回一部分的数据。
下载专业ORACLE数据库恢复工具PRM-DUL  For Oracle http://www.parnassusdata.com/zh-hans/emergency-services

如果自己搞不定可以找诗檀软件专业ORACLE数据库修复团队成员帮您恢复!

诗檀软件专业数据库修复团队

服务热线 : 13764045638  QQ: 47079569   
2#
发表于 2013-1-10 10:20:14
咋一看,有点不明白。做做实验看看。。。

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-12-20 13:32 , Processed in 0.049037 second(s), 24 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569