Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Would Oracle use index on count(*)?
In article <6h16f3$22_at_bgtnsc03.worldnet.att.net>, b-horton_at_NOSPAM.net wrote:
>Jim Morgan wrote:
>>
>> I saw this thread late, but I ran into this once before and was wondering
>> why count(*) took so long. I tried count(colname) but that performed just
>> as poorly. It kind of makes sense that count(primarykey) would use the
>> index and thus perform much better, but what if you had a compound primary
>> key?
>>
>> Regards,
>> Jim
>If the 1st count field is the major part of the index, I wouldn't
>think that you would need to specify the remainder of the composite
>key. The optimizer should still process using the index. If you
>used the minor part then no, unless there is another index on that
>part.
A where clause can be used to let Oracle know that you would like to use an index. A little experimentation with explain plan will let you balance the where clause(s) to use the index.
I.E. "WHERE left_most_column_on_index >= CHR(0)" (if it is varchar) is a start. --
lorenzen_at_tiny.com | Life is complex; it has | real and imaginary partsReceived on Wed Apr 15 1998 - 12:23:07 CDT
![]() |
![]() |