QUOTE:
原帖由
iso90000 于 2008-4-24 10:00 发表

I always thought use_hash('table') means the 'table' is the build table, i.e. the table whose joined columns are hashed into memory (or spilled to temp segment if hash area is too small 我用个例子来表明我对这句话的理解
eg1:
select /*+use_hash(a)*/ * from a,b where a.id1=b.id1;
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=409 Bytes=212
68)
1 0 HASH JOIN (Cost=5 Card=409 Bytes=21268)
2 1 TABLE ACCESS (FULL) OF 'B' (Cost=2 Card=82 Bytes=2132)
3 1 TABLE ACCESS (FULL) OF 'A' (Cost=2 Card=409 Bytes=10634)
use_hash(a)表明将表a在内存中根据连接键建立hash table,扫描表b并探测刚建成的hash table,找出与hash table匹配
的行(然后扫描表b,每读到一条记录就来探测hash表一次,找出与hash表匹配的行)。
执行顺序:扫描表b(驱动表),并通过hash算法探测刚建成的hash table(由表a建立的),找出匹配的行
eg2:
如果想已表a在内存中建立的hash table为驱动表
SQL> select /*+ordered use_hash(a)*/ * from a,b where a.id1=b.id1;
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=409 Bytes=212
68)
1 0 HASH JOIN (Cost=5 Card=409 Bytes=21268)
2 1 TABLE ACCESS (FULL) OF 'A' (Cost=2 Card=409 Bytes=10634)
3 1 TABLE ACCESS (FULL) OF 'B' (Cost=2 Card=82 Bytes=2132)
这2种方式有区别吗?
ps:在eygle的9i Performance Tuning Guide 读书笔记一中有这样一句
Execution Expain 中在上面的是先被扫描的小表,用作建立 hash table,在下的是大表。这好像与我想的eg1就有出入了,按照这个理解就是表b在内存中建立了hash table.