Bug #76209 mysqlcheck --optimize crashes when mysqld runs with --skip-new
Submitted: 7 Mar 2015 18:03 Modified: 1 Apr 2015 14:18
Reporter: M B Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:5.6.22, 5.6.23 OS:FreeBSD (8.4-RELEASE-p24)
Assigned to: CPU Architecture:Any
Tags: crash, mysqlcheck

[7 Mar 2015 18:03] M B
Description:
I'm running MySQL 5.6.22 installed from the FreeBSD ports collection.

I have a cron job that runs nightly to do this:
mysqlcheck --medium-check --auto-repair
mysqlcheck --all-databases --optimize

For the --optimize run, I got tired of seeing "Table does not support optimize, doing recreate + analyze instead" so I searched for that message and found that https://dev.mysql.com/doc/refman/5.6/en/optimize-table.html says I should run mysqld with --skip-new (which is apparently otherwise undocumented).

Since this is on FreeBSD, I added mysql_args="--skip-new" to /etc/rc.conf and ran 'service mysql-server restart'.

Well, once mysqld was invoked with --skip-new, running 'mysqlcheck --optimize' no longer complained about the tables not supporting optimize. Rather, it just dumped core immediately. 
The gdb backtrace says:
#0  0x080593fd in get_attr_key ()
#1  0x0804eefe in ?? ()
#2  0x00000000 in ?? ()

How to repeat:
Assuming you already have the mysql56-server-5.6.22 port installed and running, add to /etc/rc.conf:
mysql_args="--skip-new"

Then:

service mysql-server restart

Wait an extra 15 seconds to be sure it's really ready, and then:

mysqlcheck -uroot -pXXX --all-databases --optimize
[1 Apr 2015 14:18] MySQL Verification Team
Hello!

Thank you for the report.
Observed similar behavior at my end with 5.6.23 builds.

Thanks,
Umesh
[1 Apr 2015 14:19] MySQL Verification Team
//
[umshastr@pan17 ~/freebsd]$ md5 mysql-5.6.23-freebsd9.0-x86_64.tar.gz
MD5 (mysql-5.6.23-freebsd9.0-x86_64.tar.gz) = 0ca5f42830e37d2735f030304c5f529d

