MySQL 临时表是共享资源吗?

Is MySQL Temporary table a shared resource?(MySQL 临时表是共享资源吗?)
本文介绍了MySQL 临时表是共享资源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用临时表的 MySQL 存储过程.假设我的表名是temp",我用它来存储一些中间数据.它会在程序开始时创建,并在程序结束时删除.

I have a MySQL stored procedure that uses a temporary table. Assume that my table name is 'temp' and I use it to store some middle data. It will create at the beginning of procedure, and will drop at the end.

CREATE PROCEDURE p()
BEGIN

CREATE TEMPORARY TABLE `temp`(...);

INSERT INTO `temp` VALUES(...);

DROP TEMPORARY TABLE `temp`;

END;

问题是这个存储过程可能被不同的用户同时使用,所以我想知道这是否会导致任何问题(即临时表中插入数据的任何冲突).换句话说,临时表是对同一 SP 的不同调用中的共享资源吗?

The problem is that this stored procedure may be used by different users concurrently, so I want to know if this can cause any problems (i.e. any conflict in inserted data in temp table). In other word is temp table a shared resource within different calls to the same SP?

推荐答案

不,临时表仅限于您的数据库连接范围.在同一个数据库连接期间,您可以在对过程的后续调用中使用临时表,但其他连接无法访问它.他们可以创建一个同名的表,但每个临时表都是独立的.当您关闭连接时,临时表会消失.

No, a temp table is limited to the scope of your database connection. You can use the temp table in subsequent calls to the procedure during the same database connection, but other connections cannot access it. They can create a table by the same name, but each temp table will be independent. Temp tables go away when you close your connection.

这篇关于MySQL 临时表是共享资源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)