[MDEV-7410] Temporary table name conflict between sessions Created: 2015-01-05  Updated: 2015-01-13  Resolved: 2015-01-13

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Data Definition - Procedure
Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 5.5, 10.0, 10.1
Fix Version/s: 5.5.42, 10.0.16

Type: Bug Priority: Major
Reporter: Leo Kwan Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: upstream-fixed
Environment:

RHEL 6


Attachments: Text File mysql-gen.log     File storeprocedure.sql    
Issue Links:
Relates
relates to MDEV-5816 MySQL WL#4179 - Stored programs: vali... Closed

 Description   

If we create a temporary table with the same name within a store procedure, and try to drop some columns in two different sessions running at the same moment, error " Unknown column" may pop.

Although this is documented in

https://mariadb.com/kb/en/mariadb/documentation/sql-commands/data-definition/create/create-table/

"Temporary table names are specific to your session. They may conflict with other temporary tables from other sessions or shadow names of non-temporary tables."

But this is different behavior with Mysql

http://dev.mysql.com/doc/refman/5.5/en/create-table.html

This means that two different sessions can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.)

This is stopper if using Mariadb as a drop in replacement for Mysql, as this require rewrite all SPs with alter temporary statement.



 Comments   
Comment by Elena Stepanova [ 2015-01-06 ]

You chose 10.0.15-galera as an affected version. Did you really mean this, are you using a Galera cluster?

If not, could you please

  • enable the general log;
  • run the flow including creating the temporary table within an SP, and dropping columns in different sessions until you get the error;
  • paste the exact error code/text and the connection number of the session where it occurred;
  • attach the general log.

Thanks.

Also, regarding the quote from the documentation, I don't think it was meant as an opposite to what MySQL manual says, but I agree it sounds weird. After we figure out why you are getting the error, we'll get the documentation fixed as well.

Comment by Leo Kwan [ 2015-01-06 ]

General Log

Comment by Leo Kwan [ 2015-01-06 ]

Test SP

Comment by Leo Kwan [ 2015-01-06 ]

I am testing on 10.0.15-MariaDB-wsrep-log, and it is a three nodes testing cluster.

The general log is attached, I've also attached the store procedure.

I open 4 sessions and run the same SP on the same node, the first round ran without error, but error came on the second rounds on 2 out of 4 sessions.

This is the exact error message

Session 1
MariaDB [(none)]> call PlayGround.procedure1();
ERROR 1054 (42S22): Unknown column 'PlayGround.T_Temp_Test.Value' in 'field list'

Session 2
MariaDB [(none)]> call PlayGround.procedure1();
ERROR 1054 (42S22): Unknown column 'PlayGround.T_Temp_Test.MoreValue' in 'field list'

Thanks

Comment by Elena Stepanova [ 2015-01-09 ]

Thanks for the data, I was able to reproduce it now. It's a conflict not between sessions, but between several executions of the stored procedures. It's easily repeatable in a single session:

drop procedure if exists pr;
 
--delimiter |
create procedure pr(i int) begin
  drop table if exists t1;
  create table t1 (a int, b int);
  if (i = 1) then alter table t1 drop a;
  else alter table t1 drop b; 
  end if;
  select * from t1;
end |
--delimiter ;
 
call pr(1);
call pr(2);

It used to be an upstream bug, fixed in 5.6.6 by the following revision:

revno: 3857
revision-id: alexander.nozdrin@oracle.com-20120516123641-tnvnhoaimesc8bj9
parent: alexander.nozdrin@oracle.com-20120516110343-36sld7c7somcl3z8
committer: Alexander Nozdrin <alexander.nozdrin@oracle.com>
branch nick: trunk-stage.2
timestamp: Wed 2012-05-16 16:36:41 +0400
message:
  WL#4179: Stored programs: validation of stored program statements.
  
  Briefly, that's the implementation of WL#4179. The idea is to remember
  the original query for SQL-statement within a Stored Programs and re-parse
  it when meta-data has changed.

Comment by Leo Kwan [ 2015-01-10 ]

Thank you so much on spending time to reproduce this issue and find the root cause. Since there will be relatively long time before 10.1 become production ready. Are there any work around available on this issue so the server may not generate error or random crash?

Thanks.

Comment by Sergei Golubchik [ 2015-01-10 ]

There are no crashes, as far as I understand, aren't there?

Comment by Sergei Golubchik [ 2015-01-10 ]

Okay, I will do a simple workaround for 5.5 and 10.0 branches.

Comment by Elena Stepanova [ 2015-01-10 ]

There are no crashes, as far as I understand, aren't there?

I didn't observe any crashes while experimenting with it.

Generated at Thu Feb 08 07:19:22 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.