[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ more docs/INFO_SRC
commit: 19ff9770da1307a8b44be40beaa456c4d1149c2a
date: 2015-01-19 14:26:20 +0100
build-date: 2015-01-19 14:38:00 +0100
short: 19ff977
branch: mysql-5.6.23-release

MySQL source 5.6.23

[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ uname -an
FreeBSD pan17.se.oracle.com 9.3-RELEASE FreeBSD 9.3-RELEASE #0 r268512: Thu Jul 10 23:44:39 UTC 2014     root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

// Startup
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ scripts/mysql_install_db --basedir=/home/umshastr/freebsd/mysql-5.6.23-freebsd9.0-x86_64 --datadir=/tmp/76209
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ bin/mysqld --basedir=/home/umshastr/freebsd/mysql-5.6.23-freebsd9.0-x86_64 --datadir=/tmp/76209 --core-file --socket=/tmp/mysql_ushastry.sock  --port=15000 --skip-new 2>&1 &
[1] 53302
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ 2015-04-01 15:57:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-04-01 15:57:00 53302 [Note] Plugin 'FEDERATED' is disabled.
2015-04-01 15:57:00 53302 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-04-01 15:57:00 53302 [Note] InnoDB: The InnoDB memory heap is disabled
2015-04-01 15:57:00 53302 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-04-01 15:57:00 53302 [Note] InnoDB: Memory barrier is not used
2015-04-01 15:57:00 53302 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-04-01 15:57:00 53302 [Note] InnoDB: Not using CPU crc32 instructions
2015-04-01 15:57:00 53302 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-04-01 15:57:00 53302 [Note] InnoDB: Completed initialization of buffer pool
2015-04-01 15:57:00 53302 [Note] InnoDB: Highest supported file format is Barracuda.
2015-04-01 15:57:00 53302 [Note] InnoDB: 128 rollback segment(s) are active.
2015-04-01 15:57:00 53302 [Note] InnoDB: Waiting for purge to start
2015-04-01 15:57:00 53302 [Note] InnoDB: 5.6.23 started; log sequence number 1625997
2015-04-01 15:57:00 53302 [Note] Server hostname (bind-address): '*'; port: 15000
2015-04-01 15:57:00 53302 [Note] IPv6 is available.
2015-04-01 15:57:00 53302 [Note]   - '::' resolves to '::';
2015-04-01 15:57:00 53302 [Note] Server socket created on IP: '::'.
2015-04-01 15:57:00 53302 [Note] Event Scheduler: Loaded 0 events
2015-04-01 15:57:00 53302 [Note] bin/mysqld: ready for connections.
Version: '5.6.23'  socket: '/tmp/mysql_ushastry.sock'  port: 15000  MySQL Community Server (GPL)

// Load somedata
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ bin/mysql -u root -p -S/tmp/mysql_ushastry.sock                                                                                        Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

..
mysql> use test
Database changed
mysql> drop table if exists keyvalue;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE TABLE `keyvalue` (
    ->   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    ->   `name1` varchar(250),
    ->   `name2` varchar(250),
    ->   `name3` varchar(250),
    ->   `name4` varchar(250),
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=innodb ROW_FORMAT=COMPRESSED;
..

Query OK, 100000 rows affected (5.47 sec)
Records: 100000  Duplicates: 0  Warnings: 0

mysql> \q
Bye

// run mysqlcheck with gdb

[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ bin/mysqlcheck -u root -p -S/tmp/mysql_ushastry.sock --all-databases --optimize
Enter password:
Segmentation fault: 11 (core dumped)

[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ gdb --args bin/mysqlcheck -u root -p -S/tmp/mysql_ushastry.sock --all-databases --optimize
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) run
Starting program: /home/umshastr/freebsd/mysql-5.6.23-freebsd9.0-x86_64/bin/mysqlcheck -u root -p -S/tmp/mysql_ushastry.sock --all-databases --optimize
[New LWP 100130]
[New Thread 801c07400 (LWP 100130/mysqlcheck)]
Enter password:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 801c07400 (LWP 100130/mysqlcheck)]
mysql_fetch_row (res=0x0) at /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/sql-common/client.c:4292
4292    /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/sql-common/client.c: No such file or directory.
        in /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/sql-common/client.c
(gdb) thread apply all bt

Thread 2 (Thread 801c07400 (LWP 100130/mysqlcheck)):
#0  mysql_fetch_row (res=0x0) at /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/sql-common/client.c:4292
#1  0x0000000000409cc0 in handle_request_for_tables (tables=0x801c9c040 "columns_priv", length=<value optimized out>)
    at /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/client/mysqlcheck.c:790
#2  0x000000000040a616 in process_one_db (database=0x801c98078 "mysql") at /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/client/mysqlcheck.c:605
#3  0x000000000040aecd in main (argc=0, argv=0x801c5f2c8) at /export/home/pb2/build/sb_0-14135570-1421675638.04/mysql-5.6.23/client/mysqlcheck.c:446
(gdb)
[1 Apr 2015 14:24] MySQL Verification Team
// without --skip-new

[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ bin/mysqladmin -u root -p -S/tmp/mysql_ushastry.sock shutdown
Enter password:
[1]+  Done                    bin/mysqld --basedir=/home/umshastr/freebsd/mysql-5.6.23-freebsd9.0-x86_64 --datadir=/tmp/76209 --core-file --socket=/tmp/mysql_ushastry.sock --port=15000 --skip-new --log_error=/tmp/76209/log.err 2>&1
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ bin/mysqld --basedir=/home/umshastr/freebsd/mysql-5.6.23-freebsd9.0-x86_64 --datadir=/tmp/76209 --core-file --socket=/tmp/mysql_ushastry.sock  --port=15000 --log_error=/tmp/76209/log.err 2>&1 &
[1] 54594
[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ 2015-04-01 16:23:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

[umshastr@pan17 ~/freebsd/mysql-5.6.23-freebsd9.0-x86_64]$ bin/mysqlcheck -u root -p -S/tmp/mysql_ushastry.sock --all-databases --optimize
Enter password:
mysql.columns_priv                                 Table is already up to date
mysql.db                                           OK
mysql.event                                        Table is already up to date
mysql.func                                         Table is already up to date
mysql.general_log
note     : The storage engine for the table doesn't support optimize
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats
note     : Table does not support optimize, doing recreate + analyze instead
status   : OK
mysql.innodb_table_stats
note     : Table does not support optimize, doing recreate + analyze instead
status   : OK
mysql.ndb_binlog_index                             Table is already up to date
mysql.plugin                                       Table is already up to date
mysql.proc                                         Table is already up to date
mysql.procs_priv                                   Table is already up to date
mysql.proxies_priv                                 OK
mysql.servers                                      Table is already up to date
mysql.slave_master_info
note     : Table does not support optimize, doing recreate + analyze instead
status   : OK
mysql.slave_relay_log_info
note     : Table does not support optimize, doing recreate + analyze instead
status   : OK
mysql.slave_worker_info
note     : Table does not support optimize, doing recreate + analyze instead
status   : OK
mysql.slow_log
note     : The storage engine for the table doesn't support optimize
mysql.tables_priv                                  Table is already up to date
mysql.time_zone                                    Table is already up to date
mysql.time_zone_leap_second                        Table is already up to date
mysql.time_zone_name                               Table is already up to date
mysql.time_zone_transition                         Table is already up to date
mysql.time_zone_transition_type                    Table is already up to date
mysql.user                                         OK
test.keyvalue
note     : Table does not support optimize, doing recreate + analyze instead