Bug #40281 partitioning the general log table crashes the server
Submitted: 23 Oct 2008 11:26 Modified: 7 Aug 2009 20:33
Reporter: Giuseppe Maxia Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Logging Severity:S2 (Serious)
Version:5.1.29 OS:MacOS
Assigned to: Tatiana Azundris Nuernberg CPU Architecture:Any
Tags: logging, partitioning, table logging

[23 Oct 2008 11:26] Giuseppe Maxia
Description:
if you alter the general log table to use partitioning, the server crashes after a few connections.

mysql> create table gl like general_log;
Query OK, 0 rows affected (0.14 sec)

mysql> alter table gl engine=myisam;
Query OK, 0 rows affected (0.26 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table gl partition by hash (thread_id) partitions 20;
Query OK, 0 rows affected (0.44 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table general_log rename to gl0;
Query OK, 0 rows affected, 1 warning (0.13 sec)

mysql> alter table gl rename to general_log ;
Query OK, 0 rows affected (0.01 sec)

set global log_output='table';
set global general_log=1;

connect;
connect;
connect;

How to repeat:
--source include/have_partition.inc

use mysql;
--disable_warnings
drop table if exists gl, gl1;
--enable_warnings

set global general_log =0;
create table gl like general_log;
alter table gl engine=myisam;
alter table gl partition by hash (thread_id) partitions 10;
alter table general_log rename to gl1;
alter table gl rename to general_log;

set global log_output='table';
set global general_log =1;

use test;

--disable_warnings
drop table if exists t1;
--enable_warnings

create table t1 (i int);

let $loop = 10;

while ($loop) {

    connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);

    connection master;
    eval insert into t1 values ($loop);
    select * from t1 ;

    disconnect master;

    dec $loop;

}

drop table t1;
[23 Oct 2008 11:41] Jon Stephens
From http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations.html:

        Log tables.   Beginning with MySQL 5.1.20, it is no longer possible to 
        partition the log tables; beginning with that version, an ALTER TABLE ... 
        PARTITION BY ...  statement on such a table fails with an error. 
        (Bug#27816)

Any attempt to partition a log table should fail with an error.
[23 Oct 2008 11:46] MySQL Verification Team
Thank you for the bug report. Stack trace:

mysqld.exe!_NMSG_WRITE(int rterrnum=10)  Line 195	C
mysqld.exe!abort()  Line 44 + 0x7	C
mysqld.exe!_assert(const char * expr=0x00a756ec, const char * filename=0x00a756d8, unsigned int lineno=5287)  Line 306	C
mysqld.exe!ha_partition::extra(ha_extra_function operation=HA_EXTRA_MARK_AS_LOG_TABLE)  Line 5287 + 0x18	C++
mysqld.exe!Log_to_csv_event_handler::log_general(THD * thd=0x01ed72f8, long event_time=1224765769, const char * user_host=0x038ef454, unsigned int user_host_len=34, int thread_id=1, const char * command_type=0x00ae1414, unsigned int command_type_len=5, const char * sql_text=0x01eff8c0, unsigned int sql_text_len=17, charset_info_st * client_cs=0x00bec788)  Line 397 + 0x1e	C++
mysqld.exe!LOGGER::general_log_write(THD * thd=0x01ed72f8, enum_server_command command=COM_QUERY, const char * query=0x01eff8c0, unsigned int query_length=17)  Line 1037 + 0x6f	C++
mysqld.exe!general_log_write(THD * thd=0x01ed72f8, enum_server_command command=COM_QUERY, const char * query=0x01eff8c0, unsigned int query_length=17)  Line 4144 + 0x1a	C++
mysqld.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x01ed72f8, char * packet=0x01ef7811, unsigned int packet_length=17)  Line 1143 + 0x1b	C++
mysqld.exe!do_command(THD * thd=0x01ed72f8)  Line 809 + 0x1b	C++
mysqld.exe!handle_one_connection(void * arg=0x01ed72f8)  Line 1115 + 0x9	C++
mysqld.exe!pthread_start(void * param=0x01220db8)  Line 85 + 0x9	C
mysqld.exe!_threadstart(void * ptd=0x01ef2ea0)  Line 196 + 0xd	C
kernel32.dll!7c80b713()
[23 Oct 2008 11:47] Giuseppe Maxia
Jon,
I hear you. But still, you can crash the server with a sequence of legitimate commands.
[23 Oct 2008 13:42] Jon Stephens
Giuseppe,

The point I was trying to make is that the statements are NOT legitimate - they are supposed to be disallowed.

I believe what we have here is a 'fatal regression'. ;)
[23 Oct 2008 13:53] Jon Stephens
Nevermind, I missed the 'rename' part.

