MySQL Forums
Forum List  »  Performance

Massive SELECTs for a hit counter
Posted by: Benjamin Choi
Date: December 13, 2004 04:18PM

I have a hit counter in PHP/MySQL that generates an image on the fly. Unlike novel methods of incrementing a scalar value, the script determines the total number of hits for the user by determining COUNT(*) in the table of (hits) that belong to a particular (user).

table hits
(
hit_id (primary key)
user_id (indexed)
referrer
timestamp (indexed)
etc.
)

I want to be able to keep records of all visits (to keep the referral, timestamp, etc. data). However, to allow multiple users to use such a service would cause row counts in the millions. Using the query SELECT COUNT(*) FROM hits WHERE user_id = 1, it can take up to half a minute to run. But the counter needs to be updated quickly, as it is done on the fly for the visitor to a web page.

Is there any way around this, or is this an inevitable feature of having such a large number of rows?

Options: ReplyQuote


Subject
Views
Written By
Posted
Massive SELECTs for a hit counter
3431
December 13, 2004 04:18PM
2405
December 14, 2004 11:45AM
2188
December 14, 2004 08:06PM
2264
December 14, 2004 12:55PM
2129
December 14, 2004 11:35PM
3626
December 16, 2004 01:45AM
2372
December 15, 2004 01:19PM
2325
December 15, 2004 01:39PM
2229
December 15, 2004 01:53PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.