use test;
create  temporary  table if not exists testtemporary 
(
id int not null 
) engine=MyISAM;insert testtemporary select 2 from dual;
update testtemporary inner join (select id from testtemporary where id=2) as A using(id)
set testtemporary.id=3
where testtemporary.id=2;
Error Code: 1137
Can't reopen table: 'testtemporary'use test;
create  table if not exists testtemporary 
(
id int not null 
) engine=MyISAM;insert testtemporary select 2 from dual;
update testtemporary inner join (select id from testtemporary where id=2) as A using(id)
set testtemporary.id=3
where testtemporary.id=2;
1 row(s) affected
Rows matched: 1  Changed: 1  Warnings: 0use test;
create temporary table if not exists testtemporary 
(
id int not null 
) engine=MyISAM;select * from testtemporary,testtemporary as b;
Error Code: 1137
Can't reopen table: 'testtemporary'
在同一个查询中,临时表不能够以两个名字存在。也不能同时出现在主查询和子查询中。这个限制感觉怪怪的。导致了我想用临时表存储报表结果并进一步处理时不能够完成,但改为物理表时,又会造成线程间共享了。该真么解决呢。

解决方案 »

  1.   

    用物理表,没办法,MYSQL限制
      

  2.   

    在同一个查询中,临时表不能够以两个名字存在。也不能同时出现在主查询和子查询中。这个限制感觉怪怪的mysql就这么规定的
      

  3.   

    没办法MYSQL有自己的限制,同样其它数据库产品也有它们自己的限制。
    关键是要适应工具, 或者选择工具。 当然如果你有时间和精力也可以改造工具,把MYSQL的源代码下载后自行修改重新编译即可。
      

  4.   


    恩,mysql自己的限制,没得办法。
      

  5.   

    那用什么方法可以实现呢,我现在用物理表单击测试是达到目的了,但是并发测试时数据还是出现了问题。而且我使用事务来隔离,在进入事务后清空表,进行插入 ,查询后直接回滚达到删除表数据的目的。但不知怎么的,事务还是不生效。用LOCK TABLES ,提示存储过程不能使用LOCK TABLES.我在调用存储过程外面使用LOCK TABLES.但是 我在存储过程中使用 子查询产生的 别名表都要求锁定。那么多临时表 ,我如何去锁定啊?恩 。大侠来指点下哈 
      

  6.   

    看LZ的问题,我突然想到临时表是不是用MYISAM存储引擎查询更快些。
      

  7.   

    是的,MyISAM在并发连接不多的情况下插入和查询上速度比起Innodb快,当然MEMORY引擎更快,但是MEMORY 不支持临时表,也就是说它的表是所有连接可见的