[MDEV-25951] MariaDB crash after ALTER TABLE convert to utf8mb4 Created: 2021-06-17  Updated: 2021-11-18  Due: 2021-09-28  Resolved: 2021-09-08

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.4.19, 10.5.10, 10.4, 10.5, 10.6
Fix Version/s: 10.4.22, 10.5.13, 10.6.5

Type: Bug Priority: Critical
Reporter: Joris de Leeuw Assignee: Eugene Kosov (Inactive)
Resolution: Fixed Votes: 4
Labels: None
Environment:

OS: CloudLinux like RHEL - Kernel 4.18.0-147.8.1.el8.lve.1.x86_64


Issue Links:
Duplicate
is duplicated by MDEV-26116 Assertion failure in data0type.cc lin... Closed
is duplicated by MDEV-26379 Assertion `field->col->is_binary() ||... Closed
Relates
relates to MDEV-20726 InnoDB: Assertion failure in file dat... Closed
relates to MDEV-22899 Assertion `field->col->is_binary() ||... Closed
relates to MDEV-24419 Galera crash after ALTER TABLE conver... Closed

 Description   

We run rather large production servers with over hundreds of databases with varying sizes between a few MB and many GB.

Over the past few days we noticed that sometimes MariaDB seems to quit responding on our production servers.

We found out that this behaviour can be triggered if someone updates their WordPress website. When WordPress is updated it also performs some database queries to convert tables to utf8mb4.

E.g. the following query is done:

ALTER TABLE wp_usermeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

This causes MariaDB to complete stop responding for about 15 seconds and than recovers.

This is very unwanted behaviour because customers keep trying to update their website causing MariaDB to not respond multiple times over a short duration.

The following is logged during the crash:

2021-06-16 14:46:11 0x7fcc332b3700  InnoDB: Assertion failure in file /builddir/build/BUILD/mariadb-10.4.19/storage/innobase/data/data0type.cc line 67
InnoDB: Failing assertion: !(prefix_len % mbmaxlen)
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to https://jira.mariadb.org/
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: https://mariadb.com/kb/en/library/innodb-recovery-modes/
InnoDB: about forcing recovery.
210616 14:46:11 [ERROR] 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.
 
To report this bug, see https://mariadb.com/kb/en/reporting-bugs
 
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.
 
Server version: 10.4.19-MariaDB-log-cll-lve
key_buffer_size=67108864
read_buffer_size=1048576
max_used_connections=32
max_threads=502
thread_count=24
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 1106098 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
 
Thread pointer: 0x7fcc0b149388
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 = 0x7fcc332b13d8 thread_stack 0x40000
/usr/sbin/mysqld(my_print_stacktrace+0x2e)[0x561d6dcc656e]
/usr/sbin/mysqld(handle_fatal_signal+0x54d)[0x561d6d7b5d9d]
sigaction.c:0(__restore_rt)[0x7fcc68745b30]
:0(__GI_raise)[0x7fcc67a8c84f]
:0(__GI_abort)[0x7fcc67a76c45]
/usr/sbin/mysqld(+0x5b52a8)[0x561d6d4a92a8]
/usr/sbin/mysqld(+0x5c11d7)[0x561d6d4b51d7]
/usr/sbin/mysqld(+0xb135f3)[0x561d6da075f3]
/usr/sbin/mysqld(+0xb1b573)[0x561d6da0f573]
/usr/sbin/mysqld(+0xb1dff1)[0x561d6da11ff1]
/usr/sbin/mysqld(+0xa81618)[0x561d6d975618]
/usr/sbin/mysqld(_Z17mysql_alter_tableP3THDPK25st_mysql_const_lex_stringS3_P14HA_CREATE_INFOP10TABLE_LISTP10Alter_infojP8st_orderb+0x3dc7)[0x561d6d646377]
/usr/sbin/mysqld(_ZN19Sql_cmd_alter_table7executeEP3THD+0x347)[0x561d6d69ac37]
/usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x137e)[0x561d6d5a862e]
/usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_statebb+0x2c5)[0x561d6d5aeeb5]
/usr/sbin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcjbb+0x1602)[0x561d6d5b1412]
/usr/sbin/mysqld(_Z10do_commandP3THD+0x13a)[0x561d6d5b28ca]
/usr/sbin/mysqld(_Z24do_handle_one_connectionP7CONNECT+0x25e)[0x561d6d6967de]
/usr/sbin/mysqld(handle_one_connection+0x3d)[0x561d6d6968ad]
pthread_create.c:0(start_thread)[0x7fcc6873b15a]
/lib64/libc.so.6(clone+0x43)[0x7fcc67b51f73]
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7fcc02b64c60): ALTER TABLE wp_usermeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
 