One of these days, I simply must learn to read.
[27 Oct 2008 21:56] Konstantin Osipov
Patch:
--- sql/ha_partition.cc	2008-10-13 19:26:56 +0000
+++ sql/ha_partition.cc	2008-10-27 21:33:42 +0000
@@ -5320,6 +5320,9 @@ int ha_partition::extra(enum ha_extra_fu
     /* Special actions for MERGE tables. Ignore. */
     break;
   }
+  /* Pass down MARK_AS_LOG_TABLE extra */
+  case HA_EXTRA_MARK_AS_LOG_TABLE:
+    DBUG_RETURN(loop_extra(operation));
   default:
   {
     /* Temporary crash to discover what is wrong */
[26 Nov 2008 4:29] Tatiana Azundris Nuernberg
confirmed on linux, presuming "any OS"
[17 Jul 2009 6:03] 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/78914

2978 Tatiana A. Nurnberg	2009-07-17
      Bug#40281, partitioning the general log table crashes the server
      
      We disallow the partitioning of a log table. You could however
      partition a table first, and then point logging to it. This is
      not only against the docs, it also crashes the server.
      
      We catch this case now.
     @ mysql-test/r/partition.result
        results for 40281
     @ mysql-test/t/partition.test
        test for 40281: show that trying to log to partitioned table fails rather
        to crash the server
     @ sql/ha_partition.cc
        Signal that we no longer support logging to partitioned tables,
        as per the docs.
     @ sql/sql_partition.cc
        Don't be so sure there even was an old SELECT.
        If there isn't, there's not only no point in going on here,
        it will also crash the server.
[31 Jul 2009 12: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/79767

3015 Tatiana A. Nurnberg	2009-07-31
      Bug#40281, partitioning the general log table crashes the server
      
      We disallow the partitioning of a log table. You could however
      partition a table first, and then point logging to it. This is
      not only against the docs, it also crashes the server.
      
      We catch this case now.
     @ mysql-test/r/partition.result
        results for 40281
     @ mysql-test/t/partition.test
        test for 40281: show that trying to log to partitioned table fails rather
        to crash the server
     @ sql/ha_partition.cc
        Signal that we no longer support logging to partitioned tables,
        as per the docs.
     @ sql/sql_partition.cc
        Some commands like "USE ..." have no select, yet we may try
        to parse partition info after their execution if user set a
        partitioned table as log target. This shouldn't lead to a
        NULL-deref/crash.
[3 Aug 2009 13:15] Davi Arnaut
Queued to 5.1-bugteam
[4 Aug 2009 19:52] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090804194615-h40sa098mx4z49qg) (version source revid:iggy@mysql.com-20090731204544-7nio1afvg0dmzs7g) (merge vers: 5.4.4-alpha) (pib:11)
[4 Aug 2009 20:45] Bugs System
Pushed into 5.1.38 (revid:davi.arnaut@sun.com-20090804204317-ggodqkik7de6nfpz) (version source revid:davi.arnaut@sun.com-20090804204317-ggodqkik7de6nfpz) (merge vers: 5.1.38) (pib:11)
[7 Aug 2009 16:25] 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/80385

3482 Mikael Ronstrom	2009-08-07 [merge]
      Merge handling for mainly bug#40281
      removed:
        mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result
        mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt
        mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt
      added:
        mysql-test/r/innodb_mysql_lock.result
        mysql-test/r/partition_not_embedded.result
        mysql-test/r/partition_rename_longfilename.result
        mysql-test/std_data/loadxml2.dat
        mysql-test/suite/rpl/r/rpl_stop_middle_group.result
        mysql-test/t/innodb_mysql_lock-master.opt
        mysql-test/t/innodb_mysql_lock.test
        mysql-test/t/partition_not_embedded.test
        mysql-test/t/partition_rename_longfilename.test
      renamed:
        mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test => mysql-test/suite/rpl/t/rpl_stop_middle_group.test
      modified:
        .bzr-mysql/default.conf
        CMakeLists.txt
        Makefile.am
        client/Makefile.am
        client/mysql.cc
        client/mysqldump.c
        client/mysqltest.cc
        config/ac-macros/misc.m4
        config/ac-macros/readline.m4
        include/config-netware.h
        include/config-win.h
        include/my_base.h
        include/myisammrg.h
        libmysql/Makefile.shared
        libmysqld/Makefile.am
        libmysqld/emb_qcache.h
        libmysqld/lib_sql.cc
        mysql-test/collections/default.experimental
        mysql-test/collections/mysql-azalea.push
        mysql-test/extra/scripts/monitor_disabled_tests/comments.txt
        mysql-test/r/create.result
        mysql-test/r/debug_sync.result
        mysql-test/r/func_str.result
        mysql-test/r/innodb_mysql.result
        mysql-test/r/insert.result
        mysql-test/r/insert_select.result
        mysql-test/r/loadxml.result
        mysql-test/r/lock.result
        mysql-test/r/locktrans_innodb.result
        mysql-test/r/locktrans_myisam.result
        mysql-test/r/merge.result
        mysql-test/r/myisam.result
        mysql-test/r/mysql.result
        mysql-test/r/mysqldump.result
        mysql-test/r/outfile_loaddata.result
        mysql-test/r/partition.result
        mysql-test/r/partition_csv.result
        mysql-test/r/partition_error.result
        mysql-test/r/show_check.result
        mysql-test/r/signal.result
        mysql-test/r/signal_demo3.result
        mysql-test/r/sp_notembedded.result
        mysql-test/r/sp_trans.result
        mysql-test/std_data/init_file.dat
        mysql-test/suite/backup/r/backup_db_grants.result
        mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result
        mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt
        mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test
        mysql-test/suite/parts/r/partition_syntax_innodb.result
        mysql-test/suite/parts/r/partition_syntax_myisam.result
        mysql-test/suite/rpl/r/rpl_innodb.result
        mysql-test/suite/rpl/r/rpl_locktrans_innodb.result
        mysql-test/suite/rpl/r/rpl_locktrans_myisam.result
        mysql-test/suite/rpl/r/rpl_semi_sync.result
        mysql-test/suite/rpl/r/rpl_sf.result
        mysql-test/suite/rpl/r/rpl_temp_table_mix_row.result
        mysql-test/suite/rpl/r/rpl_udf.result
        mysql-test/suite/rpl/t/disabled.def
        mysql-test/suite/rpl/t/rpl_innodb.test
        mysql-test/suite/rpl/t/rpl_semi_sync.test
        mysql-test/suite/rpl/t/rpl_sf.test
        mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test
        mysql-test/t/create.test
        mysql-test/t/disabled.def
        mysql-test/t/innodb_mysql.test
        mysql-test/t/innodb_notembedded.test
        mysql-test/t/insert.test
        mysql-test/t/insert_select.test
        mysql-test/t/loadxml.test
        mysql-test/t/lock.test
        mysql-test/t/merge.test
        mysql-test/t/myisam.test
        mysql-test/t/mysql.test
        mysql-test/t/mysql_upgrade.test
        mysql-test/t/mysqldump.test
        mysql-test/t/outfile_loaddata.test
        mysql-test/t/partition.test
        mysql-test/t/partition_csv.test
        mysql-test/t/partition_error.test
        mysql-test/t/show_check.test
        mysql-test/t/sp_notembedded.test
        mysql-test/t/sp_trans.test
        mysql-test/valgrind.supp
        mysys/Makefile.am
        mysys/array.c
        mysys/my_handler_errors.h
        netware/BUILD/compile-netware-START
        plugin/semisync/semisync_master.cc
        plugin/semisync/semisync_master_plugin.cc
        plugin/semisync/semisync_slave_plugin.cc
        scripts/make_binary_distribution.sh
        sql-bench/README*
        sql-common/client.c
        sql/Makefile.am
        sql/backup/be_thread.cc
        sql/derror.cc
        sql/event_data_objects.cc
        sql/event_scheduler.cc
        sql/events.cc
        sql/field.cc
        sql/ha_partition.cc
        sql/handler.cc
        sql/handler.h
        sql/item_func.cc
        sql/lex.h
        sql/log.cc
        sql/log_event.cc
        sql/log_event_old.cc
        sql/mysql_priv.h
        sql/mysqld.cc
        sql/net_serv.cc
        sql/protocol.cc
        sql/protocol.h
        sql/rpl_rli.cc
        sql/rpl_rli.h
        sql/set_var.cc
        sql/share/errmsg-utf8.txt
        sql/share/errmsg.txt
        sql/slave.cc
        sql/sp.cc
        sql/sp.h
        sql/sp_head.cc
        sql/sql_base.cc
        sql/sql_class.cc
        sql/sql_class.h
        sql/sql_error.cc
        sql/sql_error.h
        sql/sql_insert.cc
        sql/sql_lex.h
        sql/sql_load.cc
        sql/sql_parse.cc
        sql/sql_partition.cc
        sql/sql_prepare.cc
        sql/sql_repl.cc
        sql/sql_select.cc
        sql/sql_show.cc
        sql/sql_signal.cc
        sql/sql_signal.h
        sql/sql_string.cc
        sql/sql_string.h
        sql/sql_table.cc
        sql/sql_update.cc
        sql/sql_yacc.yy
        sql/table.cc
        sql/table.h
        sql/unireg.h
        storage/innobase/handler/ha_innodb.cc
        storage/myisam/ha_myisam.cc
        storage/myisam/myisam_backup_engine.cc
        storage/myisammrg/ha_myisammrg.cc
        storage/myisammrg/ha_myisammrg.h
        storage/myisammrg/myrg_info.c
        storage/ndb/src/mgmsrv/Makefile.am
        support-files/mysql.server.sh
        tests/grant.pl*
        tests/mysql_client_test.c
        mysql-test/suite/rpl/t/rpl_stop_middle_group.test
[7 Aug 2009 20:33] Paul DuBois
Noted in 5.1.38, 5.4.4 changelog.

Partitioning a log table caused a server crash.
[12 Aug 2009 22:49] Paul DuBois
Noted in 5.4.2 changelog because next 5.4 version will be 5.4.2 and not 5.4.4.
[15 Aug 2009 2:04] Paul DuBois
Ignore previous comment about 5.4.2.
[14 Sep 2009 16:05] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090914155317-m1g9wodmndzdj4l1) (version source revid:alik@sun.com-20090914155317-m1g9wodmndzdj4l1) (merge vers: 5.4.4-alpha) (pib:11)
[1 Oct 2009 5:59] Bugs System
Pushed into 5.1.39-ndb-6.3.28 (revid:jonas@mysql.com-20091001055605-ap2kiaarr7p40mmv) (version source revid:jonas@mysql.com-20091001055605-ap2kiaarr7p40mmv) (merge vers: 5.1.39-ndb-6.3.28) (pib:11)
[1 Oct 2009 7:25] Bugs System
Pushed into 5.1.39-ndb-7.0.9 (revid:jonas@mysql.com-20091001072547-kv17uu06hfjhgjay) (version source revid:jonas@mysql.com-20091001071652-irejtnumzbpsbgk2) (merge vers: 5.1.39-ndb-7.0.9) (pib:11)
[1 Oct 2009 13:25] Bugs System
Pushed into 5.1.39-ndb-7.1.0 (revid:jonas@mysql.com-20091001123013-g9ob2tsyctpw6zs0) (version source revid:jonas@mysql.com-20091001123013-g9ob2tsyctpw6zs0) (merge vers: 5.1.39-ndb-7.1.0) (pib:11)
[5 Oct 2009 10:50] Bugs System
Pushed into 5.1.39-ndb-6.2.19 (revid:jonas@mysql.com-20091005103850-dwij2dojwpvf5hi6) (version source revid:jonas@mysql.com-20090930185117-bhud4ek1y0hsj1nv) (merge vers: 5.1.39-ndb-6.2.19) (pib:11)
[8 Oct 2009 19:40] Paul DuBois
The 5.4 fix has been pushed to 5.4.2.