Bug #49477 Assertion `0' failed in ha_partition.cc:5530 with temporary table and partitions
Submitted: 5 Dec 2009 21:30 Modified: 14 Oct 2010 14:34
Reporter: Elena Stepanova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Partitions Severity:S2 (Serious)
Version:5.1.41-debug, 5.5.0-debug OS:Any
Assigned to: Mattias Jonsson CPU Architecture:Any

[5 Dec 2009 21:30] Elena Stepanova
Description:
Version: '5.1.41-enterprise-commercial-advanced-debug'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Enterprise Server - Advanced Edition Debug (Commercial)
mysqld-debug: ha_partition.cc:5530: virtual int ha_partition::extra(ha_extra_function): Assertion `0' failed.
091205 22:07:08 - 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=8384512
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 = 338312 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x5060710
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 = 0x40d880f8 thread_stack 0x40000
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(my_print_stacktrace+0x2e)[0x8b4608]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(handle_segfault+0x240)[0x5ccf05]
/lib64/libpthread.so.0[0x33a8c0de70]
/lib64/libc.so.6(gsignal+0x35)[0x33a8030155]
/lib64/libc.so.6(abort+0x110)[0x33a8031bf0]
/lib64/libc.so.6(__assert_fail+0xf6)[0x33a80295d6]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_ZN12ha_partition5extraE17ha_extra_function+0x1e1)[0x6d5fc5]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z16init_read_recordP11READ_RECORDP3THDP8st_tableP10SQL_SELECTibb+0xbe)[0x6c1eca]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug[0x62d429]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z10sub_selectP4JOINP13st_join_tableb+0xb7)[0x62fb52]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug[0x647ea3]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_ZN4JOIN4execEv+0x2409)[0x64a54f]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_un
itP13st_select_lex+0x6b7)[0x64ac38]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z13handle_selectP3THDP6st_lexP13select_resultm+0x219)[0x64dce0]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug[0x5d8b4e]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z21mysql_execute_commandP3THD+0x5e7d)[0x5e3228]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z11mysql_parseP3THDPKcjPS2_+0x19b)[0x5e42a3]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z16dispatch_command19enum_server_commandP3THDPcj+0xaf6)[0x5e5408]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(_Z10do_commandP3THD+0x249)[0x5e6366]
/export/home/tmp/qauser/bin64_5141/bin/mysqld-debug(handle_one_connection+0x385)[0x5d6cc1]
/lib64/libpthread.so.0[0x33a8c062f7]
/lib64/libc.so.6(clone+0x6d)[0x33a80d1b6d]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x50bb1b0 = SELECT * FROM tmp_part
thd->thread_id=1
thd->killed=NOT_KILLED

(for 5.5.0 it's ha_partition.cc:5680)

(gdb) bt
#0  0x00000033a8c0b122 in pthread_kill () from /lib64/libpthread.so.0
#1  0x000000000089c0b8 in my_write_core (sig=6) at stacktrace.c:310
#2  0x00000000005b679f in handle_segfault (sig=6) at mysqld.cc:2576
#3  <signal handler called>
#4  0x00000033a8030155 in raise () from /lib64/libc.so.6
#5  0x00000033a8031bf0 in abort () from /lib64/libc.so.6
#6  0x00000033a80295d6 in __assert_fail () from /lib64/libc.so.6
#7  0x00000000006b2f93 in ha_partition::extra (this=0x84b3c40, operation=HA_EXTRA_MMAP) at ha_partition.cc:5680
#8  0x00000000006a61ae in init_read_record (info=0x84b9490, thd=0x8450ec0, table=0x84b27e0, select=0x84b9808, use_record_cache=1, print_error=true,
    disable_rr_cache=false) at records.cc:181
#9  0x0000000000614749 in join_init_read_record (tab=0x84b9410) at sql_select.cc:12071
#10 0x0000000000617d16 in sub_select (join=0x84a95d8, join_tab=0x7575, end_of_records=6) at sql_select.cc:11351
#11 0x000000000062d569 in do_select (join=0x84a95d8, fields=0x8452bf0, table=0x0, procedure=0x0) at sql_select.cc:11104
#12 0x000000000062fa25 in JOIN::exec (this=0x84a95d8) at sql_select.cc:2270
#13 0x00000000006300fc in mysql_select (thd=0x8450ec0, rref_pointer_array=0x8452cb8, tables=0x84a91e8, wild_num=1, fields=<value optimized out>,
    conds=<value optimized out>, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147764736, result=0x84a95b8, unit=0x84526c0,
    select_lex=0x8452ae8) at sql_select.cc:2459
#14 0x000000000063312a in handle_select (thd=0x8450ec0, lex=0x8452620, result=0x84a95b8, setup_tables_done_option=0) at sql_select.cc:272
#15 0x00000000005c1f16 in execute_sqlcom_select (thd=0x8450ec0, all_tables=0x84a91e8) at sql_parse.cc:5194
#16 0x00000000005c8ab7 in mysql_execute_command (thd=0x8450ec0) at sql_parse.cc:2288
#17 0x00000000005cae73 in mysql_parse (thd=0x8450ec0, inBuf=0x84a9000 "SELECT * FROM tmp_part", length=22, found_semicolon=0x404f3fe8) at sql_parse.cc:6211
#18 0x00000000005cbfc9 in dispatch_command (command=COM_QUERY, thd=0x8450ec0, packet=<value optimized out>, packet_length=22) at sql_parse.cc:1240
#19 0x00000000005ccf11 in do_command (thd=0x8450ec0) at sql_parse.cc:873
#20 0x00000000005be170 in handle_one_connection (arg=<value optimized out>) at sql_connect.cc:1154
#21 0x00000033a8c062f7 in start_thread () from /lib64/libpthread.so.0
#22 0x00000033a80d1b6d in clone () from /lib64/libc.so.6

How to repeat:
DROP DATABASE IF EXISTS part_features;
CREATE DATABASE part_features;

USE part_features;

CREATE TABLE `t_part` (
  `user_num` INT DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  KEY `user_num` (`user_num`)
) ENGINE=MyISAM PARTITION BY HASH(user_num);

INSERT INTO t_part VALUES ( 1, now() ), ( 2, now() );

CREATE TEMPORARY TABLE tmp_part LIKE t_part;
INSERT INTO tmp_part SELECT * FROM t_part;
SELECT * FROM tmp_part;

Suggested fix:
It's noticeable that in the provided scenario, creation of temporary tmp_part table via LIKE succeeds, even although direct creation of a temporary table with partitions is not allowed -- maybe that's (a part of) the problem.
[6 Dec 2009 9:01] Sveta Smirnova
Thank you for the report.

Verified as described.
[11 Dec 2009 17: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/93744

3262 Mattias Jonsson	2009-12-11
      Bug#49477: Assertion `0' failed in ha_partition.cc:5530
      with temporary table and partitions
      
      It was possible to create temporary partitioned tables
      via create table ... like ... (which is not allowed with
      create temporary table). This lead to a new HA_EXTRA flag
      (HA_EXTRA_MMAP) was sent to the partitioning handler,
      which was caught on an assert in debug builds.
      
      Solution was to check for partitioned tables when
      doing create table ... like ... and disallow it.
     @ mysql-test/r/partition_error.result
        Bug#49477: Assertion `0' failed in ha_partition.cc:5530
        with temporary table and partitions
        
        Added result
     @ mysql-test/t/partition_error.test
        Bug#49477: Assertion `0' failed in ha_partition.cc:5530
        with temporary table and partitions
        
        Added test
     @ sql/sql_table.cc
        Bug#49477: Assertion `0' failed in ha_partition.cc:5530
        with temporary table and partitions
        
        Added check to prevent creation of partitioned temporary
        tables.
        
        Only copy .par file for partitioned tables.
