【发布时间】:2017-09-15 12:30:16
【问题描述】:
所以老板给了我一个存储过程,因为速度慢,需要优化。该过程正在创建一个临时表,看起来很奇怪:
/* pseudocode for brevity */
create temp_table;
insert into temp_table (...)
select ...
from other_table
inner join ...
inner join ...
where condition
select * from temp_table
原来如此。该代码将数据插入到临时表中,然后立即进行检索。这是我所做的,我删除了临时表并直接返回选定的记录:
/* pseudocode for brevity */
select ...
from other_table
inner join ...
inner join ...
where condition
之前的代码看起来不对,但我想确定临时表的作用。因此,我阅读了有关临时表的信息,并认为临时表可以持续存在并且只能在单个会话中访问。我的问题:
- 会话是什么意思?当我在应用程序端并打开连接时,我可以重复使用临时表吗?我想知道这是否就是为什么这里有一个临时表。
【问题讨论】:
标签: mysql temp-tables