I\'m making a web site where I would like to increment a counter in a standard MyISAM table.
Simplified example:
UPDATE votes SET num = num + 1;
Another approach when using InnoDB is using unique index on multiple column as follow:
Table 'Sessions' { unique_key(browser_session_id,profile_id) // ensures that inserting 1 entry per session will occur once }
select count(browser_session_id) from Sessions
Will guarantee result of unique sessions, as multiple sessions per user is not allowed.
Conclusions
Advantage
Each insert does require a pre-select.
Disadvantage
It is not suitable for all cases.
May slow down write performance, and requires extra management