Bug #40389 REORGANIZE PARTITION crashes when only using one partition
Submitted: 29 Oct 2008 10:15 Modified: 20 Jan 2009 21:12
Reporter: Mattias Jonsson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S1 (Critical)
Version:5.1, 6.0 bzr OS:Any
Assigned to: Mattias Jonsson CPU Architecture:Any

[29 Oct 2008 10:15] Mattias Jonsson
Description:
The server crashes when using the (non documented) statement:
ALTER TABLE t1 REORGANIZE PARTITIONS;
on a partitioned table with only one partition

From gdb:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x002f9d40 in partition_info::check_partition_info (this=0x1069e30, thd=0x1026418, eng_type=0xb0060dd0, file=0x106a260, info=0xb00623b0, check_partition_function=true) at partition_info.cc:871
871	                           NULL);
(gdb) bt
#0  0x002f9d40 in partition_info::check_partition_info (this=0x1069e30, thd=0x1026418, eng_type=0xb0060dd0, file=0x106a260, info=0xb00623b0, check_partition_function=true) at partition_info.cc:871
#1  0x00257c07 in mysql_create_table_no_lock (thd=0x1026418, db=0x1069cc0 "test", table_name=0xb0061cc8 "#sql-17c3f_1", create_info=0xb00623b0, alter_info=0xb0062590, internal_tmp_table=true, select_field_count=0) at sql_table.cc:3333
#2  0x0025c5ae in mysql_alter_table (thd=0x1026418, new_db=0x1069cc0 "test", new_name=0x1069ab8 "t1", create_info=0xb00623b0, table_list=0x1069ae0, alter_info=0xb0062590, order_num=0, order=0x0, ignore=false) at sql_table.cc:6689
#3  0x0010da97 in mysql_execute_command (thd=0x1026418) at sql_parse.cc:2751
#4  0x0011526e in mysql_parse (thd=0x1026418, inBuf=0x1069a28 "alter table t1 reorganize partition", length=35, found_semicolon=0xb0062df4) at sql_parse.cc:5729
#5  0x00116548 in dispatch_command (command=COM_QUERY, thd=0x1026418, packet=0xcec019 "alter table t1 reorganize partition", packet_length=35) at sql_parse.cc:1152
#6  0x00117824 in do_command (thd=0x1026418) at sql_parse.cc:809
#7  0x00102b61 in handle_one_connection (arg=0x1026418) at sql_connect.cc:1115
#8  0x92cd76f5 in _pthread_start ()
#9  0x92cd75b2 in thread_start ()
(gdb) p part_expr
$1 = (class Item *) 0x0

How to repeat:
create table t1 (a int primary key)
engine myisam
partition by hash (a)
partitions 1;
alter table t1 reorganize partition;

Suggested fix:
Find why part_expr is NULL and always set it correctly
[29 Oct 2008 11:13] Sveta Smirnova
Thank you for the report.

Verified as described.
[2 Dec 2008 10:18] 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/60360

2690 Mattias Jonsson	2008-12-02
      Bug#40389: REORGANIZE PARTITION crashes when only using one partition
      
      The non documented command 'ALTER PARTITION t REORGANIZE PARTITION'
      (without any partitions!) which only make sense for nativly
      partitioned engines, such as NDB, crashes the server if there was
      no change of number of partitions.
      
      The problem was wrong usage of fast_end_partition function,
      which led to usage of a non initialized variable.
[10 Dec 2008 9:47] Mattias Jonsson
Pushed to mysql-5.1-bugteam and mysql-6.0-bugteam
[15 Jan 2009 6:39] Bugs System
Pushed into 5.1.31 (revid:joro@sun.com-20090115053147-tx1oapthnzgvs1ro) (version source revid:azundris@mysql.com-20081230114838-cn52tu180wcrvh0h) (merge vers: 5.1.31) (pib:6)
[15 Jan 2009 16:24] Jon Stephens
Documented bugfix in the 5.1.31 changelog as follows:

        ALTER TABLE ... REORGANIZE PARTITION could crash the server when
        the number of partitions was not changed.

Note that the statement as used here was recently documented for the MySQL Cluster NDB 6.4.0 release.

Set bug status back to PQ pending push to 6.0 tree.
[15 Jan 2009 18:31] Jon Stephens
Status should have been set to NDI.
[19 Jan 2009 11:23] Bugs System
Pushed into 5.1.31-ndb-6.2.17 (revid:tomas.ulin@sun.com-20090119095303-uwwvxiibtr38djii) (version source revid:tomas.ulin@sun.com-20090115073240-1wanl85vlvw2she1) (merge vers: 5.1.31-ndb-6.2.17) (pib:6)
[19 Jan 2009 13:01] Bugs System
Pushed into 5.1.31-ndb-6.3.21 (revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (version source revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (merge vers: 5.1.31-ndb-6.3.21) (pib:6)
[19 Jan 2009 13:48] Jon Stephens
Set back to NDI pending merge to 6.0.
[19 Jan 2009 16:07] Bugs System
Pushed into 5.1.31-ndb-6.4.1 (revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (version source revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (merge vers: 5.1.31-ndb-6.4.1) (pib:6)
[19 Jan 2009 17:02] Jon Stephens
Set back to NDI pending merge to 6.0.
[20 Jan 2009 18:54] Bugs System
Pushed into 6.0.10-alpha (revid:joro@sun.com-20090119171328-2hemf2ndc1dxl0et) (version source revid:azundris@mysql.com-20081230114916-c290n83z25wkt6e4) (merge vers: 6.0.9-alpha) (pib:6)
[20 Jan 2009 21:12] Jon Stephens
Fix also noted in 6.0.10 changelog; closed.
[3 Feb 2009 6: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/64966

3239 Mattias Jonsson	2009-02-03
      Bug#41945: cluster reorg part on single partition segv in mysqld
      refix of
      Bug #40389: REORGANIZE PARTITION crashes when only using one partition
      
      Problem was a remaining partition info struct that was not cleared,
      resulting in an inconsitent .frm-file
      
      Solution was to only allow REORGANIZE PARTITION on auto partitioned
      native engines, such as NDB, and not trying to do any partitioning
      specific.