Re: How can I count rows fast ?

From: Michael Sallwasser <msallwas_at_world.nad.northrop.com>
Date: Tue, 14 Jun 1994 17:12:29 GMT
Message-ID: <CrED4u.699_at_gremlin.nrtc.northrop.com>


In article <Cr6nq2.Iv3_at_nl.oracle.com> cgohring_at_uk.oracle.com writes:
>derwand_at_sap-ag.de (Guido Derwand) writes:
>: Is there a faster method to count rows in a table than using SQL
>: 'SELECT COUNT(*)' in Oracle V. 6 or 7 ? I've heard from some
>: expirience with using 'SELECT COUNT(<index>)' to be faster, but
>: I couldn't reproduce this (there seems to be no difference).
>
>Rather than doing a count(*), do a count(<column>).
>
>where <column> is a column with an index on it.
>
>This can be resolved with the index alone, then, and prevent a full table
>scan.
>
Have you actually tested this?

I have a table. It has four columns. All of the columns are flagged NOT NULL. I have have four separate indexes, one of them is for a single column. I specified the column name as you indicated. Oracle's Explain Plan says it intends to do a full table scan. In theory, it does not need to but it indicates that it will do a FULL TABLE SCAN.

Comments?

-- 
============================================================================
Michael Sallwasser  | Down one path is utter dispair and hopelessness. Down 
Northrop Grumman    | the other is total destruction. Let us choose wisely.
============================================================================
Received on Tue Jun 14 1994 - 19:12:29 CEST

Original text of this message