[MDEV-32094] Assertion `used_tables_cache == 0' failed in Item_func::fix_fields on INSERT Created: 2023-09-05  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Character Sets, Virtual Columns
Affects Version/s: 10.6, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3
Fix Version/s: 10.6, 10.11, 11.0, 11.1, 11.2

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: not-10.4, not-10.5, regression-10.6

Issue Links:
Relates
relates to MDEV-30730 Assertion `marked_for_read()' failed ... Closed

 Description   

Does not look related to MDEV-25650, and different from MDEV-30730 as no Galera is involved here, and the assert is different.

SET SESSION lc_time_names=zh_hk;
CREATE TABLE t (c CHAR,cc TEXT AS (CONCAT (c,IF(c=c,DATE_FORMAT(c,''),'')))) ENGINE=InnoDB;
SET NAMES utf8;
INSERT INTO t VALUES (0,0);
INSERT INTO t VALUES (0,0);
INSERT INTO t VALUES (0,0);

Leads to:

11.3.0 7ba9c7fb84b5f28e4736656b57d9508b70ca6369 (Debug)

...
11.3.0-dbg>INSERT INTO t VALUES (0,0);
ERROR 1906 (HY000): The value specified for generated column 'cc' in table 't' has been ignored
11.3.0-dbg>INSERT INTO t VALUES (0,0);
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE) for operation 'concat'
11.3.0-dbg>INSERT INTO t VALUES (0,0);
ERROR 2013 (HY000): Lost connection to server during query

11.3.0 7ba9c7fb84b5f28e4736656b57d9508b70ca6369 (Debug)

mariadbd: /test/git-bisect/11.3_dbg/sql/item_func.cc:326: virtual bool Item_func::fix_fields(THD*, Item**): Assertion `used_tables_cache == 0' failed.

11.3.0 7ba9c7fb84b5f28e4736656b57d9508b70ca6369 (Debug)

Core was generated by `/test/MD020923-mariadb-11.3.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22937018324544)
    at ./nptl/pthread_kill.c:44
