Re: How can I count rows fast ?

From: Michael C. Matthews <matthews_at_everestech.com>
Date: Mon, 13 Jun 1994 21:54:40 GMT
Message-ID: <CrCvJ4.FGz_at_everestech.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).
>:
>: Is there a chance to make it faster with a b-tree analysis ?
>:
>: How ever, I'm interested in every possibility (just mail it to me or
>: post it in this group).
>
>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.
>
Of course, this will only work if that column has no NULLs in it. count(<column>) gives you a count of non-NULL values in that column. count(*) gives you a count of ALL rows.

---                                                /\
    Mike Matthews                     Open        /,`\
    matthews_at_everestech.com          System      /\/`'\
    NeXTmail Welcome!               Solutions   /      \
Voice (713)973-1994         Fax (713)973-0347  /E v e r e s t
12727 Kimberley Suite 190 Houston, TX 77024 / Technologies, Inc. "Now you're getting personal, you halfwit." -- Mike Dahmus Received on Mon Jun 13 1994 - 23:54:40 CEST

Original text of this message