Connection ID (thread ID): 4914
Status: NOT_KILLED
 
Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,m
aterialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_
cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on
 
The manual page at https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mysqld/ contains
information that should help you find out what is causing the crash.
Writing a core file...
Working directory at /var/lib/mysql
Resource Limits:
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             514122               514122               processes 
Max open files            51200                51200                files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       514122               514122               signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        
Core pattern: |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e
 
2021-06-16 14:46:18 0 [Warning] You need to use --log-bin to make --binlog-format work.
2021-06-16 14:46:18 0 [Warning] The parameter innodb_file_format is deprecated and has no effect. It may be removed in future releases. See https://mariadb.com/kb/en/library/xtradbinnodb-file-format/
2021-06-16 14:46:18 0 [Warning] InnoDB: Setting innodb_checksum_algorithm to values other than crc32, full_crc32, strict_crc32 or strict_full_crc32 is UNSAFE and DEPRECATED. These deprecated values will be disallowed in MariaDB 10.6.
2021-06-16 14:46:18 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-06-16 14:46:18 0 [Note] InnoDB: Uses event mutexes
2021-06-16 14:46:18 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-06-16 14:46:18 0 [Note] InnoDB: Number of pools: 1
2021-06-16 14:46:18 0 [Note] InnoDB: Using SSE2 crc32 instructions
2021-06-16 14:46:18 0 [Note] mysqld: O_TMPFILE is not supported on /var/lib/mysql_tmp (disabling future attempts)
2021-06-16 14:46:18 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2021-06-16 14:46:18 0 [Note] InnoDB: Completed initialization of buffer pool
2021-06-16 14:46:18 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-06-16 14:46:18 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=30378586209559
2021-06-16 14:46:19 0 [Note] InnoDB: Starting final batch to recover 220 pages from redo log.
2021-06-16 14:46:24 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2021-06-16 14:46:24 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2021-06-16 14:46:24 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-06-16 14:46:24 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-06-16 14:46:24 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-06-16 14:46:24 0 [Note] InnoDB: Waiting for purge to start
2021-06-16 14:46:24 0 [Note] InnoDB: 10.4.19 started; log sequence number 30378586621666; transaction id 47558113933
2021-06-16 14:46:24 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-06-16 14:46:24 0 [Note] Plugin 'FEEDBACK' is disabled.
2021-06-16 14:46:24 0 [Note] Server socket created on IP: '::'.
2021-06-16 14:46:24 0 [Note] Reading of all Master_info entries succeeded
2021-06-16 14:46:24 0 [Note] Added new Master_info '' to hash table
2021-06-16 14:46:24 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.4.19-MariaDB-log-cll-lve'  socket: '/var/lib/mysql_sock/mysql.sock'  port: 3306  MariaDB Server
2021-06-16 14:46:24 0 [Note] InnoDB: Buffer pool(s) load completed at 210616 14:46:24



 Comments   
Comment by Alice Sherepa [ 2021-06-28 ]

Reproducible on 10.4-10.6

-- source include/have_innodb.inc
 
CREATE TABLE t1 (a varchar(32), KEY (a(4))) engine=innodb DEFAULT charset=utf8;
insert into t1 values ('a1'),('a1'),('a1'),('a1'),('a1'),('a1'),('a1');
 
ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;

10.4 09b03ff31b8fd71aee265c224

