Bug #99403 Assertion ".conv_field->has_charset"
Submitted: 30 Apr 2020 6:53 Modified: 26 Aug 2020 22:01
Reporter: Hrvoje Matijakovic Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S6 (Debug Builds)
Version:8.0.20 OS:Linux
Assigned to: CPU Architecture:x86
Tags: regression

[30 Apr 2020 6:53] Hrvoje Matijakovic
Description:
Running following query results in assertion on the debug build.

gdb:
Core was generated by `/sdc/MS270420-mysql-8.0.20-linux-x86_64-debug/bin/mysqld --no-defaults --basedi'.
Program terminated with signal 6, Aborted.
#0  0x00007f38e5c79a61 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:59
59        val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
(gdb) bt
+bt
#0  0x00007f38e5c79a61 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:59
#1  0x0000000004aa3c56 in my_write_core (sig=6) at /sdc/MS-8.0.20_dbg/mysys/stacktrace.cc:308
#2  0x000000000374f2b5 in handle_fatal_signal (sig=6) at /sdc/MS-8.0.20_dbg/sql/signal_handler.cc:171
#3  <signal handler called>
#4  0x00007f38e3ac1337 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
#5  0x00007f38e3ac2a28 in __GI_abort () at abort.c:90
#6  0x00007f38e3aba156 in __assert_fail_base (fmt=0x7f38e3c15be0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5ee2510 "!conv_field->has_charset() || conv_field->charset() == &my_charset_utf8mb4_0900_bin", file=file@entry=0x5ee0b98 "/sdc/MS-8.0.20_dbg/sql/field.cc", line=line@entry=9999, function=function@entry=0x5ee6e80 <Field_typed_array::sql_type(String&) const::__PRETTY_FUNCTION__> "virtual void Field_typed_array::sql_type(String&) const") at assert.c:92
#7  0x00007f38e3aba202 in __GI___assert_fail (assertion=0x5ee2510 "!conv_field->has_charset() || conv_field->charset() == &my_charset_utf8mb4_0900_bin", file=0x5ee0b98 "/sdc/MS-8.0.20_dbg/sql/field.cc", line=9999, function=0x5ee6e80 <Field_typed_array::sql_type(String&) const::__PRETTY_FUNCTION__> "virtual void Field_typed_array::sql_type(String&) const") at assert.c:101                                                                                                       #8  0x00000000038c1cca in Field_typed_array::sql_type (this=0x7f388c0d2c50, str=...) at /sdc/MS-8.0.20_dbg/sql/field.cc:9998                                                                                                                  #9  0x000000000480554e in dd::get_sql_type_by_create_field (table=0x7f38e61446a0, field=...) at /sdc/MS-8.0.20_dbg/sql/dd/dd_table.cc:239
#10 0x0000000004806fa6 in dd::fill_dd_columns_from_create_fields (thd=0x7f388c020000, tab_obj=0x7f388c078ed0, create_fields=..., file=0x7f388c0d1028) at /sdc/MS-8.0.20_dbg/sql/dd/dd_table.cc:735
#11 0x000000000480c2b0 in dd::fill_dd_table_from_create_info (thd=0x7f388c020000, tab_obj=0x7f388c078ed0, table_name="#sql-a51_8", schema_name="test", create_info=0x7f38e61483d0, create_fields=..., keyinfo=0x7f388c0d26c8, keys=1, keys_onoff=Alter_info::LEAVE_AS_IS, fk_keyinfo=0x0, fk_keys=0, check_cons_spec=0x7f38e6148340, file=0x7f388c0d1028) at /sdc/MS-8.0.20_dbg/sql/dd/dd_table.cc:2137                                                                                     #12 0x000000000480db34 in dd::create_tmp_table (thd=0x7f388c020000, sch_obj=..., table_name="#sql-a51_8", create_info=0x7f38e61483d0, create_fields=..., keyinfo=0x7f388c0d26c8, keys=1, keys_onoff=Alter_info::LEAVE_AS_IS, check_cons_spec=0x7f38e6148340, file=0x7f388c0d1028) at /sdc/MS-8.0.20_dbg/sql/dd/dd_table.cc:2377
#13 0x0000000003621fd0 in rea_create_tmp_table (thd=0x7f388c020000, path=0x7f38e61475a4 "/dev/shm/1588217992/tmp/#sqla51_8_1", sch_obj=..., db=0x7f388c0638e8 "test", table_name=0x7f38e61469c0 "#sql-a51_8", create_info=0x7f38e61483d0, create_fields=..., keys=1, key_info=0x7f388c0d26c8, keys_onoff=Alter_info::LEAVE_AS_IS, check_cons_spec=0x7f38e6148340, file=0x7f388c0d1028, no_ha_table=true, binlog_to_trx_cache=0x0, tmp_table_def=0x7f38e6146210) at /sdc/MS-8.0.20_dbg/sql/sql_table.cc:743
#14 0x00000000036360ad in create_table_impl (thd=0x7f388c020000, schema=..., db=0x7f388c0638e8 "test", table_name=0x7f38e61469c0 "#sql-a51_8", error_table_name=0x7f388c062f70 "t1", path=0x7f38e61475a4 "/dev/shm/1588217992/tmp/#sqla51_8_1", create_info=0x7f38e61483d0, alter_info=0x7f38e6148280, internal_tmp_table=true, select_field_count=0, find_parent_keys=true, no_ha_table=true, do_not_store_in_dd=true, is_trans=0x0, key_info=0x7f38e61463f8, key_count=0x7f38e61463f4, keys_onoff=Alter_info::LEAVE_AS_IS, fk_key_info=0x7f38e61463e8, fk_key_count=0x7f38e61463e4, existing_fk_info=0x0, existing_fk_count=0, existing_fk_table=0x0, fk_max_generated_name_number=0, table_def=0x7f38e6146210, post_ddl_ht=0x0) at /sdc/MS-8.0.20_dbg/sql/sql_table.cc:8498
#15 0x000000000364d8c0 in mysql_alter_table (thd=0x7f388c020000, new_db=0x7f388c0638e8 "test", new_name=0x0, create_info=0x7f38e61483d0, table_list=0x7f388c063330, alter_info=0x7f38e6148280) at /sdc/MS-8.0.20_dbg/sql/sql_table.cc:16188
#16 0x0000000003bb1676 in Sql_cmd_alter_table::execute (this=0x7f388c0638f0, thd=0x7f388c020000) at /sdc/MS-8.0.20_dbg/sql/sql_alter.cc:351
#17 0x000000000357f46b in mysql_execute_command (thd=0x7f388c020000, first_level=true) at /sdc/MS-8.0.20_dbg/sql/sql_parse.cc:4489
#18 0x0000000003581e3b in mysql_parse (thd=0x7f388c020000, parser_state=0x7f38e6149ae0) at /sdc/MS-8.0.20_dbg/sql/sql_parse.cc:5306
#19 0x00000000035771cb in dispatch_command (thd=0x7f388c020000, com_data=0x7f38e614ab90, command=COM_QUERY) at /sdc/MS-8.0.20_dbg/sql/sql_parse.cc:1776
#20 0x00000000035756db in do_command (thd=0x7f388c020000) at /sdc/MS-8.0.20_dbg/sql/sql_parse.cc:1274
#21 0x0000000003739c03 in handle_connection (arg=0x7f38d6ff5ca0) at /sdc/MS-8.0.20_dbg/sql/conn_handler/connection_handler_per_thread.cc:302
#22 0x00000000052b711a in pfs_spawn_thread (arg=0x7f38e1c64a60) at /sdc/MS-8.0.20_dbg/storage/perfschema/pfs.cc:2854
#23 0x00007f38e5c74e65 in start_thread (arg=0x7f38e614b700) at pthread_create.c:307
#24 0x00007f38e3b8988d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Release build doesn't crash:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20 MySQL Community Server - GPL

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.01 sec)

mysql> USE test;
Database changed
mysql> CREATE TEMPORARY TABLE t1(j JSON DEFAULT (CAST('["HelloWorld"]' AS JSON)),KEY idxbn ((CAST(j->'$[*]' AS CHAR(1) ARRAY))));
Query OK, 0 rows affected (0.00 sec)

mysql> alter table t1 CONVERT TO CHARACTER SET latin1;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>

How to repeat:
CREATE DATABASE test;
USE test;
CREATE TEMPORARY TABLE t1(j JSON DEFAULT (CAST('["HelloWorld"]' AS JSON)),KEY idxbn ((CAST(j->'$[*]' AS CHAR(1) ARRAY))));
alter table t1 CONVERT TO CHARACTER SET latin1;
[5 May 2020 5:49] MySQL Verification Team
Hello Hrvoje Matijakovic,

Thank you for the bug report and test case.
Verified as described on 8.0.20 debug build.

regards,
Umesh
[5 May 2020 5:55] MySQL Verification Team
-- 8.0.19 debug build not affected with provided test case

 bin/mysql -uroot -S /tmp/mysql_ushastry.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 8.0.19-debug MySQL Community Server - GPL - Debug

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.00 sec)

mysql> USE test;
Database changed
mysql> CREATE TEMPORARY TABLE t1(j JSON DEFAULT (CAST('["HelloWorld"]' AS JSON)),KEY idxbn ((CAST(j->'$[*]' AS CHAR(1) ARRAY))));
Query OK, 0 rows affected (0.01 sec)

mysql> alter table t1 CONVERT TO CHARACTER SET latin1;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
[26 Aug 2020 22:01] Jon Stephens
Documented fix in the MySQL 8.0.23 changelog as follows:

    When ALTER TABLE ... CONVERT TO CHARACTER SET is executed, the
    character set of every CHAR, VARCHAR, and TEXT column is updated
    to the new value. This change was also applied to the hidden
    CHAR column used by an ARRAY column for a multi-valued index;
    since the hidden column must be one of
    my_charset_utf8mb4_0900_bin or binary, this led to an assert in
    debug builds of the server.

    This problem is fixed by no longer setting the character set of
    the hidden column to that of the table when executing the
    statement referenced previously; this is similar to what is done
    for BLOB columns in similar circumstances.

Closed.