存储过程中的MySQL临时vs内存表 [英] MySQL temporary vs memory table in stored procedures
问题描述
在存储过程中使用什么更好:临时表或内存表?
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));
或
CREATE TABLE t (avg (double)) ENGINE=MEMORY;
推荐答案
在这两者中,我将使用临时表进行报告.
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.
这篇关于存储过程中的MySQL临时vs内存表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!