Bug #60039 crash when exchanging a partition on nonpartitioned table with a view
Submitted: 9 Feb 2011 9:17 Modified: 10 Mar 2011 11:42
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S1 (Critical)
Version:5.6.2 OS:Any
Assigned to: Mattias Jonsson CPU Architecture:Any

[9 Feb 2011 9:17] Shane Bester
Description:
Version: '5.6.2-m5-valgrind-max-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[New Thread 0x7fffe3f88710 (LWP 22325)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe3f88710 (LWP 22325)]
0x000000000088f71d in Sql_cmd_alter_table_exchange_partition::exchange_partition at ./sql/sql_partition_admin.cc:530
530       table_hton= swap_table->file->ht;
(gdb) bt
#0 in Sql_cmd_alter_table_exchange_partition::exchange_partition at ./sql/sql_partition_admin.cc:530
#1 in Sql_cmd_alter_table_exchange_partition::execute at ./sql/sql_partition_admin.cc:94
#2 in mysql_execute_command at ./sql/sql_parse.cc:4356
#3 in mysql_parse at ./sql/sql_parse.cc:5549
#4 in dispatch_command at ./sql/sql_parse.cc:1078
#5 in do_command at ./sql/sql_parse.cc:815
#6 in do_handle_one_connection at ./sql/sql_connect.cc:748
#7 in handle_one_connection at ./sql/sql_connect.cc:684
#8 in start_thread at pthread_create.c:301
#9 in clone at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115

How to repeat:
#run on mysql-trunk:
drop table if exists `g1`;
create table `g1`(`a` int)engine=innodb;
create or replace view `w1` as select * from `g1`;
alter table `g1` exchange partition `p0` with table `w1`;
[9 Feb 2011 10:37] Valeriy Kravchuk
Verified with current mysql-trunk on 32-bit Ubuntu 10.04:

Version: '5.6.2-m5-valgrind-max-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
110209 12:35:51 - mysqld got signal 11 ;
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=8388608
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 338003 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0xa9ca250
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...
stack_bottom = 0xa909f348 thread_stack 0x30000
/home2/openxs/dbs/trunk/bin/mysqld(my_print_stacktrace+0x33)[0x85516a8]
/home2/openxs/dbs/trunk/bin/mysqld(handle_segfault+0x355)[0x818a511]
[0xa45400]
/home2/openxs/dbs/trunk/bin/mysqld(_ZN38Sql_cmd_alter_table_exchange_partition7executeEP3THD+0x2dd)[0x84ba3cd]
/home2/openxs/dbs/trunk/bin/mysqld(_Z21mysql_execute_commandP3THD+0x7cac)[0x830de9c]
/home2/openxs/dbs/trunk/bin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x1ff)[0x83108c8]
/home2/openxs/dbs/trunk/bin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0xa5c)[0x8304507]
/home2/openxs/dbs/trunk/bin/mysqld(_Z10do_commandP3THD+0x292)[0x8303892]
/home2/openxs/dbs/trunk/bin/mysqld(_Z24do_handle_one_connectionP3THD+0x3f7)[0x82dc687]
/home2/openxs/dbs/trunk/bin/mysqld(handle_one_connection+0x35)[0x82dc285]
/lib/tls/i686/cmov/libpthread.so.0(+0x596e)[0x8f596e]
/lib/tls/i686/cmov/libc.so.6(clone+0x5e)[0x2c3a4e]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0xaa1ecd0): alter table `g1` exchange partition `p0` with table `w1`
Connection ID (thread ID): 1
Status: NOT_KILLED
...
[9 Feb 2011 11:44] Mattias Jonsson
Assigning myself, since I wrote WL#4445/EXCHANGE PARTITION.
[10 Feb 2011 9:51] 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/130990

3624 Mattias Jonsson	2011-02-10
      Bug#60039: crash when exchanging a partition on
                 nonpartitioned table with a view
      
      Since the table was a view, it was never opened.
      Due to this it crashed on null pointer reference.
      
      Fixed by checking the tables before using it.
     @ mysql-test/r/partition_error.result
        updated result
     @ mysql-test/t/partition_error.test
        added test
     @ sql/sql_partition_admin.cc
        check swap_table before using it.
[10 Mar 2011 11:42] Jon Stephens
Fixed in 5.6.3. Since the issue did not occur in a release version, no changelog entry is required. Closed.
[10 Mar 2011 12:07] Jon Stephens
MJ informs me that the issue does exist in 5.6.2.

Documented fix in the 5.6.3 changelog as follows:

        Attempting to use ALTER TABLE ... EXCHANGE PARTITION to exchange
        a view with a (nonexistent) partition of a table that was not
        partitioned caused the server to crash.

No status change.