When you tune queries that access views, consider where you place the ORDERED optimizer directive. Two cases can affect join order when you use views:
CREATE VIEW emp_job_view as SELECT {+ORDERED} emp.job_num, job.job_name FROM emp, job WHERE emp.job_num = job.job_num;
The ORDERED directive specifies that the emp and job table are joined in that order. Because of the view definition, the emp and job tables must also be joined in exactly that order if you execute the following query:
SELECT * from dept, emp_job_view, project WHERE dept.dept_no = project.dept_num emp_job_view.job_num = project.job_num;
Any join order that places the emp table immediately before the job table is permitted, thus any of the following join orders might occur:
Consider a view defined as follows:
CREATE VIEW emp_job_view AS SELECT emp.job_num, job.job_name FROM emp, job WHERE emp.job_num = job.job_num;
If you run the following query against this view, the join order is dept, project, emp, job:
SELECT {+ORDERED} * FROM dept, project, emp_job_view WHERE dept.dept_no = project.dept_num AND emp_job_view.job_num = project.job_num;
If the view cannot be folded into the query, the database server executes the query against the view and stores the result in a temporary table. Consider the result of running the previous query against a view defined as follows:
CREATE VIEW emp_job_view2 AS SELECT DISTINCT emp.job_num, job.job_name FROM emp,job WHERE emp.job_num = job.job_num;
When the query is executed, the join order of tables is dept, project, temp_table.