Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why a function within a SELECT FROM DUAL is faster?

612338Oct 6 2010 — edited Oct 8 2010
1)I have a SELECT with a function. Ex:
"SELECT DISTINCT function(...) FROM table"

2)I changed the SELECT and put the function inside a SUB-SELECT with FROM DUAL. Ex:
"SELECT DISTINCT (SELECT function(...) FROM DUAL) FROM table"

3)The second SELECT is faster than the first.

I discovered this problem on my tables and my functions. So I did a generic example for this forum with a common function and large table. My results:
Table has 2.196.058 records and the field is a VARCHAR2:
SELECT DISTINCT SUBSTR(field, 2) FROM Table -> Executed in 110 seconds
SELECT DISTINCT (SELECT SUBSTR(field, 2) FROM DUAL) FROM Table -> Executed in 39 seconds

Why "SELECT DISTINCT (SELECT function(...) FROM DUAL) FROM table" is faster than "SELECT DISTINCT function(...) FROM table"


thanks,

Fernando
This post has been answered by Hoek on Oct 7 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2010
Added on Oct 6 2010
16 comments
6,672 views