QuestionQ193

VerifiedDisplaying Data from Multiple Tables

Consider the following three statements:

create view v1 as  
select department_id, department_name, last_name  
from departments join employees using (department_id);  
  
select department_name, last_name  
from v1  
where department_id = 20;  
  
select d.department_name, e.last_name  
from departments d, employees e  
where d.department_id = e.department_id  
and d.department_id = 20;  

Why will the first query be quicker than the second?

Explanation

An ordinary Oracle view is a stored query definition, not a precomputed join result. Oracle can merge the view query with the outer query and optimize the equivalent join and department_id = 20 predicate against the base tables. Neither ANSI versus legacy join notation nor view compilation inherently makes one of these equivalent queries faster.

Community Discussion

No comments yet. Be the first to start the discussion!