count(*)与count(1)有区别吗?

一直以为sql中count(*)会比count(1)更消耗资源,今天实际分析比较下发现其实是一样的!

先看count(*):


[oracle@single bdump]$ sqlplus '/as sysdba'


SQL*Plus: Release 9.2.0.4.0 - Production on Sat Mar 21 10:21:21 2009


Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to an idle instance.


idle>startup
ORACLE instance started.


Total System Global Area  120017880 bytes
Fixed Size                   451544 bytes
Variable Size              67108864 bytes
Database Buffers           50331648 bytes
Redo Buffers                2125824 bytes
Database mounted.
Database opened.
idle>set autot on
idle>select count(*) from scott.test;


  COUNT(*)
----------
    282912




Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT ptimizer=CHOOSE
   1    0   SORT (AGGREGATE)
   2    1     TABLE ACCESS (FULL) OF 'TEST'


 




Statistics
----------------------------------------------------------
        164  recursive calls
          0  db block gets
       3462  consistent gets
       3439  physical reads
          0  redo size
        381  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          1  rows processed




再看count(1):


SQL*Plus: Release 9.2.0.4.0 - Production on Sat Mar 21 10:22:29 2009


Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to an idle instance.


idle>startup
ORACLE instance started.


Total System Global Area  120017880 bytes
Fixed Size                   451544 bytes
Variable Size              67108864 bytes
Database Buffers           50331648 bytes
Redo Buffers                2125824 bytes
Database mounted.
Database opened.
idle>set autot on
idle>select count(1) from scott.test;


  COUNT(1)
----------
    282912




Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT ptimizer=CHOOSE
   1    0   SORT (AGGREGATE)
   2    1     TABLE ACCESS (FULL) OF 'TEST'


 




Statistics
----------------------------------------------------------
        164  recursive calls
          0  db block gets
       3462  consistent gets
       3439  physical reads
          0  redo size
        381  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
          1  rows processed


二者的资源消耗是一致的,没看出有多大区别。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值