Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: count(*) v. count(pk)
Hi.
I run a number of test concerning the performance of COUNT(*) and a number of different options.
call count cpu elapsed disk query current rows ------ ----- -------- --------- --------- --------- --------- ---------
Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 10.89 20.94 41975 41975 0 1 ------ ------ -------- --------- --------- --------- --------- --------- total 3 10.89 20.94 41975 41975 0 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE 0 SORT (AGGREGATE)
B. select /*+ INDEX_FFS(XXX_TAB XXX_TAB$ID_NO ) */ count(ID_NO)
from XXX_TAB where ID_NO > 0
I tried to force FAST INDEX SCAN ( without success ).
call count cpu elapsed disk query current rows ------ ------ -------- --------- --------- --------- --------- ---------
Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 12.37 12.41 41919 41975 0 1 ------- ----- ------- --------- --------- --------- --------- --------- total 3 12.37 12.41 41919 41975 0 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE
C. select /*+ INDEX_FFS(XXX_TAB XXX_TAB$ID_NO ) */
count(*) from XXX_TAB XXX_TAB where ID_NO > 0
call count cpu elapsed disk query current rows ------ ------ -------- --------- --------- --------- --------- ---------
Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 11.19 12.34 41975 41975 0 1 ------- ----- ------- --------- --------- --------- --------- --------- total 3 11.19 12.34 41975 41975 0 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE 0 SORT (AGGREGATE)
D. select count(ID_NO) from XXX_TAB
call count cpu elapsed disk query current rows ------ ------ -------- --------- --------- --------- --------- ---------
Parse 1 0.00 0.01 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 6.45 6.45 39964 39965 2 1 ------- ----- -------- --------- --------- --------- --------- --------- total 3 6.45 6.46 39964 39965 2 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE
E. select count(rowid) from XXX_TAB
call count cpu elapsed disk query current rows ------ ------ -------- --------- --------- --------- --------- ---------
Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 5.43 5.44 39964 39965 2 1 ------- ----- ------- --------- --------- --------- --------- --------- total 3 5.43 5.44 39964 39965 2 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE
F. select count(1) from XXX_TAB
call count cpu elapsed disk query current rows ------- ----- -------- --------- --------- --------- --------- ---------
Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.01 0.00 0 0 0 0 Fetch 1 5.41 5.42 39965 39965 2 1 ------- ----- -------- --------- --------- --------- --------- --------- total 3 5.42 5.42 39965 39965 2 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE
G. select count(*) from XXX_TAB
call count cpu elapsed disk query current rows ------ ----- ------- --------- --------- --------- --------- ----------
Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 4.29 4.29 39964 39965 2 1 ------- ------ ------- --------- --------- --------- --------- ---------- total 3 4.29 4.29 39964 39965 2 1 Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: RULE 0 SORT (AGGREGATE)
> > Venkat schrieb: > > > > >1) Is this in fact true (that a count(*) always does a full table scan)? > > **** Yes count(*) always does a FTS > No, using CBO might lead to an index scan. That's propably why Brendan's > testing resulted in same performance. > > > > > >2) Isn't counting on the primary key an impossibility if the key is > > comprised > > >of multiple columns? > > > > **** No. You can do SELECT COUNT(ename||empno) from emp; > > > > >3) Can anyone suggest any other method for quickly retieving total rows > > from > > >large, multi-column-PK tables? > > > > **** If you keep your statistics upto-date a simple solution would bequery
> > the dba_tables to see the number of rows. Analyze your tables and then > > query the num_rows column of dba_tables. > > > > HTH > > Venkat > > -- > > Regards > > Matthias Gresz :-) > > GreMa_at_t-online.de >
-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Tue Apr 28 1998 - 15:13:42 CDT
![]() |
![]() |