Answer the question
In order to leave comments, you need to log in
How to speed up MySQL UPDATE?
Greetings!
In order for each news to have a counter of the number of views on the blog, when you open an article, the following request occurs:
UPDATE `table` SET `views` = `views` + 1 WHERE id = '123'
Answer the question
In order to leave comments, you need to log in
you can trigger on each select,
but because correctly, you don’t need to go after a cached article every time - make a separate accounting service: insert logs for each view and post-process data daily / hourly / weekly / second
The problem is optimized in a trivial way.
Realtime counters are transferred to Redis (another key-value storage), and the update to the database should be done once a day, for example, by cron.
Naturally, if you need up-to-date data at the current moment, then they must be taken from Redis
I'm not special at all, but if you make a table in the form of a "stack" with auto-increment or even without it
INSERT INTO stack VALUES ('article_id');
And then count the number of lines for each news and periodically clear the table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question