views:

78

answers:

2

What's is better to use in a stored procedure: a temporary table or a memory table?

The table is used to stored summary data for reports.

Are there any trade offs that developers should be aware off?

CREATE TEMPORARY TABLE t (avg (double));

or

CREATE TABLE t (avg (double)) ENGINE=MEMORY;
+1  A: 

A temporary table will only exist for the duration of your session. A table declared with Engine=Memory will persist across user sessions / connections but will only exist in the lifetime of the MySQL instance. So if MySQL gets restarted the table goes away.

Cody Caughlan
+2  A: 

Of the two, I'd use a temporary table for report.

A memory table holds data across user sessions & connections, so you'd have to truncate it every time to make sure you wouldn't be using data from someone else. Assuming you put in whats necessary to maintain a memory table depending on your needs, it's fine - the temp table is a little safer from a maintenance perspective.

OMG Ponies