mysqld: /10.4/src/storage/innobase/dict/dict0dict.cc:1910: dberr_t dict_index_add_to_cache(dict_index_t*&, ulint, const dict_add_v_col_t*): Assertion `field->col->is_binary() || field->prefix_len % field->col->mbmaxlen == 0' failed.
210628 15:04:24 [ERROR] mysqld got signal 6 ;
 
Server version: 10.4.21-MariaDB-debug-log
 
linux/raise.c:51(__GI_raise)[0x7effcc88d18b]
stdlib/abort.c:81(__GI_abort)[0x7effcc86c859]
intl/loadmsgcat.c:509(get_sysdep_segment_value)[0x7effcc86c729]
:0(__GI___assert_fail)[0x7effcc87df36]
dict/dict0dict.cc:1912(dict_index_add_to_cache(dict_index_t*&, unsigned long, dict_add_v_col_t const*))[0x559f1a86e71e]
dict/dict0crea.cc:1249(dict_create_index_step(que_thr_t*))[0x559f1a8531d1]
que/que0que.cc:1048(que_thr_step(que_thr_t*))[0x559f1a4505c0]
que/que0que.cc:1100(que_run_threads_low(que_thr_t*))[0x559f1a4509a9]
que/que0que.cc:1142(que_run_threads(que_thr_t*))[0x559f1a450e08]
handler/handler0alter.cc:6191(create_index_dict(trx_t*, dict_index_t*, dict_add_v_col_t const*))[0x559f1a24d3e5]
handler/handler0alter.cc:7048(prepare_inplace_alter_table_dict(Alter_inplace_info*, TABLE const*, TABLE const*, char const*, unsigned long, unsigned long, unsigned long, bool, bool))[0x559f1a256ff6]
handler/handler0alter.cc:8343(ha_innobase::prepare_inplace_alter_table(TABLE*, Alter_inplace_info*))[0x559f1a263424]
sql/handler.cc:4609(handler::ha_prepare_inplace_alter_table(TABLE*, Alter_inplace_info*))[0x559f19bf8ba0]
sql/sql_table.cc:7785(mysql_inplace_alter_table(THD*, TABLE_LIST*, TABLE*, TABLE*, Alter_inplace_info*, MDL_request*, Alter_table_ctx*))[0x559f19637ef1]
sql/sql_table.cc:10248(mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool))[0x559f19649d0e]
sql/sql_alter.cc:520(Sql_cmd_alter_table::execute(THD*))[0x559f197cd346]
sql/sql_parse.cc:6189(mysql_execute_command(THD*))[0x559f193de226]
sql/sql_parse.cc:7992(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x559f193e9d73]
sql/sql_parse.cc:1860(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x559f193c0523]
sql/sql_parse.cc:1373(do_command(THD*))[0x559f193bcfa0]
sql/sql_connect.cc:1412(do_handle_one_connection(CONNECT*))[0x559f197b490a]
sql/sql_connect.cc:1317(handle_one_connection)[0x559f197b41ae]
perfschema/pfs.cc:1871(pfs_spawn_thread)[0x559f1ae8a71b]
nptl/pthread_create.c:478(start_thread)[0x7effccd94609]
x86_64/clone.S:97(__GI___clone)[0x7effcc969293]
 
Query (0x62b0000a1290): ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci

10.5.11

Version: '10.5.11-MariaDB'  
2021-06-28 13:17:53 0x7fc428310700  InnoDB: Assertion failure in file /home/buildbot/buildbot/build/storage/innobase/data/data0type.cc line 67
InnoDB: Failing assertion: !(prefix_len % mbmaxlen)
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to https://jira.mariadb.org/
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: https://mariadb.com/kb/en/library/innodb-recovery-modes/
InnoDB: about forcing recovery.
210628 13:17:53 [ERROR] mysqld got signal 6 ;
 
Server version: 10.5.11-MariaDB
 
linux/raise.c:51(__GI_raise)[0x7fc4295d17bb]
stdlib/abort.c:81(__GI_abort)[0x7fc4295bc535]
:0(ut_dbg_assertion_failed(char const*, char const*, unsigned int))[0x55c7bc0a92df]
data/data0type.cc:67(dtype_get_at_most_n_mbchars(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, char const*))[0x55c7bc8ab39c]
include/data0data.ic:54(dfield_set_len)[0x55c7bc7aecd7]
row/row0merge.cc:2340(row_merge_read_clustered_index(trx_t*, TABLE*, dict_table_t const*, dict_table_t*, bool, dict_index_t**, dict_index_t*, fts_psort_t*, merge_file_t*, unsigned long const*, unsigned long, dtuple_t const*, dict_add_v_col_t const*, unsigned long const*, unsigned long, ib_sequence_t&, unsigned char*, bool, pfs_os_file_t*, ut_stage_alter_t*, double, unsigned char*, TABLE*, bool))[0x55c7bc7b4d92]
row/row0merge.cc:4539(row_merge_build_indexes(trx_t*, dict_table_t*, dict_table_t*, bool, dict_index_t**, unsigned long const*, unsigned long, TABLE*, dtuple_t const*, unsigned long const*, unsigned long, ib_sequence_t&, bool, ut_stage_alter_t*, dict_add_v_col_t const*, TABLE*, bool))[0x55c7bc7b74b4]
handler/handler0alter.cc:8491(ha_innobase::inplace_alter_table(TABLE*, Alter_inplace_info*))[0x55c7bc706cdc]
sql/sql_table.cc:8116(mysql_inplace_alter_table)[0x55c7bc26ad51]
sql/sql_alter.cc:545(Sql_cmd_alter_table::execute(THD*))[0x55c7bc2c8b4e]
sql/sql_parse.cc:6052(mysql_execute_command(THD*))[0x55c7bc1d0300]
sql/sql_parse.cc:8096(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55c7bc1d3ba9]
sql/sql_audit.h:169(mysql_audit_general)[0x55c7bc1d64fd]
sql/sql_parse.cc:1375(do_command(THD*))[0x55c7bc1d7edf]
sql/sql_connect.cc:1410(do_handle_one_connection(CONNECT*, bool))[0x55c7bc2c3e52]
sql/sql_connect.cc:1318(handle_one_connection)[0x55c7bc2c4114]
perfschema/pfs.cc:2204(pfs_spawn_thread)[0x55c7bc64a13d]
nptl/pthread_create.c:487(start_thread)[0x7fc429a70fa3]
x86_64/clone.S:97(clone)[0x7fc4296934cf]
 
Query (0x7fc3bc011e20): ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci

Comment by Laurence Parry [ 2021-07-18 ]

I got this as well, trying to upgrade Drupal 6's node table to enable emoji support.
I was converting from utf8_general_ci to utf8mb4_general_nopad_ci.

I first reduced the size of the `title` field (from 255, I think).
This resolved failures on other tables due to index prefix length, but when I tried with `node`, it crashed.
I deleted the node_type and node_title_type indexes and it worked. They could be recreated afterwards.

Below shows the table structure after recreation.

CREATE TABLE `node` (
  `nid` int(10) UNSIGNED NOT NULL,
  `vid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `type` varchar(32) COLLATE utf8mb4_general_nopad_ci NOT NULL DEFAULT '',
  `language` varchar(12) COLLATE utf8mb4_general_nopad_ci NOT NULL DEFAULT '',
  `title` varchar(129) COLLATE utf8mb4_general_nopad_ci NOT NULL DEFAULT '',
  `uid` int(11) NOT NULL DEFAULT 0,
  `status` int(11) NOT NULL DEFAULT 1,
  `created` int(11) NOT NULL DEFAULT 0,
  `changed` int(11) NOT NULL DEFAULT 0,
  `comment` int(11) NOT NULL DEFAULT 0,
  `promote` int(11) NOT NULL DEFAULT 0,
  `moderate` int(11) NOT NULL DEFAULT 0,
  `sticky` int(11) NOT NULL DEFAULT 0,
  `tnid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `translate` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_nopad_ci;
 
ALTER TABLE `node`
  ADD PRIMARY KEY (`nid`),
  ADD UNIQUE KEY `vid` (`vid`),
  ADD KEY `node_changed` (`changed`),
  ADD KEY `node_created` (`created`),
  ADD KEY `node_moderate` (`moderate`),
  ADD KEY `node_promote_status` (`promote`,`status`),
  ADD KEY `node_status_type` (`status`,`type`,`nid`),
  ADD KEY `uid` (`uid`),
  ADD KEY `tnid` (`tnid`),
  ADD KEY `translate` (`translate`),
  ADD KEY `node_type` (`type`(4)),
  ADD KEY `node_title_type` (`title`,`type`(4));
 
ALTER TABLE `node`
  MODIFY `nid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