[Current thread is 1 (Thread 0x14dc70d45640 (LWP 3134337))]
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22937018324544) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=22937018324544) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=22937018324544, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x000014dc8ea42476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x000014dc8ea287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000014dc8ea2871b in __assert_fail_base (fmt=0x14dc8ebdd150 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5633f4ef434a "used_tables_cache == 0", file=0x5633f4ef4748 "/test/git-bisect/11.3_dbg/sql/item_func.cc", line=326, function=<optimized out>) at ./assert/assert.c:92
#6  0x000014dc8ea39e96 in __GI___assert_fail (assertion=0x5633f4ef434a "used_tables_cache == 0", file=0x5633f4ef4748 "/test/git-bisect/11.3_dbg/sql/item_func.cc", line=326, function=0x5633f4ef5040 "virtual bool Item_func::fix_fields(THD*, Item**)") at ./assert/assert.c:101
#7  0x00005633f457d83b in Item_func::fix_fields (this=this@entry=0x14dc200285d8, thd=thd@entry=0x14dc20000d58, ref=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item_func.cc:326
#8  0x00005633f45c3330 in Item_str_func::fix_fields (this=0x14dc200285d8, thd=0x14dc20000d58, ref=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item_strfunc.cc:128
#9  0x00005633f43218ff in Virtual_column_info::fix_expr (this=this@entry=0x14dc200286a8, thd=thd@entry=0x14dc20000d58) at /test/git-bisect/11.3_dbg/sql/table.cc:3725
#10 0x00005633f4321a68 in Virtual_column_info::fix_session_expr (this=0x14dc200286a8, thd=thd@entry=0x14dc20000d58) at /test/git-bisect/11.3_dbg/sql/table.cc:3751
#11 0x00005633f4321da2 in TABLE::vcol_fix_expr (this=<optimized out>, thd=thd@entry=0x14dc20000d58) at /test/git-bisect/11.3_dbg/sql/table.cc:3835
#12 0x00005633f418dd6f in open_table (thd=thd@entry=0x14dc20000d58, table_list=table_list@entry=0x14dc20013380, ot_ctx=ot_ctx@entry=0x14dc70d43710) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:2353
#13 0x00005633f419200d in open_and_process_table (ot_ctx=0x14dc70d43710, has_prelocking_list=false, prelocking_strategy=0x14dc70d43900, flags=0, counter=0x14dc70d437ac, tables=0x14dc20013380, thd=0x14dc20000d58) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:4148
#14 open_tables (thd=thd@entry=0x14dc20000d58, options=@0x14dc200065e8: {m_options = DDL_options_st::OPT_NONE}, start=start@entry=0x14dc70d43798, counter=counter@entry=0x14dc70d437ac, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x14dc70d43900) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:4633
#15 0x00005633f4192e78 in open_and_lock_tables (thd=thd@entry=0x14dc20000d58, options=<optimized out>, tables=<optimized out>, tables@entry=0x14dc20013380, derived=derived@entry=true, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x14dc70d43900) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:5607
#16 0x00005633f41d0a4a in open_and_lock_tables (flags=0, derived=true, tables=0x14dc20013380, thd=0x14dc20000d58) at /test/git-bisect/11.3_dbg/sql/sql_base.h:525
#17 mysql_insert (thd=thd@entry=0x14dc20000d58, table_list=0x14dc20013380, fields=@0x14dc20005fa0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x5633f5755be0 <end_of_list>, last = 0x14dc20005fa0, elements = 0}, <No data fields>}, values_list=@0x14dc20005fe8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14dc20014098, last = 0x14dc20014098, elements = 1}, <No data fields>}, update_fields=@0x14dc20005fd0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x5633f5755be0 <end_of_list>, last = 0x14dc20005fd0, elements = 0}, <No data fields>}, update_values=@0x14dc20005fb8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x5633f5755be0 <end_of_list>, last = 0x14dc20005fb8, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false, result=0x0) at /test/git-bisect/11.3_dbg/sql/sql_insert.cc:767
#18 0x00005633f420cc37 in mysql_execute_command (thd=thd@entry=0x14dc20000d58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/git-bisect/11.3_dbg/sql/sql_parse.cc:4427
#19 0x00005633f42123a8 in mysql_parse (thd=thd@entry=0x14dc20000d58, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14dc70d44200) at /test/git-bisect/11.3_dbg/sql/sql_parse.cc:7760
#20 0x00005633f421453c in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14dc20000d58, packet=packet@entry=0x14dc2000af69 "INSERT INTO t VALUES (0,0)", packet_length=packet_length@entry=26, blocking=blocking@entry=true) at /test/git-bisect/11.3_dbg/sql/sql_class.h:247
#21 0x00005633f4216417 in do_command (thd=0x14dc20000d58, blocking=blocking@entry=true) at /test/git-bisect/11.3_dbg/sql/sql_parse.cc:1406
#22 0x00005633f436d2ae in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5633f6d011d8, put_in_cache=put_in_cache@entry=true) at /test/git-bisect/11.3_dbg/sql/sql_connect.cc:1445
#23 0x00005633f436d50d in handle_one_connection (arg=0x5633f6d011d8) at /test/git-bisect/11.3_dbg/sql/sql_connect.cc:1347
#24 0x000014dc8ea94b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#25 0x000014dc8eb26a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Bug confirmed present in:
MariaDB: 10.6.15 (dbg), 10.9.8 (dbg), 10.10.6 (dbg), 10.11.5 (dbg), 11.0.3 (dbg), 11.1.2 (dbg), 11.2.0 (dbg), 11.3.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.4.31 (dbg), 10.4.31 (opt), 10.5.22 (dbg), 10.5.22 (opt), 10.6.15 (opt), 10.9.8 (opt), 10.10.6 (opt), 10.11.5 (opt), 11.0.3 (opt), 11.1.2 (opt), 11.2.0 (opt), 11.3.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.40 (dbg), 8.0.33 (dbg), 8.0.33 (opt)



 Comments   
Comment by Roel Van de Paar [ 2023-09-05 ]

MTR Testcase

