[MDEV-31063] Assertion `marked_for_read()' failed in virtual longlong Field_bit::val_int() Created: 2023-04-17  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.4, 10.5, 10.6, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1

Type: Bug Priority: Major
Reporter: Ramesh Sivaraman Assignee: Nikita Malyavin
Resolution: Unresolved Votes: 0
Labels: None


 Description   

SET sql_mode='';
SET use_stat_tables=PREFERABLY;
CREATE TABLE tbl0 (a BIT)  engine=MyISAM;
ALTER TABLE tbl0 ADD b INT ;
INSERT INTO tbl0 VALUES (0,0),(0,0),(0,0);
LOCK TABLES tbl0 READ;
ANALYZE TABLE tbl0;
ANALYZE TABLE tbl0 PERSISTENT FOR COLUMNS () INDEXES ();

Leads to:

11.0.2 8e55d7ea4a2f94ae3f38fdd8785778612d4b1203 (Debug)

mariadbd: /test/11.0_dbg/sql/field.cc:9950: virtual longlong Field_bit::val_int(): Assertion `marked_for_read()' failed.

11.0.2 8e55d7ea4a2f94ae3f38fdd8785778612d4b1203 (Debug)

Core was generated by `/test/MD100423-mariadb-11.0.2-linux-x86_64-dbg/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x14973bb67700 (LWP 2902366))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x000014976c55e859 in __GI_abort () at abort.c:79
#2  0x000014976c55e729 in __assert_fail_base (fmt=0x14976c6f4588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5646c594c550 "marked_for_read()", file=0x5646c594c3cb "/test/11.0_dbg/sql/field.cc", line=9950, function=<optimized out>) at assert.c:92
#3  0x000014976c56ffd6 in __GI___assert_fail (assertion=assertion@entry=0x5646c594c550 "marked_for_read()", file=file@entry=0x5646c594c3cb "/test/11.0_dbg/sql/field.cc", line=line@entry=9950, function=function@entry=0x5646c594e0e0 "virtual longlong Field_bit::val_int()") at assert.c:101
#4  0x00005646c4ebe133 in Field_bit::val_int (this=0x149710024180) at /test/11.0_dbg/sql/field.cc:9950
#5  0x00005646c4d52294 in Field_bit::update_min (this=<optimized out>, min_val=0x149710094900, force_update=<optimized out>) at /test/11.0_dbg/sql/field.h:4983
#6  0x00005646c4cc3b8a in Column_statistics_collected::add (this=0x149710024390) at /test/11.0_dbg/sql/sql_statistics.h:534
#7  collect_statistics_for_table (thd=thd@entry=0x149710000d48, table=0x1497100218e8) at /test/11.0_dbg/sql/sql_statistics.cc:2786
#8  0x00005646c4d77ca4 in mysql_admin_table (thd=thd@entry=0x149710000d48, tables=tables@entry=0x149710013260, check_opt=check_opt@entry=0x1497100062a0, operator_name=operator_name@entry=0x5646c5f37190 <msg_analyze>, lock_type=lock_type@entry=TL_READ_NO_INSERT, org_open_for_modify=org_open_for_modify@entry=true, repair_table_use_frm=false, extra_open_options=0, prepare_func=0x0, operator_func=(int (handler::*)(class handler * const, class THD *, HA_CHECK_OPT *)) 0x5646c4ef4858 <handler::ha_analyze(THD*, st_ha_check_opt*)>, view_operator_func=0x0, is_cmd_replicated=true) at /test/11.0_dbg/sql/sql_admin.cc:986
#9  0x00005646c4d797cc in Sql_cmd_analyze_table::execute (this=<optimized out>, thd=0x149710000d48) at /test/11.0_dbg/sql/sql_admin.cc:1483
#10 0x00005646c4c0a79a in mysql_execute_command (thd=thd@entry=0x149710000d48, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/11.0_dbg/sql/sql_parse.cc:6003
#11 0x00005646c4bf316d in mysql_parse (thd=thd@entry=0x149710000d48, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14973bb66300) at /test/11.0_dbg/sql/sql_parse.cc:7999
#12 0x00005646c4c0079f in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x149710000d48, packet=packet@entry=0x14971000ae29 "", packet_length=packet_length@entry=55, blocking=blocking@entry=true) at /test/11.0_dbg/sql/sql_class.h:1370
#13 0x00005646c4c02bd8 in do_command (thd=0x149710000d48, blocking=blocking@entry=true) at /test/11.0_dbg/sql/sql_parse.cc:1407
#14 0x00005646c4d668b9 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5646c79abff8, put_in_cache=put_in_cache@entry=true) at /test/11.0_dbg/sql/sql_connect.cc:1416
#15 0x00005646c4d66d88 in handle_one_connection (arg=0x5646c79abff8) at /test/11.0_dbg/sql/sql_connect.cc:1318
#16 0x000014976ca6f609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#17 0x000014976c65b133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.4.29 (dbg), 10.5.20 (dbg), 10.6.13 (dbg), 10.8.8 (dbg), 10.9.6 (dbg), 10.10.4 (dbg), 10.11.3 (dbg), 11.0.2 (dbg), 11.1.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.4.29 (opt), 10.5.20 (opt), 10.6.13 (opt), 10.8.8 (opt), 10.9.6 (opt), 10.10.4 (opt), 10.11.3 (opt), 11.0.2 (opt), 11.1.0 (opt)



 Comments   
Comment by Ramesh Sivaraman [ 2023-06-15 ]

Found slightly different stack when we execute the test case below
Unique ID

marked_for_read()|SIGABRT|Field_short::val_str|Field::val_str|Histogram_json_builder::append_column_value|Histogram_json_builder::start_bucket

SET SQL_MODE='';
CREATE TABLE t (a SMALLINT) engine='MyISAM';
INSERT INTO t VALUES (0xAEC8);
LOCK TABLE t READ;
ANALYZE TABLE t persistent FOR ALL;
ANALYZE TABLE t PERSISTENT FOR COLUMNS (b) INDEXes (idx2);

Leads to

11.0.2 5ba3bafb834dbc56e6105809ded9a7ccef70ee54 (Debug)

mariadbd: /test/11.0_dbg/sql/field.cc:4134: virtual String* Field_short::val_str(String*, String*): Assertion `marked_for_read()' failed.

