[MDEV-21242] Wrong result or failed assertion upon SELECT under READ UNCOMMITTED with index on virtual column Created: 2019-12-06  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Virtual Columns
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Nikita Malyavin
Resolution: Unresolved Votes: 0
Labels: None


 Description   

--source include/have_innodb.inc
 
CREATE TABLE t1 ( 
    a CHAR(3),
    b INT,
    c INT,
    d CHAR(3) AS (a) VIRTUAL,
    KEY(b,d)
) ENGINE=InnoDB;
 
INSERT INTO t1 (a,b,c) VALUES ('foo',0,10),('bar',1,11);
 
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
 
# Cleanup
DROP TABLE t1;

10.3 e5e58777 non-debug

SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
a	b	c	d
foo	0	10	NULL
bar	1	11	NULL

Values in the last (virtual) column are obviously wrong.

10.3 e5e58777 debug

mysqld: /data/src/10.3/sql/field.cc:7247: virtual String* Field_string::val_str(String*, String*): Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength)))' failed.
191206 17:32:07 [ERROR] mysqld got signal 6 ;
 
#7  0x00007ff2c7a1ef12 in __GI___assert_fail (assertion=0x561286600e60 "!table || (!table->read_set || bitmap_is_set(table->read_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength)))", file=0x561286600cb9 "/data/src/10.3/sql/field.cc", line=7247, function=0x561286605020 <Field_string::val_str(String*, String*)::__PRETTY_FUNCTION__> "virtual String* Field_string::val_str(String*, String*)") at assert.c:101
#8  0x0000561285b33636 in Field_string::val_str (this=0x7ff264006b38, val_buffer=0x7ff2c4265c50, val_ptr=0x7ff2c4265c50) at /data/src/10.3/sql/field.cc:7247
#9  0x000056128572ef5b in Field::val_str (this=0x7ff264006b38, str=0x7ff2c4265c50) at /data/src/10.3/sql/field.h:841
#10 0x000056128572ca83 in Protocol_text::store (this=0x7ff2640010a8, field=0x7ff264006b38) at /data/src/10.3/sql/protocol.cc:1257
#11 0x0000561285b891a5 in Item_field::send (this=0x7ff264013a20, protocol=0x7ff2640010a8, buffer=0x7ff2c4266030) at /data/src/10.3/sql/item.cc:7457
#12 0x000056128572b5ad in Protocol::send_result_set_row (this=0x7ff2640010a8, row_items=0x7ff264005270) at /data/src/10.3/sql/protocol.cc:997
#13 0x00005612857d889e in select_send::send_data (this=0x7ff264013480, items=...) at /data/src/10.3/sql/sql_class.cc:2938
#14 0x00005612858bd4fa in end_send (join=0x7ff2640134a8, join_tab=0x7ff264015908, end_of_records=false) at /data/src/10.3/sql/sql_select.cc:20758
#15 0x00005612858babb2 in evaluate_join_record (join=0x7ff2640134a8, join_tab=0x7ff264015578, error=0) at /data/src/10.3/sql/sql_select.cc:19798
#16 0x00005612858ba471 in sub_select (join=0x7ff2640134a8, join_tab=0x7ff264015578, end_of_records=false) at /data/src/10.3/sql/sql_select.cc:19578
#17 0x00005612858b98fb in do_select (join=0x7ff2640134a8, procedure=0x0) at /data/src/10.3/sql/sql_select.cc:19118
#18 0x0000561285890af3 in JOIN::exec_inner (this=0x7ff2640134a8) at /data/src/10.3/sql/sql_select.cc:4092
#19 0x000056128588fec6 in JOIN::exec (this=0x7ff2640134a8) at /data/src/10.3/sql/sql_select.cc:3886
#20 0x00005612858911d7 in mysql_select (thd=0x7ff264000af0, tables=0x7ff264012840, wild_num=1, fields=..., conds=0x7ff2640130f8, og_num=1, order=0x7ff264013368, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7ff264013480, unit=0x7ff2640049c0, select_lex=0x7ff264005148) at /data/src/10.3/sql/sql_select.cc:4291
#21 0x00005612858828dc in handle_select (thd=0x7ff264000af0, lex=0x7ff2640048f8, result=0x7ff264013480, setup_tables_done_option=0) at /data/src/10.3/sql/sql_select.cc:370
#22 0x000056128584a2eb in execute_sqlcom_select (thd=0x7ff264000af0, all_tables=0x7ff264012840) at /data/src/10.3/sql/sql_parse.cc:6294
#23 0x0000561285840ce7 in mysql_execute_command (thd=0x7ff264000af0) at /data/src/10.3/sql/sql_parse.cc:3821
#24 0x000056128584e5e3 in mysql_parse (thd=0x7ff264000af0, rawbuf=0x7ff264012608 "SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c", length=51, parser_state=0x7ff2c4267630, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7818
#25 0x000056128583b12f in dispatch_command (command=COM_QUERY, thd=0x7ff264000af0, packet=0x7ff264008c71 "", packet_length=51, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1856
#26 0x0000561285839a77 in do_command (thd=0x7ff264000af0) at /data/src/10.3/sql/sql_parse.cc:1401
#27 0x00005612859b0fb4 in do_handle_one_connection (connect=0x561289f38490) at /data/src/10.3/sql/sql_connect.cc:1403
#28 0x00005612859b0d16 in handle_one_connection (arg=0x561289f38490) at /data/src/10.3/sql/sql_connect.cc:1308
#29 0x00007ff2c95944a4 in start_thread (arg=0x7ff2c4268700) at pthread_create.c:456
#30 0x00007ff2c7adbd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Reproducible on 10.2-10.3.
With the test case above, I couldn't reproduce it on 10.4, 10.5, but see the second test case below, which only differs from the first one in one value for `b` column (2 instead of 1):

