Re: Implement a logging table; avoiding conflicting inserts
Fan, Wellington wrote:
> > > Given: MySQL 4.0.12, I need to implement a pageview log with a
>>> resolution of 1 day.
If you want to brute-force it, I think I would go this route:
create table hits (
day date not null primary key,
hitcount int unsigned not null,
);
insert ignore into hits(day, hitcount) values (current_date, 0);
update hits set hitcount = hitcount + 1 where day = current_date;
No transactions. Your application logic can perhaps be smart and avoid
the first query. But the transactional method with locking in share
mode is probably going to have a lot more overhead and lower concurrency
than my suggestion.
Baron
|