SQL> create table tt(
A VARCHAR2(23),
B VARCHAR2(33)
);
SQL>insert into tt ('a','c');
SQL>insert into tt ('a','c');
SQL>insert into tt ('a',null);
SQL> select * from tt;
A B
---------------------------------------------- ---------
a c
a c
a
SQL> select count(b) from tt;
COUNT(B)
----------
2
SQL> select count(*) from tt;
COUNT(*)
----------
3
SQL> select count(a) from tt;
COUNT(A)
----------
3
SQL> select count(1) from tt;
COUNT(1)
----------
3
如果表中没有主键,那么count(1)比count(*)快
如果有主键,那么count(主键,联合主键)比count(*)快
如果表中只有一个字段,count(*)最快
count() 不会计算 null
A VARCHAR2(23),
B VARCHAR2(33)
);
SQL>insert into tt ('a','c');
SQL>insert into tt ('a','c');
SQL>insert into tt ('a',null);
SQL> select * from tt;
A B
---------------------------------------------- ---------
a c
a c
a
SQL> select count(b) from tt;
COUNT(B)
----------
2
SQL> select count(*) from tt;
COUNT(*)
----------
3
SQL> select count(a) from tt;
COUNT(A)
----------
3
SQL> select count(1) from tt;
COUNT(1)
----------
3
如果表中没有主键,那么count(1)比count(*)快
如果有主键,那么count(主键,联合主键)比count(*)快
如果表中只有一个字段,count(*)最快
count() 不会计算 null
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/129556/viewspace-269305/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/129556/viewspace-269305/