select TABLE1.FIELD1,
TABLE1.FIELD2,
TABLE1.FIELD3,
TABLE1.FIELD4,
TABLE1.FIELD5,
TABLE2.FIELD6,
TABLE2.FIELD7
from TABLE1,
TABLE2
where TABLE1.FIELD8 = 'value'
and TABLE2.FIELD6 = TABLE1.FIELD6;
I am looking for some data from two different tables. (Oracle database - fields indexed for both tables) The above query takes 500 ms to complete. When I look at the tables separately for the same fields, they end in less than 20 meters each.
I could look up TABLE1 for the data I need (+ FIELD6) and then find TABLE2 for the rest using FIELD6.
My question is. Why is it so slow when I join tables. Am I doing something wrong?
EDIT: adding oracle explanation plan
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 6318 | 586K| 620 |
| 1 | HASH JOIN | | 6318 | 586K| 620 |
| 2 | TABLE ACCESS BY INDEX ROWID| TABLE1 | 6318 | 450K| 2 |
| 3 | INDEX RANGE SCAN | INDEX_TABLE1_FIELD8 | 2527 | | 1 |
| 4 | TABLE ACCESS FULL | TABLE2 | 430K| 9242K| 508 |
Note: cpu costing is off, 'PLAN_TABLE' is old version
source
share