differenct between count(0), count(1) and count(*)[哪个执行速度快?]
来源:互联网 发布:温州动车事故真相知乎 编辑:程序博客网 时间:2024/05/14 03:58
Counting records
Over the years, there have been many debates regarding what is the optimal wayto count a selection of records from a table. Without going into the largehistory of this topic, different versions of Oracle mandated different approachesto best counting records.
However, in the more recent releases of Oracle, the fast full index scan (bitmapespecially) has generally become the most prudent way to count the records. Thankfully, under the cost optimiser, Oracle now performs this for most of combinations of "count(*)"that DBA's have advocated in the past, thus any of them will perform equivalently as canbe seen from the examples below
Example with indexed table
SQL> select count(*) from PURCHASED_VEHICLES; COUNT(*)---------- 283761Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=247 Card=1) 1 0 SORT (AGGREGATE) 2 1 INDEX (FAST FULL SCAN) OF 'PUVE_VEFE_MODEL_I' (NON-UNIQU E) (Cost=247 Card=283761)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 2583 consistent gets 4 physical reads 0 redo size 369 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processedSQL> select count(1) from PURCHASED_VEHICLES; COUNT(1)---------- 283761Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=247 Card=1) 1 0 SORT (AGGREGATE) 2 1 INDEX (FAST FULL SCAN) OF 'PUVE_VEFE_MODEL_I' (NON-UNIQU E) (Cost=247 Card=283761)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 2583 consistent gets 4 physical reads 0 redo size 369 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processedSQL> select count(rowid) from PURCHASED_VEHICLES;COUNT(ROWID)------------ 283761Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=247 Card=1 Bytes=7) 1 0 SORT (AGGREGATE) 2 1 INDEX (FAST FULL SCAN) OF 'PUVE_VEFE_MODEL_I' (NON-UNIQU E) (Cost=247 Card=283761 Bytes=1986327)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 2583 consistent gets 3 physical reads 0 redo size 373 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processedSQL> select count(id) from PURCHASED_VEHICLES; -- indexed colCOUNT(ID)--------- 283761Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=247 Card=1 Bytes=7) 1 0 SORT (AGGREGATE) 2 1 INDEX (FAST FULL SCAN) OF 'PUVE_VEFE_MODEL_I' (NON-UNIQU E) (Cost=247 Card=283761 Bytes=1986327)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 2583 consistent gets 3 physical reads 0 redo size 373 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed
Example with unindexed table
SQL> select count(*) from PURCHASED_VEHICLES; COUNT(*)---------- 283761Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=11952 Card=1) 1 0 SORT (AGGREGATE) 2 1 TABLE ACCESS (FULL) OF 'PURCHASED_VEHICLES_JN' (Cost=119 52 Card=459871)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 126734 consistent gets 126569 physical reads 0 redo size 369 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processedSQL> select count(1) from PURCHASED_VEHICLES_JN; COUNT(1)---------- 478957Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=11952 Card=1) 1 0 SORT (AGGREGATE) 2 1 TABLE ACCESS (FULL) OF 'PURCHASED_VEHICLES_JN' (Cost=119 52 Card=459871)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 126734 consistent gets 126569 physical reads 0 redo size 369 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processedSQL> select count(rowid) from PURCHASED_VEHICLES_JN; COUNT(ROWID)-------------- 478957Execution Plan---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=11952 Card=1) 1 0 SORT (AGGREGATE) 2 1 TABLE ACCESS (FULL) OF 'PURCHASED_VEHICLES_JN' (Cost=119 52 Card=459871)Statistics---------------------------------------------------------- 0 recursive calls 4 db block gets 126734 consistent gets 126569 physical reads 0 redo size 369 bytes sent via SQL*Net to client 424 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed参见:http://oracledba.co.uk/tips/count_speed.htm=========================================================================================================differenct between count(0), count(1) and count(*)...???
Hi,Please clarify the difference b/w count(0), count(1) and count(*)...???.SQL> set timing onSQL> select count(0) from trade2 /COUNT(0)----------112158506Elapsed: 00:00:03.08SQL> edWrote file afiedt.buf1* select count(1) from tradeSQL> /COUNT(1)----------112158506Elapsed: 00:00:02.01SQL> edWrote file afiedt.buf1* select count(*) from tradeSQL> /COUNT(*)----------112158506Elapsed: 00:00:02.03SQL> Is there any differences??ThanksSATHYA
https://community.oracle.com/thread/523654?tstart=0
count(0) count(*) 区别 谷歌
oracle count 0 谷歌
count 0 vs count - Google 搜索
0 0
- differenct between count(0), count(1) and count(*)[哪个执行速度快?]
- count(1) and count(*)
- count(),count(1),count(*)
- sql count执行速度测试
- count(*),count(1),count(0)效率
- sql中count(0),count(1),count(),count(列名)
- difference between count(*) and count(col) in the query
- count(1)、count(*)与count(列名)的执行区别
- Count
- COUNT
- count
- Count
- count
- count
- count
- count
- Count
- count
- 工具库篇
- HTTP关于表单请求的基础知识讲解
- 什么是MEAN全堆栈javascript开发框架
- Android 带清空按钮的EditText
- windows 驱动开发工具
- differenct between count(0), count(1) and count(*)[哪个执行速度快?]
- 第二章(线性表之顺序存储)
- Luci实现框架
- [LeetCode]Copy List with Random Pointer &Clone Graph 复杂链表的复制&图的复制
- 个性化控件(View)篇
- FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?
- Regular Expression Matching
- (windows编程 学习笔记二) 结构化异常处理(异常处理程序和软件异常)
- 优秀项目篇