Bug #26104 Bug on foreign key class constructor
Submitted: 6 Feb 2007 6:56 Modified: 27 Jul 2007 4:40
Reporter: Jan Lindström Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S2 (Serious)
Version:5.0 & 5.1 OS:Linux (Linux, Any)
Assigned to: Konstantin Osipov CPU Architecture:Any
Tags: Contribution

[6 Feb 2007 6:56] Jan Lindström
Description:
Currently foreign key constructor in sql_class.h is as follows:

foreign_key(const char *name_arg, List<key_part_spec> &cols,
	      Table_ident *table,   List<key_part_spec> &ref_cols,
	      uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
    :Key(FOREIGN_KEY, name_arg, HA_KEY_ALG_UNDEF, 0, cols),
    ref_table(table), ref_columns(cols),
    delete_opt(delete_opt_arg), update_opt(update_opt_arg),
    match_opt(match_opt_arg)
  {}

Note that cols is assigned to ref_columns.

How to repeat:
create table t1(a int not null, primary key (a)) engine=innodb;
create table t2(a int not null, b int not null, primary key (a),
foreign key (b) references t1(a)) engine=innodb:

For the second create table use gdb and display the contents of foreign key class after the constructor call.

Suggested fix:
--- 1.338/sql/sql_class.h	2007-01-16 10:34:40 +02:00
+++ 1.339/sql/sql_class.h	2007-01-16 10:34:40 +02:00
@@ -145,7 +145,7 @@
 	      Table_ident *table,   List<key_part_spec> &ref_cols,
 	      uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
     :Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
-    ref_table(table), ref_columns(cols),
+    ref_table(table), ref_columns(ref_cols),
     delete_opt(delete_opt_arg), update_opt(update_opt_arg),
     match_opt(match_opt_arg)
   {}
[6 Feb 2007 11:05] Valeriy Kravchuk
Thank you for a problem report. Verified by code review with 5.0-BK.
[18 Jul 2007 12:02] 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/31080

ChangeSet@1.2531, 2007-07-18 16:01:58+04:00, kostja@bodhi.(none) +3 -0
  A fix and a test case for Bug#26104 Bug on foreign key class constructor.
  
  Fix the typo in the constructor. Cover a semantic check that previously
  never worked with a test.
[18 Jul 2007 12:23] 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/31082

ChangeSet@1.2531, 2007-07-18 16:22:05+04:00, kostja@bodhi.(none) +5 -0
  A fix and a test case for Bug#26104 Bug on foreign key class constructor.
  
  Fix the typo in the constructor. Cover a semantic check that previously
  never worked with a test.
[18 Jul 2007 12:26] Konstantin Osipov
A trivial bug, queued in 5.0-runtime
[25 Jul 2007 8:47] Bugs System
Pushed into 5.0.48
[25 Jul 2007 8:48] Bugs System
Pushed into 5.1.21-beta
[27 Jul 2007 4:40] Paul DuBois
Test case change. No changelog entry needed.
[27 Jul 2007 4:42] Paul DuBois
Previous comment should be:

Compilation fix and test case change. No changelog entry needed.