MySQL Forums
Forum List  »  Performance

Performance of INSERT... ON DUPLICATE KEY UPDATE
Posted by: Jesus Inzunza
Date: March 09, 2011 12:03PM

I have a listing website with thousands of ads. I keep a visit counter on each ad, but I want to implement a visit counter per day, per ad. My table design to achieve this is the following:

CREATE TABLE hitsPerDay (
adId VARCHAR(16) NOT NULL,
hitDay DATE NOT NULL,
numberOfHits SMALLINT(4) UNSIGNED NULL,
PRIMARY KEY(adId , hitDay),
INDEX hitsPerDay_index3554(adId)
)
TYPE=InnoDB;

When someone checks an ad, it inserts a new record or updates it if a duplicate on the adId/date is detected:

INSERT INTO hitsPerDay VALUES ('ad2332', CURRENT_DATE(), 1)
ON DUPLICATE KEY UPDATE numberOfHits = numberOfHits + 1;

Everything works great in my tests, but given the high volume of ads, and the number of times each ad will be consulted, I am afraid the table will reach hundreds of thousands of records in a few days.

Is this the best approach? Will there be performance issues if the table reaches, say, 1 million records? Any advice will be appreciated.



Edited 1 time(s). Last edit at 03/09/2011 12:15PM by Jesus Inzunza.

Options: ReplyQuote


Subject
Views
Written By
Posted
Performance of INSERT... ON DUPLICATE KEY UPDATE
5658
March 09, 2011 12:03PM


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.