You have two potential problems:
- Will you get the right answer?
- Will you get unreasonable locking, will your whole app go very slow or even deadlock.
The right answer depends upon whether two users could compute (visit + 1) on the same value of visit. We can imagine that the database needs to do these actions:
Read visit count
Add one to visit count
Write visit count
So if two users are working at the same time could they both read the same old value? That's where the isolation level of the transaction comes into play. As observed by Artefacto the default isolation level is repeatable read, and hence we get:
Grab a lock
Read, increment, Write
Release lock
Rather than
Read (two users same old value)
Increment
First user Grab Lock, second waits
Write
Release, second user grabs lock
Write (same value!)
Release
However the level of contention could be quite high, and very much depends on the scope of your transaction. Suppose you have:
Begin transaction
Do the visit increment stuff
Do some serious business work
End transaction <==== visit lock is held until here
Then you will get a lot of folks waiting for that visit lock. We don't know the overall structure of your app, whether you are using large transaction scopes like this. Very likely you are getting a default behaviour of a single transaction per SQL statement, and in which case you're contention is just for the duration of the SQL statement, pretty much as you would be hoping.
Other folks might not be so fortunate: there are environments (eg. JEE Servlets) where implicit transaction scopes can be created by the infrastructure and then the longer lived transactions I show above happen by default. Worse is the possibility that your code is not written consistently (with the visit increment always first, or always last) you can get:
Begin transaction
Do the visit increment stuff
Do some serious business work
End transaction <==== visit lock and business locks held until here
and
Begin transaction
Do some other serious business work
Do the visit increment stuff
End transaction <==== visit lock and maybesame business locks held until here
And bingo: Deadlock
For high volume sites you bcould consider writing a "Visit" event to a queue, and having a daemon listening for those events and maintaining the count. More complex, but possibly fewer contention issues.