Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Would Oracle use index on count(*)?
Eugen Nyffeler <eugen.nyffeler_at_ubs.com> wrote in article
<35331BA9.86E49A6E_at_ubs.com>...
>
> If you use a count(*) the full table scan is coosen. If you use
> count(primary key field)
> an index scan shoud be used. I don't know the exact Oracle
internals for
> this, but
> i think one reason is to make the codeing simple (e.g. what do you
do
> when there
> are several indexes but none is unique, or even indexes with null
value
> ??)
>
Not strictly true, although there are plenty of variations dependent
upon
Oracle version.
For instance, if you have a bitmap index (in 8.0.3 at least) then select count(*) will almost certainly use the index to do the count (partly because, contrary to btree indexes) null are stored in the index.
I believe that given suitable cost factors, count(*) can be converted to a count using the PK index if such exists.
Jonathan Lewis Received on Tue Apr 14 1998 - 08:23:55 CDT