[25 May 2010 7:08] Mattias Jonsson
pushed into mysql-5.1-bugteam and mysql-pe
[25 May 2010 13:47] Mattias Jonsson
also pushed to mysql-trunk-merge
[28 May 2010 6:39] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100524190941-nuudpx60if25wsvx) (version source revid:alik@sun.com-20100524190409-5w4l7mje1wk1c90l) (merge vers: 6.0.14-alpha) (pib:16)
[1 Jun 2010 10:40] Jon Stephens
Documented bugfix in the 6.0.14 changelog as follows:

        It was possible to execute a CREATE TEMPORARY TABLE tmp LIKE pt
        statement, where pt is a partitioned table, even though 
        partitioned temporary tables are not permitted, which caused the 
        server to crash. Now a check is performed to prevent such statements 
        from being executed.

Set status = NM, waiting for merges to 5.1 and 5.5 trees.
[2 Jun 2010 8:48] Bugs System
Pushed into 5.1.48 (revid:georgi.kodinov@oracle.com-20100602084411-2yu607bslbmgufl3) (version source revid:mattias.jonsson@sun.com-20100521121814-7ohj7mk71zlzoxkl) (merge vers: 5.1.47) (pib:16)
[2 Jun 2010 12:30] Jon Stephens
Also documented in the 5.1.48 changelog. Returned to NM pending 5.5 merge.
[14 Oct 2010 8:31] Bugs System
Pushed into mysql-5.1-telco-7.0 5.1.51-ndb-7.0.20 (revid:martin.skold@mysql.com-20101014082627-jrmy9xbfbtrebw3c) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 8:46] Bugs System
Pushed into mysql-5.1-telco-6.3 5.1.51-ndb-6.3.39 (revid:martin.skold@mysql.com-20101014083757-5qo48b86d69zjvzj) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 9:01] Bugs System
Pushed into mysql-5.1-telco-6.2 5.1.51-ndb-6.2.19 (revid:martin.skold@mysql.com-20101014084420-y54ecj85j5we27oa) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 12:57] Jon Stephens
Already documented in 5.1.48; no new changelog entries required. 

Still waiting for 5.5 merge, returned status to NM.
[14 Oct 2010 14:34] Jon Stephens
Added changelog entry to 5.5.5 changelog; closed.