Bug #31137 Assertion failed: primary_key_no == -1 || primary_key_no == 0, file .\ha_innodb.
Submitted: 21 Sep 2007 17:21 Modified: 23 Jan 2008 16:00
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S2 (Serious)
Version:5.0.45, 5.1.23 OS:Any
Assigned to: Ramil Kalimullin CPU Architecture:Any

[21 Sep 2007 17:21] Shane Bester
Description:
Version: '5.1.23-beta-debug'  socket: '/tmp/mysql.sock'  port: 3306  yes
070921 18:57:19  InnoDB: Error: table `test`.`t` does not exist in the InnoDB internal
InnoDB: data dictionary though MySQL is trying to drop it.
InnoDB: Have you copied the .frm file of the table to the
InnoDB: MySQL database directory from another database?
InnoDB: You can look for further help from
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html
mysqld: handler/ha_innodb.cc:4982: virtual int ha_innobase::create(const char*, TABLE*, HA_CREATE_INFO*): Assertion `primary_key_no == -1 || primary_key_no == 0' failed.
070921 18:57:20 - mysqld got signal 6;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8388572
read_buffer_size=131072
max_used_connections=1
max_threads=151
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 337620 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x8dbc7b8
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0x42863e14, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x820111b handle_segfault + 541
0xffffe410 _end + -142173536
0x400edb75 _end + 932549125
0x400e5903 _end + 932515731
0x83bacee ha_innobase::create(char const*, st_table*, st_ha_create_information*) + 928
0x82f462e ha_create_table(THD*, char const*, char const*, char const*, st_ha_create_information*, bool) + 338
0x82b9baa rea_create_table(THD*, char const*, char const*, char const*, st_ha_create_information*, List<Create_field>&, unsigned int, st_ + 390
0x830b82d mysql_create_table_no_lock(THD*, char const*, char const*, st_ha_create_information*, Alter_info*, bool, unsigned int) + 2625
0x830bbb7 mysql_create_table(THD*, char const*, char const*, st_ha_create_information*, Alter_info*, bool, unsigned int) + 521
0x820f690 mysql_execute_command(THD*) + 5472
0x8217550 mysql_parse(THD*, char const*, unsigned int, char const**) + 372
0x820cc00 dispatch_command(enum_server_command, THD*, char*, unsigned int) + 2354
0x820c2c2 do_command(THD*) + 600
0x820acbd handle_one_connection + 255
0x40038aa7 _end + 931807543
0x4017ec2e _end + 933143230
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/refman/5.1/en/resolve-stack-dump.html
and follow instructions on how to resolve the stack trace.
Resolved stack trace is much more helpful in diagnosing the
problem, so please do resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x8deb988 = create table `t` (
`col001` char (68) not null ,unique key(`col001`(1)),
`col004` char(68) not null , unique key(`col004` )
)engine=innodb
thd->thread_id=1

How to repeat:
drop table if exists `t`;
create table `t` (`col001` char (68) not null ,unique key(`col001`(1)),`col004` char(68) not null , unique key(`col004` ))engine=innodb;
[21 Sep 2007 17:26] MySQL Verification Team
please use a debug build to test it.  non-debug build didn't appear to crash
[24 Sep 2007 11:24] Heikki Tuuri
Shane, Sunny,

the assertion used to be true in old versions of MySQL.

I see that the table has a unique NOT NULL key. Old versions of MySQL would promote that to the internal primary key and number it as key number 0. What has changed?

Regards,

Heikki
[25 Oct 2007 9:55] 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/36326

ChangeSet@1.2552, 2007-10-25 14:55:03+05:00, ramil@mysql.com +3 -0
  Fix for bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0, 
  file .\ha_innodb.
  
  Problem: if a partial unique key followed by a non-partial one we declare
  the second one as a primary key.
  
  Fix: declaring an unique key as primary, check if it's the first key.
  
  Note: I doubt we can change the order in the sort_keys() in the 5.x
  as some clients may depend on the current behaviour.
[26 Oct 2007 10:38] 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/36424

ChangeSet@1.2552, 2007-10-26 15:37:38+05:00, ramil@mysql.com +7 -0
  Fix for bug #31137: Assertion failed: primary_key_no == -1 || primary_key_no == 0, 
  file .\ha_innodb.
  
  Problem: if a partial unique key followed by a non-partial one we declare
  the second one as a primary key.
  
  Fix: sort non-partial unique keys before partial ones.
[7 Dec 2007 23:07] Bugs System
Pushed into 6.0.5-alpha
[7 Dec 2007 23:09] Bugs System
Pushed into 5.1.23-rc
[7 Dec 2007 23:10] Bugs System
Pushed into 5.0.54
[23 Jan 2008 16:00] Paul DuBois
Noted in 5.0.54, 5.1.23, 6.0.5 changelogs.

MySQL declares a UNIQUE key as a PRIMARY key if it doesn't have NULL
columns and is not a partial key, and the PRIMARY key must alway be
the first key. However, in some cases, a non-first key could be
reported as PRIMARY, leading to an assert failure by InnoDB. This is
fixed by correcting the key sort order.
[3 Dec 2010 5:55] MySQL Verification Team
if you still see this bug symptoms refer yourself to bug 58650