I need an explanation and an advice on the execution plan in Oracle.
I have 3 tables in my Oracle database:
- t (id, name, t1_id, t2_id)
- t1 (id, name)
- t2 (id, name)
id is a primary key in each table.
Table t has 13 000 000 rows, t1 has 4 000 000 rows and t2 has 1 000 000 rows.
The following query shows "hash join" in execution plan:
select
t.*
from t
left join t1 on t1.id = t.t1_id
But the same query with table t2 instead of t1 doesn't show "hash join" in execution plan (there is only "table access" of table t):
select
t.*
from t
left join t2 on t2.id = t.t2_id
In my opinion none of two queries should show "hash join" in execution plan because left join operation can not change the number of rows in the result set due to primary keys and we do not choose any of fields from t1 and t2 in the select statement. In case of table t2 it works good. Why the execution plan is different in case of table t1?
To make it more clear, I need a such behavior because in my real case there are tens of different left joins and different users of my BI will choose different set of fields. But no one will choose all fields. And I want Oracle to implement left joins only for those tables, which fields are choosen. If Oracle will implement all left joins it will be too long query.