Bug #32047 'Spurious' errors while opening MERGE tables
Submitted: 2 Nov 2007 6:43 Modified: 4 Mar 2009 17:11
Reporter: Dmitry Lenev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Merge storage engine Severity:S2 (Serious)
Version:5.0.50-bk, 5.0.60-bk OS:Any
Assigned to: Sergey Vojtovich CPU Architecture:Any

[2 Nov 2007 6:43] Dmitry Lenev
Description:
Attempts to open valid MERGE table after failing to open invalid MERGE table with  a ER_WRONG_MRG_TABLE error sometimes fails with same error. See How-to-repeat section for the example/details.

How to repeat:
# This script for 'mysqltest' reproduces the problem in 5.0.50
# To reproduce it in 5.1/6.0 one also have to disable slow and general logs.
create table t1 (i int);
create table t11 (i int);
create table t2 (j varchar(10));
create table t3 (i int) engine=MERGE UNION=(t1,t2);
create table t4 (i int) engine=MERGE UNION=(t1,t11);
select * from t1;
select * from t11;
--error ER_WRONG_MRG_TABLE
select * from t3;
# This should not generate an error but it does
select * from t4;

Suggested fix:
The problem is caused by incorrect use of my_errno variable in myrg_open() routine which in some cases still holds generated by previous call to this function.

diff -Nru a/storage/myisammrg/myrg_open.c b/storage/myisammrg/myrg_open.c
--- a/storage/myisammrg/myrg_open.c	2007-11-01 19:49:24 +01:00
+++ b/storage/myisammrg/myrg_open.c	2007-11-01 19:49:24 +01:00
@@ -45,6 +45,8 @@
 
   LINT_INIT(key_parts);
 
+  my_errno= 0;
+  
   bzero((char*) &file,sizeof(file));
   if ((fd=my_open(fn_format(name_buff,name,"",MYRG_NAME_EXT,
                             MY_UNPACK_FILENAME|MY_APPEND_EXT),
[23 Apr 2008 13:01] MySQL Verification Team
bug #36290 was marked as a duplicate of this
[23 Apr 2008 14:33] MySQL Verification Team
repeatable on 5.0.60-bk

<cut>
mysql> select * from t11;
Empty set (0.00 sec)

mysql> select * from t3;
ERROR 1168 (HY000): Unable to open underlying table which is different
mysql> select * from t4;
ERROR 1168 (HY000): Unable to open underlying table which is different
mysql> flush tables;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t4;
Empty set (0.00 sec)

mysql> select version();
+--------------+
| version()    |
+--------------+
| 5.0.60-debug |
+--------------+
1 row in set (0.00 sec)
[25 Apr 2008 18:52] MySQL Verification Team
i confirm the patch supplied by dmitri seems to work.  no error after last select.

mysql> select * from t11;
Empty set (0.00 sec)

mysql> select * from t3;
ERROR 1168 (HY000): Unable to open underlying table which is differen
mysql> select * from t4;
Empty set (0.00 sec)
[26 Sep 2008 18:43] Omer Barnir
triage: Updating tag from SR51MRU to CHECKED as customer issue is closed
[29 Jan 2009 12:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/64468

2733 Sergey Vojtovich	2009-01-29
      BUG#32047 - 'Spurious' errors while opening MERGE tables
      
      Accessing well defined MERGE table may return an error
      stating that the merge table is incorrectly defined. This
      happens if MERGE child tables were accessed before and we
      failed to open another incorrectly defined MERGE table in
      this connection.
      
      The problem was incorrect usage of my_errno.
[4 Feb 2009 12:49] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/65161

2737 Sergey Vojtovich	2009-02-04
      BUG#32047 - 'Spurious' errors while opening MERGE tables
      
      Accessing well defined MERGE table may return an error
      stating that the merge table is incorrectly defined. This
      happens if MERGE child tables were accessed before and we
      failed to open another incorrectly defined MERGE table in
      this connection.
      
      myrg_open() internally used my_errno as a variable for determining
      failure, and thus could be tricked into a wrong decision by other
      uses of my_errno.
      
      With this fix we use function local boolean flag instead of my_errno
      to determine failure.
[6 Feb 2009 13:42] Bugs System
Pushed into 5.0.78 (revid:joro@sun.com-20090206133929-ybpbkkox9wkptopb) (version source revid:matthias.leich@sun.com-20090204153428-c9h69m8qajpc2fvy) (merge vers: 5.0.78) (pib:6)
[9 Feb 2009 22:34] Bugs System
Pushed into 5.1.32 (revid:davi.arnaut@sun.com-20090209214102-gj3sb3ujpnvpiy4c) (version source revid:davi.arnaut@sun.com-20090209214102-gj3sb3ujpnvpiy4c) (merge vers: 5.1.32) (pib:6)
[14 Feb 2009 13:01] Bugs System
Pushed into 6.0.10-alpha (revid:matthias.leich@sun.com-20090212211028-y72faag15q3z3szy) (version source revid:svoj@mysql.com-20090204133910-kjnr35ocsr1voej9) (merge vers: 6.0.10-alpha) (pib:6)
[17 Feb 2009 15:00] Bugs System
Pushed into 5.1.32-ndb-6.3.23 (revid:tomas.ulin@sun.com-20090217131017-6u8qz1edkjfiobef) (version source revid:tomas.ulin@sun.com-20090216083408-rmvyaxjt6mk8sg1y) (merge vers: 5.1.32-ndb-6.3.23) (pib:6)
[17 Feb 2009 16:48] Bugs System
Pushed into 5.1.32-ndb-6.4.3 (revid:tomas.ulin@sun.com-20090217134419-5ha6xg4dpedrbmau) (version source revid:tomas.ulin@sun.com-20090216083646-m8st11oj1hhfuuh5) (merge vers: 5.1.32-ndb-6.4.3) (pib:6)
[17 Feb 2009 18:24] Bugs System
Pushed into 5.1.32-ndb-6.2.17 (revid:tomas.ulin@sun.com-20090217134216-5699eq74ws4oxa0j) (version source revid:tomas.ulin@sun.com-20090211111208-wf0acl7c1vl5653e) (merge vers: 5.1.32-ndb-6.2.17) (pib:6)
[4 Mar 2009 17:11] Tony Bedford
Entries were added to the 6.0.10, 5.1.32 and 5.0.78 changelogs:

Attempts to open a valid MERGE table sometimes resulted in a ER_WRONG_MRG_TABLE error. This happened after failure to open an invalid MERGE table had also generated an ER_WRONG_MRG_TABLE error.