I have a MySQL stored routine where I'd like to use a temporary data table to store intermediate results. To avoid having to create a "normal" table, I want to use an in-memory table that goes away when routine execution has completed. I'm a MySQL newbie, but I suppose this is the way to go:
DROP TABLE IF EXISTS MyInMemoryTable;
CREATE TABLE MyInMemoryTable ( numberField int ) ENGINE = MEMORY;
...
DROP TABLE IF EXISTS MyInMemoryTable;
My routine works for a single user, but I am nervous about what happens if multiple users run the routine at the same time?
Is MyInMemoryTable
local to each user session executing the routine, so there can be many instances of this table (without conflicts) at the same time?
Or is MyInMemoryTable
a single global table for all users, thereby risking different users' data getting mixed-up in the table? Or will one user risk getting a database error if another user is busy running the routine?
To me, the documentation is confusing: It says the MEMORY
engine associates each table with a disk file, but also that "MEMORY
tables are never converted to disk tables."
Have I misunderstood MySQL in-memory tables? Perhaps there's a better approach?