Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

slow select count(*) on partitioned table

Status
Not open for further replies.

butterfm

Programmer
Feb 15, 2002
132
GB
Hi,

I have a partitioned table in Oracle with no indexes.

select count(*) from <tabname> partition (name)

takes around 10 mins to count 70,000 rows. It's doing a full scan of the partition but this stills seems a long time, even if the data isn't already cached.

Would an index speed up a select count(*) ?. I was under the impression that you'd need to use select count(col name) to get it to use the index.

ta,
M
 
The timing would depend on how powerful your system is, so it's difficult to say whether it's good or bad. How long do other sorts of queries typically take ? Is there data very fragmented e.g. did you previously have lots of rows in there which have been deleted ? Have you checked the plan of the query and also got all of the table stats up to date ?
 
It is a well specced system.
Is there a way I can tell when the stats were last updated ?
I have done an explain and it is table scanning.
 
Would an index speed up a select count(*) ?. I was under the impression that you'd need to use select count(col name) to get it to use the index.
A unique index will rewrite the query to perform a fast full scan of the index, a non unique index will continue to use a fts if you write count(*) but will use a FFS if you do count(column_name)
(The advantage of a FFS is that it too can read multiple blocks as per the db_file_multiblock_read_count parameter)

HTH
 
Is there a way I can tell when the stats were last updated ?

Look at sys.dba_tables.last_analyzed and num_rows. Also, because it's partitioned, look at USER_TAB_PARTITIONS as well.
 
I re-read my post there, I mis-spoke/mis-typed.
If the table in question has a primary key (using a unique OR a non-unique index, will perform a fast full scan(FFS) of that index. However any other index (unique - non-unique, part of a constraint or not) will not automatically use a that index in a count(*), it will however perform a FFS if you count the column containing the index.
Sorry for the confusion.

 
Thanks for the info guys - that's a great help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top