--source include/have_innodb.inc
 
CREATE TABLE t1 ( 
    a CHAR(3),
    b INT,
    c INT,
    d CHAR(3) AS (a) VIRTUAL,
    KEY(b,d)
) ENGINE=InnoDB;
 
INSERT INTO t1 (a,b,c) VALUES ('foo',0,10),('bar',2,11);
 
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
 
# Cleanup
DROP TABLE t1;

10.4 f5b76d8c non-debug

SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
a	b	c	d
foo	0	10	NULL

Reproducible on 10.2-10.5.

10.4 f5b76d8c debug

mysqld: /data/src/10.4/sql/field.cc:7278: virtual String* Field_string::val_str(String*, String*): Assertion `marked_for_read()' failed.
191206 17:44:06 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f7dfe9e9f12 in __GI___assert_fail (assertion=0x561ec9c13bf0 "marked_for_read()", file=0x561ec9c13a2b "/data/src/10.4/sql/field.cc", line=7278, function=0x561ec9c18760 <Field_string::val_str(String*, String*)::__PRETTY_FUNCTION__> "virtual String* Field_string::val_str(String*, String*)") at assert.c:101
#8  0x0000561ec90d5877 in Field_string::val_str (this=0x7f7dac03ffd8, val_buffer=0x7f7df3db1480, val_ptr=0x7f7df3db1480) at /data/src/10.4/sql/field.cc:7278
#9  0x0000561ec8c7923b in Field::val_str (this=0x7f7dac03ffd8, str=0x7f7df3db1480) at /data/src/10.4/sql/field.h:840
#10 0x0000561ec8c769c9 in Protocol_text::store (this=0x7f7dac0010b8, field=0x7f7dac03ffd8) at /data/src/10.4/sql/protocol.cc:1275
#11 0x0000561ec912dc11 in Item_field::send (this=0x7f7dac0152a0, protocol=0x7f7dac0010b8, buffer=0x7f7df3db1860) at /data/src/10.4/sql/item.cc:7110
#12 0x0000561ec8c759bb in Protocol::send_result_set_row (this=0x7f7dac0010b8, row_items=0x7f7dac013370) at /data/src/10.4/sql/protocol.cc:1035
#13 0x0000561ec8d2a83e in select_send::send_data (this=0x7f7dac014cf8, items=...) at /data/src/10.4/sql/sql_class.cc:3002
#14 0x0000561ec8e20fc1 in end_send (join=0x7f7dac014d20, join_tab=0x7f7dac0172e0, end_of_records=false) at /data/src/10.4/sql/sql_select.cc:21424
#15 0x0000561ec8e1e652 in evaluate_join_record (join=0x7f7dac014d20, join_tab=0x7f7dac016f38, error=0) at /data/src/10.4/sql/sql_select.cc:20455
#16 0x0000561ec8e1df38 in sub_select (join=0x7f7dac014d20, join_tab=0x7f7dac016f38, end_of_records=false) at /data/src/10.4/sql/sql_select.cc:20235
#17 0x0000561ec8e1d3c7 in do_select (join=0x7f7dac014d20, procedure=0x0) at /data/src/10.4/sql/sql_select.cc:19773
#18 0x0000561ec8df25b9 in JOIN::exec_inner (this=0x7f7dac014d20) at /data/src/10.4/sql/sql_select.cc:4433
#19 0x0000561ec8df16f6 in JOIN::exec (this=0x7f7dac014d20) at /data/src/10.4/sql/sql_select.cc:4215
#20 0x0000561ec8df2e0b in mysql_select (thd=0x7f7dac000af0, tables=0x7f7dac0137e8, wild_num=1, fields=..., conds=0x7f7dac014108, og_num=1, order=0x7f7dac014ba0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f7dac014cf8, unit=0x7f7dac004a20, select_lex=0x7f7dac013228) at /data/src/10.4/sql/sql_select.cc:4647
#21 0x0000561ec8de2b12 in handle_select (thd=0x7f7dac000af0, lex=0x7f7dac004958, result=0x7f7dac014cf8, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:420
#22 0x0000561ec8da928b in execute_sqlcom_select (thd=0x7f7dac000af0, all_tables=0x7f7dac0137e8) at /data/src/10.4/sql/sql_parse.cc:6360
#23 0x0000561ec8d9e939 in mysql_execute_command (thd=0x7f7dac000af0) at /data/src/10.4/sql/sql_parse.cc:3899
#24 0x0000561ec8dad397 in mysql_parse (thd=0x7f7dac000af0, rawbuf=0x7f7dac013158 "SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c", length=51, parser_state=0x7f7df3db3160, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7901
#25 0x0000561ec8d9853c in dispatch_command (command=COM_QUERY, thd=0x7f7dac000af0, packet=0x7f7dac1363c1 "", packet_length=51, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1842
#26 0x0000561ec8d96bc9 in do_command (thd=0x7f7dac000af0) at /data/src/10.4/sql/sql_parse.cc:1360
#27 0x0000561ec8f1f6b7 in do_handle_one_connection (connect=0x561ecbb30180) at /data/src/10.4/sql/sql_connect.cc:1412
#28 0x0000561ec8f1f406 in handle_one_connection (arg=0x561ecbb30180) at /data/src/10.4/sql/sql_connect.cc:1316
#29 0x0000561ec99216bd in pfs_spawn_thread (arg=0x561ecbaad870) at /data/src/10.4/storage/perfschema/pfs.cc:1862
#30 0x00007f7e0055f4a4 in start_thread (arg=0x7f7df3db4700) at pthread_create.c:456
#31 0x00007f7dfeaa6d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Reproducible on 10.4, 10.5. With 10.2-10.3 it produces the same assertion failure as the first test case.



 Comments   
Comment by Alice Sherepa [ 2022-06-21 ]

the second testcase on 10.10:

bb-10.10-MDEV-28881 812f8cbfb3a7a02705f65d8bb7e3

/sql/field.cc:4456: virtual longlong Field_long::val_int(): Assertion `marked_for_read()' failed.
220621 14:46:07 [ERROR] mysqld got signal 6 ;
 
