select count(column_name) form table_name or select count(*) from table_Name
select count(column_name) form table_name or select count(*) from table_Name
ORACLEdatabasedbaselect select count(*) from table_name select count(column_name) form table_name
To calculate a table's row number, most programer think 'select count(*) from table_name' is not a patch on ' select count(column_name) form table_name'. Is it ?
example:
select count(*) from emp; Execution Plan ---------------------------------------------------------- Plan hash value: 2937609675 ------------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| Time | ------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | | | | 2 | INDEX FULL SCAN| PK_EMP | 14 | 1 (0)| 00:00:01 | ------------------------------------------------------------------- select count(ename) from emp; Execution Plan ---------------------------------------------------------- Plan hash value: 2083865914 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 6 | | | | 2 | TABLE ACCESS FULL| EMP | 14 | 84 | 3 (0)| 00:00:01 | ---------------------------------------------------------------------------
It is obviously see that the first sql need less cost of the oracle resource.
When we do select count(*) from table_name, oracle cbo will do a internal tuning which will select the most performance path to do that.