-
1.) SELECT COUNT(DISTINCT deptno) FROM scott.emp;
2.) SELECT COUNT(deptno) FROM scott.emp GROUP BY deptno;
I did experiment on a large table (1M rows) with index on deptno.
Based on the explain plan output, the first statement executes faster than the 2nd one, the reason is the first one uses Fast Full Index Scan and it never uses table data. And the 2nd execution path uses INDEX scan.
Please note that if an index is not available on DEPTNO, then it will be a different story.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|