--source include/have_innodb.inc
SET SESSION lc_time_names=zh_hk;
CREATE TABLE t (c CHAR,cc TEXT AS (CONCAT (c,IF(c=c,DATE_FORMAT(c,''),'')))) ENGINE=InnoDB;
SET NAMES utf8;
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
INSERT INTO t VALUES (0,0);
--error ER_CANT_AGGREGATE_2COLLATIONS
INSERT INTO t VALUES (0,0);
INSERT INTO t VALUES (0,0);
 
DROP TABLE t;

Comment by Roel Van de Paar [ 2023-09-05 ]

There seem to be two issues: the crash, and the ERROR not being the same for the first and second INSERT.

Comment by Roel Van de Paar [ 2023-09-09 ]

Another testcase with a significantly different stack

SET NAMES gbk;
CREATE TABLE t (id INT,js CHAR,t TIME AS (CAST(JSON_VALUE (JSON_EXTRACT(js,CONCAT ('',DAYNAME (curDATE()))),'') AS TIME)) VIRTUAL);
UPDATE t SET name='U +0B HIRAGANA LETTER HO';
INSERT INTO t VALUES (0,0);
INSERT INTO t SELECT 0 t;

Leads to:

11.3.0 7ba9c7fb84b5f28e4736656b57d9508b70ca6369 (Debug)

mariadbd: /test/git-bisect/11.3_dbg/sql/item_func.cc:326: virtual bool Item_func::fix_fields(THD*, Item**): Assertion `used_tables_cache == 0' failed.

11.3.0 7ba9c7fb84b5f28e4736656b57d9508b70ca6369 (Debug)

Core was generated by `/test/MD020923-mariadb-11.3.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22906269873728)
    at ./nptl/pthread_kill.c:44
