Bug #15820 Can create table with 1 partition, then doing ALTER .. ADD PARTITION crashes
Submitted: 17 Dec 2005 5:13 Modified: 2 Feb 2006 5:12
Reporter: Sergey Petrunya Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S1 (Critical)
Version:5.1-bk OS:Linux (Linux)
Assigned to: Mikael Ronström CPU Architecture:Any

[17 Dec 2005 5:13] Sergey Petrunya
Description:
If one doesn't specify "PARTITIONS n" clause, a table is created with one partition:

mysql> create table t10 (a int) partition by hash(a);
Query OK, 0 rows affected (0.00 sec)

mysql> show create table t10\G
*************************** 1. row ***************************
       Table: t10
Create Table: CREATE TABLE `t10` (
  `a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY HASH (a) 
1 row in set (0.00 sec)

I'm not sure this is intended. I would require the "PARTITIONS n" clause.

Doing ALTER TABLE ... ADD PARTITION on such table will cause assertion failure.

How to repeat:
Run:
create table t10 (a int) partition by hash(a);
ALTER TABLE t10 ADD PARTITION PARTITIONS 4;

And get:
  [New Thread 180236 (LWP 31515)]
  mysqld: ha_partition.cc:1947: int ha_partition::partition_scan_set_up(byte*, bool): Assertion `m_part_spec.start_part < m_tot_parts && m_part_spec.end_part < m_tot_parts' failed.

Stack:
  #5  0xb7c07e9d in __assert_fail () from /lib/libc.so.6
  #6  0x0839e3dc in ha_partition::partition_scan_set_up (this=0x91fa4d8, buf=0x91d46ca "¥¥¥¥¥h4z\025z\025\217\217\2170", idx_read_flag=false) at ha_partition.cc:1946
  #7  0x0839cee5 in ha_partition::rnd_init (this=0x91fa4d8, scan=true) at ha_partition.cc:1384
  #8  0x08158ebe in handler::ha_rnd_init (this=0x91fa4d8, scan=true) at handler.h:906
  #9  0x082ce39c in init_read_record (info=0xb54fc400, thd=0x91cc7b8, table=0x91f26a8, select=0x0, use_record_cache=1, print_error=true) at records.cc:235
  #10 0x082f0e15 in copy_data_between_tables (from=0x91f26a8, to=0x91faf70, create=@0xb54fc9b0, handle_duplicates=DUP_ERROR, ignore=false, order_num=0, order=0x0, copied=0xb54fcbc8, deleted=0xb54fcbc0) at sql_table.cc:4900
  #11 0x082efeb9 in mysql_alter_table (thd=0x91cc7b8, new_db=0x91d2950 "parti4", new_name=0x91f34c0 "t10", create_info=0x91ccd50, table_list=0x91f34e8, fields=@0x91ccc74, keys=@0x91ccc68, order_num=0, order=0x0, handle_duplicates=DUP_ERROR, ignore=false, alter_info=0x91cce9c, do_send_ok=true) at sql_table.cc:4574
  #12 0x0820fdde in mysql_execute_command (thd=0x91cc7b8) at sql_parse.cc:3013
  #13 0x08217a26 in mysql_parse (thd=0x91cc7b8, inBuf=0x91f3458 "ALTER TABLE t10 ADD PARTITION PARTITIONS 4", length=42) at sql_parse.cc:5626

Suggested fix:
We need to decide 
 * if "PARTITIONS n" clause is really optional
 * if we support partitioned tables with one partition
And act accordingly.
[17 Dec 2005 13:35] MySQL Verification Team
051217 11:34:35 [Note] /home/miguel/dbs/5.1/libexec/mysqld: ready for connections.
Version: '5.1.4-alpha-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[New Thread 1117604784 (LWP 28269)]
[Thread 1117604784 (zombie) exited]
[New Thread 1117604784 (LWP 28271)]
mysqld: ha_partition.cc:1947: int ha_partition::partition_scan_set_up(byte*, bool): Assertion `m_part_spec.start_part < m_tot_parts && m_part_spec.end_part < m_tot_parts' failed.

Program received signal SIGABRT, Aborted.
[Switching to Thread 1117604784 (LWP 28271)]
0xffffe410 in __kernel_vsyscall ()
[27 Jan 2006 15:42] 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/1748
[2 Feb 2006 5:12] Mike Hillyer
Documented in 5.1.6 changelog:

      <listitem>
        <para>
          <literal>ALTER TABLE ... ADD PARTITIONS</literal> on a table
          with one partition crashed the server. (Bug #15820)
        </para>
      </listitem>