Skip to content

Instantly share code, notes, and snippets.

@xtender
Created January 17, 2013 17:10
Show Gist options
  • Save xtender/4557588 to your computer and use it in GitHub Desktop.
Save xtender/4557588 to your computer and use it in GitHub Desktop.
count(*) and count(1)
SQL> create table t_nulls as select cast(null as int) col_nulls from dual connect by level<=1e3;
Table created.
SQL> select count(*) from t_nulls;
COUNT(*)
----------
1000
1 row selected.
SQL> select count(1) from t_nulls;
COUNT(1)
----------
1000
1 row selected.
SQL> explain plan for select count(*) from t_nulls;
Explained.
SQL> @xplan
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------
Plan hash value: 2660291840
----------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T_NULLS | 1000 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=0) COUNT(*)[22]
SQL> explain plan for select count(1) from t_nulls;
Explained.
SQL> @xplan
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------
Plan hash value: 2660291840
----------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T_NULLS | 1000 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=0) COUNT(*)[22]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment