Assume I have two tables,
Student Test
Id Name TestId Score StudentId
-- ---- ------ ---- ---------
1 Mark 774 100 1
2 Sam 774 89 2
3 John 775 78 3
Now I have to print student name,test id and score of each student.
I know both of them produce the same results.But which one is better in terms of performance?Does the second one find cartesian product and then apply filter(where clause)?
1.Select test.testid,student.name,test.score
from student
join test
on test.studentid=student.id
2.Select test.testid,student.name,test.score
from student,test
where test.studentid=student.id
I’m not going to answer your question directly but rather provide you with a tool to solve such problems in the future.
Oracle offers ways to see how queries are executed. You can see how the access to your tables is performed, how much time a query execution takes, whether indexes are used or not, etc.
The commands are:
EXPLAIN PLAN
and
SET AUTOTRACE.
In your case, it would be as simple as this:
Or using autotrace:
In case of
EXPLAIN PLAN, the results are kept in a special table that you can query to see them. Check the documentation I linked to in order to see what can be done with it.