11.0.2 5ba3bafb834dbc56e6105809ded9a7ccef70ee54 (Debug)

Core was generated by `/test/MD060623-mariadb-11.0.2-linux-x86_64-dbg/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x14f647966700 (LWP 1224600))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x000014f67ff2c859 in __GI_abort () at abort.c:79
#2  0x000014f67ff2c729 in __assert_fail_base (fmt=0x14f6800c2588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55a1e1d84ab0 "marked_for_read()", file=0x55a1e1d8492b "/test/11.0_dbg/sql/field.cc", line=4134, function=<optimized out>) at assert.c:92
#3  0x000014f67ff3dfd6 in __GI___assert_fail (assertion=assertion@entry=0x55a1e1d84ab0 "marked_for_read()", file=file@entry=0x55a1e1d8492b "/test/11.0_dbg/sql/field.cc", line=line@entry=4134, function=function@entry=0x55a1e1d87190 "virtual String* Field_short::val_str(String*, String*)") at assert.c:101
#4  0x000055a1e12ef6d5 in Field_short::val_str (this=0x14f624021d28, val_buffer=0x14f647963c70, val_ptr=<optimized out>) at /test/11.0_dbg/sql/field.cc:4134
#5  0x000055a1e11e05ee in Field::val_str (str=0x14f647963c70, this=<optimized out>) at /test/11.0_dbg/sql/field.h:1047
#6  Histogram_json_builder::append_column_value (this=this@entry=0x14f6240668a0, elem=elem@entry=0x14f62419b228, is_start=is_start@entry=true) at /test/11.0_dbg/sql/opt_histogram_json.cc:242
#7  0x000055a1e11e09fd in Histogram_json_builder::start_bucket (cnt=1, elem=0x14f62419b228, this=0x14f6240668a0) at /test/11.0_dbg/sql/opt_histogram_json.cc:225
#8  Histogram_json_builder::next (this=0x14f6240668a0, elem=0x14f62419b228, elem_cnt=1) at /test/11.0_dbg/sql/opt_histogram_json.cc:317
#9  0x000055a1e10ebfed in histogram_build_walk (elem=<optimized out>, elem_cnt=<optimized out>, arg=<optimized out>) at /test/11.0_dbg/sql/sql_statistics.cc:1674
#10 0x000055a1e1a34de0 in tree_walk_left_root_right (tree=tree@entry=0x14f624013ea8, element=0x14f62419b210, action=action@entry=0x55a1e10ebfd5 <histogram_build_walk(void*, element_count, void*)>, argument=argument@entry=0x14f6240668a0) at /test/11.0_dbg/mysys/tree.c:588
#11 0x000055a1e1a35e4c in tree_walk (tree=tree@entry=0x14f624013ea8, action=action@entry=0x55a1e10ebfd5 <histogram_build_walk(void*, element_count, void*)>, argument=argument@entry=0x14f6240668a0, visit=visit@entry=left_root_right) at /test/11.0_dbg/mysys/tree.c:576
#12 0x000055a1e116a907 in Unique::walk (this=0x14f624013cf0, table=<optimized out>, action=action@entry=0x55a1e10ebfd5 <histogram_build_walk(void*, element_count, void*)>, walk_action_arg=walk_action_arg@entry=0x14f6240668a0) at /test/11.0_dbg/sql/uniques.cc:657
#13 0x000055a1e10edbc8 in Count_distinct_field::walk_tree_with_histogram (rows=<optimized out>, this=0x14f624013cc0) at /test/11.0_dbg/sql/sql_statistics.cc:1782
#14 Column_statistics_collected::finish (sample_fraction=1, rows=1, mem_root=0x14f624021bb0, this=0x14f624021e58) at /test/11.0_dbg/sql/sql_statistics.cc:2508
#15 collect_statistics_for_table (thd=thd@entry=0x14f624000d48, table=0x14f6240218f8) at /test/11.0_dbg/sql/sql_statistics.cc:2819
#16 0x000055a1e11a2b20 in mysql_admin_table (thd=thd@entry=0x14f624000d48, tables=tables@entry=0x14f624013278, check_opt=check_opt@entry=0x14f6240062a8, operator_name=operator_name@entry=0x55a1e250b110 <msg_analyze>, lock_type=lock_type@entry=TL_READ_NO_INSERT, org_open_for_modify=org_open_for_modify@entry=true, repair_table_use_frm=false, extra_open_options=0, prepare_func=0x0, operator_func=(int (handler::*)(class handler * const, class THD *, HA_CHECK_OPT *)) 0x55a1e1321e7a <handler::ha_analyze(THD*, st_ha_check_opt*)>, view_operator_func=0x0, is_cmd_replicated=true) at /test/11.0_dbg/sql/sql_admin.cc:986
#17 0x000055a1e11a46a8 in Sql_cmd_analyze_table::execute (this=<optimized out>, thd=0x14f624000d48) at /test/11.0_dbg/sql/sql_admin.cc:1483
#18 0x000055a1e10323af in mysql_execute_command (thd=thd@entry=0x14f624000d48, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/11.0_dbg/sql/sql_parse.cc:6015
#19 0x000055a1e101aab7 in mysql_parse (thd=thd@entry=0x14f624000d48, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14f647965300) at /test/11.0_dbg/sql/sql_parse.cc:8014
#20 0x000055a1e1028387 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14f624000d48, packet=packet@entry=0x14f62400ae39 "", packet_length=packet_length@entry=57, blocking=blocking@entry=true) at /test/11.0_dbg/sql/sql_class.h:1370
#21 0x000055a1e102a7df in do_command (thd=0x14f624000d48, blocking=blocking@entry=true) at /test/11.0_dbg/sql/sql_parse.cc:1407
#22 0x000055a1e1191435 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55a1e3eefcd8, put_in_cache=put_in_cache@entry=true) at /test/11.0_dbg/sql/sql_connect.cc:1416
#23 0x000055a1e1191904 in handle_one_connection (arg=0x55a1e3eefcd8) at /test/11.0_dbg/sql/sql_connect.cc:1318
#24 0x000014f68043d609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#25 0x000014f680029133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

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