Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7410

Temporary table name conflict between sessions

Details

    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.

      Attachments

        Issue Links

          Activity

            leomkkwan Leo Kwan created issue -

            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.

            elenst Elena Stepanova added a comment - 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.
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            Due Date 2015-01-27
            leomkkwan Leo Kwan added a comment -

            General Log

            leomkkwan Leo Kwan added a comment - General Log
            leomkkwan Leo Kwan made changes -
            Attachment mysql-gen.log [ 36627 ]
            leomkkwan Leo Kwan added a comment -

            Test SP

            leomkkwan Leo Kwan added a comment - Test SP
            leomkkwan Leo Kwan made changes -
            Attachment storeprocedure.sql [ 36628 ]
            leomkkwan Leo Kwan added a comment - - edited

            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

            leomkkwan Leo Kwan added a comment - - edited 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
            elenst Elena Stepanova made changes -
            Due Date 2015-01-27
            elenst Elena Stepanova made changes -
            Assignee Elena Stepanova [ elenst ]

            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.

            elenst Elena Stepanova added a comment - 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.
            elenst Elena Stepanova made changes -
            Component/s Data Definition - Procedure [ 10119 ]
            Fix Version/s 10.1 [ 16100 ]
            Affects Version/s 5.3.12 [ 12000 ]
            Affects Version/s 5.2.14 [ 12101 ]
            Affects Version/s 5.1.67 [ 12100 ]
            Affects Version/s 10.1 [ 16100 ]
            Affects Version/s 10.0 [ 16000 ]
            Affects Version/s 5.5 [ 15800 ]
            Affects Version/s 10.0.15-galera [ 17501 ]
            Assignee Elena Stepanova [ elenst ] Sergei Golubchik [ serg ]
            Labels upstream-fixed
            elenst Elena Stepanova made changes -
            leomkkwan Leo Kwan added a comment -

            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.

            leomkkwan Leo Kwan added a comment - 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.
            serg Sergei Golubchik made changes -
            Fix Version/s 10.0 [ 16000 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.0 [ 16000 ]

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

            serg Sergei Golubchik added a comment - There are no crashes, as far as I understand, aren't there?
            serg Sergei Golubchik made changes -

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

            serg Sergei Golubchik added a comment - Okay, I will do a simple workaround for 5.5 and 10.0 branches.
            serg Sergei Golubchik made changes -
            Fix Version/s 10.0 [ 16000 ]
            Fix Version/s 5.5 [ 15800 ]
            Fix Version/s 10.1 [ 16100 ]
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -

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

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

            elenst Elena Stepanova added a comment - There are no crashes, as far as I understand, aren't there? I didn't observe any crashes while experimenting with it.
            serg Sergei Golubchik made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.0.16 [ 17900 ]
            Fix Version/s  5.5.42 [ 18102 ]
            Fix Version/s 5.5 [ 15800 ]
            Fix Version/s 10.0 [ 16000 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 59111 ] MariaDB v3 [ 66092 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 66092 ] MariaDB v4 [ 148680 ]

            People

              serg Sergei Golubchik
              leomkkwan Leo Kwan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.