scalar subqueries vs. joins
286397Apr 9 2003 — edited Apr 15 2003Hi,
is someone able to tell me something about the impact on performance of scalar subqueries in select list?
I found that scalar subqueries are processed faster than joins but don't understand why.
E.g. first statement:
select e.ename, d.deptno,
(select dname from dept d where d.deptno=e.deptno) dname from emp e
where e.deptno =10;
Second statement:
select e.ename, d.deptno, d.dname
from emp e, dept.d
where e.deptno=d.deptno and d.deptno=10;
The optimizer calculates the first statement using a full table scan on emp, while the second statement using a nested loop join.
First statement is executed faster. I found also that the first staement is executed more for throughput, the second for answer time.
This is the behavior not only if there are thousands of lines in emp but also in real life applications.
Regards Frank