Server version: 10.10.0-MariaDB-debug-log
 
??:0(__assert_fail)[0x7ff9ef6fffd6]
sql/field.cc:4459(Field_long::val_int())[0x5568aa6bd752]
sql/item.cc:3357(Item_field::val_int())[0x5568aa7ac6e6]
sql/item.h:1440(Item::to_longlong_hybrid())[0x5568aa849de7]
sql/item_cmpfunc.cc:2245(Item_func_between::val_int_cmp_int())[0x5568aa81b34a]
sql/sql_type.cc:5720(Type_handler_int_result::Item_func_between_val_int(Item_func_between*) const)[0x5568aa4e0a3e]
sql/item_cmpfunc.h:986(Item_func_between::val_int())[0x5568a9b3ff21]
sql/opt_range.h:1905(SQL_SELECT::skip_record(THD*))[0x5568a9d6b5ab]
sql/filesort.cc:953(find_all_keys(THD*, Sort_param*, SQL_SELECT*, SORT_INFO*, st_io_cache*, st_io_cache*, Bounded_queue<unsigned char, unsigned char>*, unsigned long long*))[0x5568aa724ce7]
sql/filesort.cc:357(filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long))[0x5568aa7202a1]
sql/sql_select.cc:25007(create_sort_index(THD*, JOIN*, st_join_table*, Filesort*))[0x5568aa004715]
sql/sql_select.cc:22688(st_join_table::sort_table())[0x5568a9ff2a35]
sql/sql_select.cc:22627(join_init_read_record(st_join_table*))[0x5568a9ff201c]
sql/sql_select.cc:21674(sub_select(JOIN*, st_join_table*, bool))[0x5568a9feb50f]
sql/sql_select.cc:21222(do_select(JOIN*, Procedure*))[0x5568a9fe96de]
sql/sql_select.cc:4794(JOIN::exec_inner())[0x5568a9f722fe]
sql/sql_select.cc:4573(JOIN::exec())[0x5568a9f6f7fe]
sql/sql_select.cc:5054(mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x5568a9f73d6d]
sql/sql_select.cc:583(handle_select(THD*, LEX*, select_result*, unsigned long))[0x5568a9f43f9f]
sql/sql_parse.cc:6260(execute_sqlcom_select(THD*, TABLE_LIST*))[0x5568a9e68cff]
sql/sql_parse.cc:3944(mysql_execute_command(THD*, bool))[0x5568a9e57734]
sql/sql_parse.cc:8036(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x5568a9e73fdf]
sql/sql_parse.cc:1896(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x5568a9e49fc4]
sql/sql_parse.cc:1407(do_command(THD*, bool))[0x5568a9e46d45]
sql/sql_connect.cc:1418(do_handle_one_connection(CONNECT*, bool))[0x5568aa2fc39a]
sql/sql_connect.cc:1314(handle_one_connection)[0x5568aa2fbc26]
perfschema/pfs.cc:2203(pfs_spawn_thread)[0x5568aafe14ea]
nptl/pthread_create.c:478(start_thread)[0x7ff9efc1a609]
 
Query (0x6290001092a8): SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c

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