[Current thread is 1 (Thread 0x14d548143640 (LWP 2698714))]
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=22906269873728) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=22906269873728) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=22906269873728, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x000014d565442476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x000014d5654287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000014d56542871b in __assert_fail_base (fmt=0x14d5655dd150 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5590f4a6034a "used_tables_cache == 0", file=0x5590f4a60748 "/test/git-bisect/11.3_dbg/sql/item_func.cc", line=326, function=<optimized out>) at ./assert/assert.c:92
#6  0x000014d565439e96 in __GI___assert_fail (assertion=0x5590f4a6034a "used_tables_cache == 0", file=0x5590f4a60748 "/test/git-bisect/11.3_dbg/sql/item_func.cc", line=326, function=0x5590f4a61040 "virtual bool Item_func::fix_fields(THD*, Item**)") at ./assert/assert.c:101
#7  0x00005590f40e983b in Item_func::fix_fields (this=this@entry=0x14d4fc028518, thd=thd@entry=0x14d4fc000d58, ref=ref@entry=0x14d4fc028b90) at /test/git-bisect/11.3_dbg/sql/item_func.cc:326
#8  0x00005590f412f330 in Item_str_func::fix_fields (this=this@entry=0x14d4fc028518, thd=thd@entry=0x14d4fc000d58, ref=ref@entry=0x14d4fc028b90) at /test/git-bisect/11.3_dbg/sql/item_strfunc.cc:128
#9  0x00005590f3f40c43 in Item_json_str_multipath::fix_fields (this=0x14d4fc028518, thd=0x14d4fc000d58, ref=0x14d4fc028b90) at /test/git-bisect/11.3_dbg/sql/item_jsonfunc.cc:947
#10 0x00005590f40e98fa in Item::fix_fields_if_needed (ref=0x14d4fc028b90, thd=0x14d4fc000d58, this=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item.h:1147
#11 Item_func::fix_fields (this=this@entry=0x14d4fc028b10, thd=thd@entry=0x14d4fc000d58, ref=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item_func.cc:349
#12 0x00005590f412f330 in Item_str_func::fix_fields (this=0x14d4fc028b10, thd=0x14d4fc000d58, ref=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item_strfunc.cc:128
#13 0x00005590f40e98fa in Item::fix_fields_if_needed (ref=0x14d4fc0287d0, thd=0x14d4fc000d58, this=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item.h:1147
#14 Item_func::fix_fields (this=0x14d4fc028750, thd=0x14d4fc000d58, ref=<optimized out>) at /test/git-bisect/11.3_dbg/sql/item_func.cc:349
#15 0x00005590f3e8d8ff in Virtual_column_info::fix_expr (this=this@entry=0x14d4fc028800, thd=thd@entry=0x14d4fc000d58) at /test/git-bisect/11.3_dbg/sql/table.cc:3725
#16 0x00005590f3e8da68 in Virtual_column_info::fix_session_expr (this=0x14d4fc028800, thd=thd@entry=0x14d4fc000d58) at /test/git-bisect/11.3_dbg/sql/table.cc:3751
#17 0x00005590f3e8dda2 in TABLE::vcol_fix_expr (this=<optimized out>, thd=thd@entry=0x14d4fc000d58) at /test/git-bisect/11.3_dbg/sql/table.cc:3835
#18 0x00005590f3cf9d6f in open_table (thd=thd@entry=0x14d4fc000d58, table_list=table_list@entry=0x14d4fc013378, ot_ctx=ot_ctx@entry=0x14d548141ae0) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:2353
#19 0x00005590f3cfe00d in open_and_process_table (ot_ctx=0x14d548141ae0, has_prelocking_list=false, prelocking_strategy=0x14d548141c20, flags=0, counter=0x14d548141b7c, tables=0x14d4fc013378, thd=0x14d4fc000d58) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:4148
#20 open_tables (thd=thd@entry=0x14d4fc000d58, options=@0x14d4fc0065e8: {m_options = DDL_options_st::OPT_NONE}, start=start@entry=0x14d548141b68, counter=counter@entry=0x14d548141b7c, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x14d548141c20) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:4633
#21 0x00005590f3cfee78 in open_and_lock_tables (thd=thd@entry=0x14d4fc000d58, options=<optimized out>, tables=<optimized out>, derived=derived@entry=true, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x14d548141c20) at /test/git-bisect/11.3_dbg/sql/sql_base.cc:5607
#22 0x00005590f3d7917c in open_and_lock_tables (flags=0, derived=true, tables=<optimized out>, thd=0x14d4fc000d58) at /test/git-bisect/11.3_dbg/sql/sql_base.h:525
#23 mysql_execute_command (thd=thd@entry=0x14d4fc000d58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/git-bisect/11.3_dbg/sql/sql_parse.cc:4514
#24 0x00005590f3d7e3a8 in mysql_parse (thd=thd@entry=0x14d4fc000d58, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14d548142200) at /test/git-bisect/11.3_dbg/sql/sql_parse.cc:7760
#25 0x00005590f3d8053c in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14d4fc000d58, packet=packet@entry=0x14d4fc00af69 "INSERT INTO t SELECT 0 t", packet_length=packet_length@entry=24, blocking=blocking@entry=true) at /test/git-bisect/11.3_dbg/sql/sql_class.h:247
#26 0x00005590f3d82417 in do_command (thd=0x14d4fc000d58, blocking=blocking@entry=true) at /test/git-bisect/11.3_dbg/sql/sql_parse.cc:1406
#27 0x00005590f3ed92ae in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5590f6b91d18, put_in_cache=put_in_cache@entry=true) at /test/git-bisect/11.3_dbg/sql/sql_connect.cc:1445
#28 0x00005590f3ed950d in handle_one_connection (arg=0x5590f6b91d18) at /test/git-bisect/11.3_dbg/sql/sql_connect.cc:1347
#29 0x000014d565494b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#30 0x000014d565526a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Bug confirmed present in:
MariaDB: 10.6.15 (dbg), 10.9.8 (dbg), 10.10.6 (dbg), 10.11.5 (dbg), 11.0.3 (dbg), 11.1.2 (dbg), 11.2.0 (dbg), 11.3.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.4.31 (dbg), 10.4.31 (opt), 10.5.22 (dbg), 10.5.22 (opt), 10.6.15 (opt), 10.9.8 (opt), 10.10.6 (opt), 10.11.5 (opt), 11.0.3 (opt), 11.1.2 (opt), 11.2.0 (opt), 11.3.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.40 (dbg), 8.0.33 (dbg), 8.0.33 (opt)

Generated at Thu Feb 08 10:28:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.