Let’s create Page.php
query1
query2
query3
Is there any way to lock a few tables, so if one user visits Page.php and second user opens this page a little bit later, second user would need to wait until the first user’s all queries executes.
And more importantly, would it slow a website very much if there are a few hundreds users on the same page at the same time?
Thank you.
You can use row level locking to cause the connection to block for other users.
Note that a select statement never causes a lock on a row or table though you may be able to use locking hints to cause it to lock the row. Your best bet is to just touch the row by setting a value in the row to itself or adding another column.
Databases perform well because they accommodate concurrency. Any time you cause what would be concurrent to behave serially, you’ll incur a performance penalty. In some cases this may be okay, it really depends on what you’re actually doing with it.
I’m more of a SQL Server guy, but it’s pretty generic DBMS concepts, for further information I would look into:
Transaction Isolation Levels
http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
Locking Hints
http://www.xaprb.com/blog/2006/08/05/how-to-give-locking-hints-in-mysql/
Row / Table Locking Mechanisms
http://dev.mysql.com/doc/refman/5.5/en/internal-locking.html