外连接和使用Oracle索引

时间:2016-06-01 00:00:13

标签: sql oracle

SELECT  * 
FROM  t1,  t2 , t3
WHERE t1.row_id = t2.invoice_id(+)
and t2.voi_id = t3.row_id(+)
and type = 'Dec'
order by 1

我有3个索引,一个用于连接中的每一列,但似乎解释计划在不使用索引的情况下对表使用全表扫描:

计划

1 Every row in the table t1  is read.
2 The rows were sorted to support the join at step 5.
3 Every row in the table t2  is read.
4 The rows were sorted to support the join at step 5.
5 Join the sorted results sets provided from steps 2, 4.
6 Rows were returned by the SELECT statement.

1 个答案:

答案 0 :(得分:0)

这取决于行的计数和表的大小。在您的查询中,将获取所有行t1(因为使用了左连接,并且将显示来自t1的所有行,其中type ='Dec')。这就是为什么 TABLE ACCESS FULL 到表t1是正常的。

如果t1中的rowcount在t2中超过20-30%rowcount(%取决于t2大小), TABLE ACCESS FULL 到t2并且他们的散列连接是正常的场景。