COMMIT;

The error output:

2021-07-18 16:20:03 0x83c010f00  InnoDB: Assertion failure in file storage/innobase/data/data0type.cc line 67
InnoDB: Failing assertion: !(prefix_len % mbmaxlen)
[..memory trap..]
Server version: 10.5.11-MariaDB
key_buffer_size=157286400
read_buffer_size=1048576
max_used_connections=11
max_threads=152
thread_count=11
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 935403 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
 
Thread pointer: 0x83d878b58
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 = 0x7fffde05af38 thread_stack 0x49000
0x12c666c <my_print_stacktrace+0x3c> at /usr/local/libexec/mariadbd
0xc41eae <handle_fatal_signal+0x28e> at /usr/local/libexec/mariadbd
0x802e18c80 <pthread_sigmask+0x530> at /lib/libthr.so.3
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x83d89c428): ALTER TABLE `node` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_nopad_ci
 
Connection ID (thread ID): 1331
Status: NOT_KILLED
 
Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off

Comment by Ashish SHUKLA [ 2021-09-01 ]

We also had a similar crash with following test case on MariaDB 10.4.21:

{{DROP TABLE IF EXISTS `mfa_usermeta`;
CREATE TABLE `mfa_usermeta` (
`umeta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL DEFAULT 0,
`meta_key` varchar(255) DEFAULT NULL,
`meta_value` longtext DEFAULT NULL,
PRIMARY KEY (`umeta_id`),
KEY `user_id` (`user_id`),
KEY `meta_key` (`meta_key`(191))
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8;
INSERT INTO mfa_usermeta VALUES (1,1,'','');
ALTER TABLE mfa_usermeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;}}

Excerpt from the log file:

{{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.

Server version: 10.4.21-MariaDB-log
key_buffer_size=134217728
read_buffer_size=4194304
max_used_connections=9
max_threads=502
thread_count=15
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 4255875 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x7ff18681e008
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 = 0x7ff198fbfe30 thread_stack 0x40000
mysys/stacktrace.c:175(my_print_stacktrace)[0x5595fad7ecce]
sql/signal_handler.cc:222(handle_fatal_signal)[0x5595fa7639df]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x110e0)[0x7ff19b6ce0e0]
linux/raise.c:51(__GI_raise)[0x7ff19aac6fff]
stdlib/abort.c:91(__GI_abort)[0x7ff19aac842a]
ut/ut0rbt.cc:218(rbt_tree_add_child(ib_rbt_t const*, ib_rbt_bound_t*, ib_rbt_node_t*) [clone .isra.4] [clone .part.5])[0x5595fa454888]
data/data0type.cc:67(dtype_get_at_most_n_mbchars(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, char const*))[0x5595faac4acc]
include/data0data.ic:54(dfield_set_len)[0x5595fa9d15ef]
row/row0merge.cc:2355(row_merge_read_clustered_index(trx_t*, TABLE*, dict_table_t const*, dict_table_t*, bool, dict_index_t*, dict_index_t, fts_psort_t*, merge_file_t*, unsigned long const*, unsigned long, dtuple_t const*, dict_add_v_col_t const*, unsigned long cons
t*, unsigned long, ib_sequence_t&, unsigned char*, bool, pfs_os_file_t*, ut_stage_alter_t*, double, unsigned char*, TABLE*, bool))[0x5595fa9d7acf]
include/ut0stage.h:434(ut_stage_alter_t::reestimate())[0x5595fa9da07f]
handler/handler0alter.cc:8559(ha_innobase::inplace_alter_table(TABLE*, Alter_inplace_info*))[0x5595fa92f9c0]
sql/sql_table.cc:7822(mysql_inplace_alter_table(THD*, TABLE_LIST*, TABLE*, TABLE*, Alter_inplace_info*, MDL_request*, Alter_table_ctx*) [clone .isra.337] [clone .constprop.411])[0x5595fa443060]
sql/sql_table.cc:10254(mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool))[0x5595fa5e9677]
sql/sql_alter.cc:526(Sql_cmd_alter_table::execute(THD*))[0x5595fa6401f5]
sql/sql_parse.cc:6192(mysql_execute_command(THD*))[0x5595fa550772]
sql/sql_parse.cc:7995(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x5595fa556d52]
sql/sql_parse.cc:1919(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x5595fa5596ec]
sql/sql_parse.cc:1374(do_command(THD*))[0x5595fa55ac8b]
sql/sql_connect.cc:1420(do_handle_one_connection(CONNECT*))[0x5595fa63bc62]
sql/sql_connect.cc:1318(handle_one_connection)[0x5595fa63bd4d]
nptl/pthread_create.c:456(start_thread)[0x7ff19b6c44a4]
x86_64/clone.S:99(clone)[0x7ff19ab7cd0f]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7ff18685d020): ALTER TABLE mfa_usermeta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

Connection ID (thread ID): 19
Status: NOT_KILLED

Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,mat
erialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cach
e_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on}}

Thanks in advance.

Comment by Eugene Kosov (Inactive) [ 2021-09-06 ]

The bug happens when a partially indexes CHAR or VARCHAR field in converted from utf8mb3 to utf8mb4.

3  0x00007faa31be8662 in __GI___assert_fail (assertion=0x5e13e6 "field->col->is_binary() || field->prefix_len % field->col->mbmaxlen == 0", file=0x5d46d7 "../storage/innobase/dict/dict0dict.cc", line=1919, function=0x4e30bc "dberr_t dict_index_add_to_cache(dict_index_t *&, ulint, const dict_add_v_col_t *)") at assert.c:101
#4  0x00000000012ca9ce in dict_index_add_to_cache (index=@0x7faa200424f8: 0x7faa20119a70, page_no=4294967295, add_v=0x0) at dict0dict.cc:1918
#5  0x00000000014648f4 in dict_create_index_step (thr=0x7faa2005ca68) at dict0crea.cc:1249
#6  0x00000000015bc1d6 in que_thr_step (thr=0x7faa2005ca68) at que0que.cc:1048
#7  0x00000000015bb2a0 in que_run_threads_low (thr=0x7faa2005ca68) at que0que.cc:1100
#8  0x00000000015bafd7 in que_run_threads (thr=0x7faa2005ca68) at que0que.cc:1140
#9  0x00000000014a7ba6 in create_index_dict (trx=0x7faa30991208, index=0x7faa20119a70, add_v=0x0) at handler0alter.cc:6189
#10 0x000000000149762a in prepare_inplace_alter_table_dict (ha_alter_info=0x7faa080a8f10, altered_table=0x7faa080a7bb8, old_table=0x7faa20092408, table_name=0x7faa2003fafd "t1", flags=33, flags2=80, fts_doc_id_col=18446744073709551615, add_fts_doc_id=false, add_fts_doc_id_idx=false) at handler0alter.cc:7048
#11 0x000000000148fafd in ha_innobase::prepare_inplace_alter_table (this=0x7faa20093200, altered_table=0x7faa080a7bb8, ha_alter_info=0x7faa080a8f10) at handler0alter.cc:8356
#12 0x0000000000c2ecf1 in handler::ha_prepare_inplace_alter_table (this=0x7faa20093200, altered_table=0x7faa080a7bb8, ha_alter_info=0x7faa080a8f10) at handler.cc:4622
#13 0x0000000000fbc32b in mysql_inplace_alter_table (thd=0x7faa2000ada8, table_list=0x7faa2001d7b0, table=0x7faa20092408, altered_table=0x7faa080a7bb8, ha_alter_info=0x7faa080a8f10, target_mdl_request=0x7faa080a9838, alter_ctx=0x7faa080a99e8) at sql_table.cc:7785
#14 0x0000000000fb6a81 in mysql_alter_table (thd=0x7faa2000ada8, new_db=0x7faa2000f3e8, new_name=0x7faa2000f810, create_info=0x7faa080aad68, table_list=0x7faa2001d7b0, alter_info=0x7faa080aacb0, order_num=0, order=0x0, ignore=false) at sql_table.cc:10251
#15 0x0000000001065cad in Sql_cmd_alter_table::execute (this=0x7faa2001dea0, thd=0x7faa2000ada8) at sql_alter.cc:520
#16 0x0000000000ebb97e in mysql_execute_command (thd=0x7faa2000ada8) at sql_parse.cc:6192
#17 0x0000000000ea8dda in mysql_parse (thd=0x7faa2000ada8, rawbuf=0x7faa2001d670 "ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci", length=78, parser_state=0x7faa080ad6c8, is_com_multi=false, is_next_command=false) at sql_parse.cc:7995

1918                                ut_ad(field->col->is_binary()
1919                                      || field->prefix_len % field->col->mbmaxlen == 0);

(rr) p *field
$3 = {
  col = 0x7faa20040b00,
  name = 0x7faa20040bdb "a",
  prefix_len = 28,
  fixed_len = 0
}
(rr) p *field->col
$4 = {
  prtype = 2162703,
  mtype = 12,
  len = 96,
  mbminlen = 1,
  mbmaxlen = 3,
  ind = 1,
  ord_part = 1,
  max_prefix = 21,
  def_val = {
    data = 0x0,
    len = 4294967294
  }
}

Here fields points for an old col which is still mbmaxlen=3. And this is incorrect. The new index should point to a new column definition. But there is no now column definition and no new dict_table_t object. New dict_table_t is created in a new_clustered=true code path in prepare_inplace_alter_table_dict() which involves creating the whole dict_table_t and call to a row_create_table_for_mysql() which doesn't happen and should not happen for an instant column change. A possible fix is to disallow ALGORITHM=NOCOPY for this very case.

Generated at Thu Feb 08 09:41:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.