I am trying to build a system using Java and MySQL 5.1.63 GA where there are some input tables and some output tables in database.
To populate output tables I have written a procedure which will be called from servlet and generate a lot of intermediate tables before finally populating output tables. There are a lot of calculations and can take time even upto a minute.
Input and output tables operate using user_id but intermediate tables simply contain value columns.
But I have following concerns:
1) what happens if two users trigger calculation sequence at once, how can I protect intermediate tables?
2) Can I use any other technique like temporary tables, etc.?
The way to isolate each user is to have all intermediate calculations done in temporary tables. Per the MySQL Documentation:
So long as the input and output tables are all segregated by user_id you should be fine.
Changing your code to use temporary tables may be pretty easy as well. Most times all you’ll have to do is add the word
TEMPORARYto yourCREATE TABLEstatements like this: