[MDEV-28610] Assertion `marked_for_read()' failed upon range select with virtual column in index Created: 2022-05-18  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Optimizer, Virtual Columns
Affects Version/s: 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0
Fix Version/s: 10.5, 10.6, 10.11

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None


 Description   

CREATE TABLE t (
  a INT UNSIGNED NOT NULL DEFAULT 0,
  b INT AS (a) VIRTUAL,
  c TIME,
  d INT,
  e DATE,
  f VARCHAR(1024),
  PRIMARY KEY(c),
  KEY(c,b,d,f(64))
);
INSERT INTO t (c) VALUES ('00:00:00'),('00:00:04');
SELECT c FROM t WHERE c BETWEEN '00:00:00' AND '00:00:00' ORDER BY d;
 
# Cleanup
DROP TABLE t;

10.5 b03ab127

mariadbd: /data/src/10.5/sql/field.cc:4426: virtual longlong Field_long::val_int(): Assertion `marked_for_read()' failed.
220518 18:52:40 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fe282233662 in __GI___assert_fail (assertion=0x55bf4143e61d "marked_for_read()", file=0x55bf4143e053 "/data/src/10.5/sql/field.cc", line=4426, function=0x55bf4143f5d0 "virtual longlong Field_long::val_int()") at assert.c:101
#8  0x000055bf4082b9e5 in Field_long::val_int (this=0x7fe26c2236f0) at /data/src/10.5/sql/field.cc:4426
#9  0x000055bf4067f765 in Field_num::save_in_field (this=0x7fe26c2236f0, to=0x7fe26c2237c8) at /data/src/10.5/sql/field.h:2065
#10 0x000055bf4067e57e in Field::store_field (this=0x7fe26c2237c8, from=0x7fe26c2236f0) at /data/src/10.5/sql/field.h:918
#11 0x000055bf4084f44f in field_conv_incompatible (to=0x7fe26c2237c8, from=0x7fe26c2236f0) at /data/src/10.5/sql/field_conv.cc:850
#12 0x000055bf4084f4ab in field_conv (to=0x7fe26c2237c8, from=0x7fe26c2236f0) at /data/src/10.5/sql/field_conv.cc:863
#13 0x000055bf40893265 in save_field_in_field (from=0x7fe26c2236f0, null_value=0x7fe26c1020be, to=0x7fe26c2237c8, no_conversions=false) at /data/src/10.5/sql/item.cc:6625
#14 0x000055bf408934a6 in Item_field::save_in_field (this=0x7fe26c102040, to=0x7fe26c2237c8, no_conversions=false) at /data/src/10.5/sql/item.cc:6676
#15 0x000055bf4064cafa in TABLE::update_virtual_fields (this=0x7fe26c202688, h=0x7fe26c100ce0, update_mode=VCOL_UPDATE_FOR_READ) at /data/src/10.5/sql/table.cc:8762
#16 0x000055bf40866906 in handler::ha_rnd_pos (this=0x7fe26c100ce0, buf=0x7fe26c101540 "\376", pos=0x7fe26c190cd8 "") at /data/src/10.5/sql/handler.cc:3137
#17 0x000055bf40a23422 in rr_from_pointers (info=0x7fe26c018fb0) at /data/src/10.5/sql/records.cc:615
#18 0x000055bf4043e59f in READ_RECORD::read_record (this=0x7fe26c018fb0) at /data/src/10.5/sql/records.h:80
#19 0x000055bf4057ca33 in join_init_read_record (tab=0x7fe26c018ee8) at /data/src/10.5/sql/sql_select.cc:21884
#20 0x000055bf4057a4c7 in sub_select (join=0x7fe26c017048, join_tab=0x7fe26c018ee8, end_of_records=false) at /data/src/10.5/sql/sql_select.cc:20917
#21 0x000055bf4057996d in do_select (join=0x7fe26c017048, procedure=0x0) at /data/src/10.5/sql/sql_select.cc:20452
#22 0x000055bf4054cfaf in JOIN::exec_inner (this=0x7fe26c017048) at /data/src/10.5/sql/sql_select.cc:4540
#23 0x000055bf4054c0b1 in JOIN::exec (this=0x7fe26c017048) at /data/src/10.5/sql/sql_select.cc:4320
#24 0x000055bf4054d907 in mysql_select (thd=0x7fe26c000db8, tables=0x7fe26c015a10, fields=..., conds=0x7fe26c0163c8, og_num=1, order=0x7fe26c016eb0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fe26c017020, unit=0x7fe26c004f60, select_lex=0x7fe26c0153f8) at /data/src/10.5/sql/sql_select.cc:4797
#25 0x000055bf4053d2d1 in handle_select (thd=0x7fe26c000db8, lex=0x7fe26c004e98, result=0x7fe26c017020, setup_tables_done_option=0) at /data/src/10.5/sql/sql_select.cc:444
#26 0x000055bf4050012a in execute_sqlcom_select (thd=0x7fe26c000db8, all_tables=0x7fe26c015a10) at /data/src/10.5/sql/sql_parse.cc:6330
#27 0x000055bf404f7461 in mysql_execute_command (thd=0x7fe26c000db8) at /data/src/10.5/sql/sql_parse.cc:4021
#28 0x000055bf40504f0b in mysql_parse (thd=0x7fe26c000db8, rawbuf=0x7fe26c015310 "SELECT c FROM t WHERE c BETWEEN '00:00:00' AND '00:00:00' ORDER BY d", length=68, parser_state=0x7fe27cbf0510, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:8116
#29 0x000055bf404f1034 in dispatch_command (command=COM_QUERY, thd=0x7fe26c000db8, packet=0x7fe26c00b5c9 "", packet_length=68, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:1907
#30 0x000055bf404ef7c0 in do_command (thd=0x7fe26c000db8) at /data/src/10.5/sql/sql_parse.cc:1375
#31 0x000055bf4069ccd3 in do_handle_one_connection (connect=0x55bf43c8d6b8, put_in_cache=true) at /data/src/10.5/sql/sql_connect.cc:1418
#32 0x000055bf4069c995 in handle_one_connection (arg=0x55bf43c6d1c8) at /data/src/10.5/sql/sql_connect.cc:1312
#33 0x000055bf40bace9a in pfs_spawn_thread (arg=0x55bf43c8d438) at /data/src/10.5/storage/perfschema/pfs.cc:2201
#34 0x00007fe2826ffea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#35 0x00007fe2822fcdef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Reproducible at least with InnoDB and MyISAM.
No obvious problem on a non-debug build.

Not reproducible on 10.4, but it could be because the plan there is different.

10.5 (fails)

EXPLAIN EXTENDED
SELECT c FROM t WHERE c BETWEEN '00:00:00' AND '00:00:00' ORDER BY d;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t	range	PRIMARY,c	c	3	NULL	1	100.00	Using where; Using index; Using filesort
Warnings:
Note	1003	select `test`.`t`.`c` AS `c` from `test`.`t` where `test`.`t`.`c` between '00:00:00.000000' and '00:00:00.000000' order by `test`.`t`.`d`

10.4 (does not fail)

EXPLAIN EXTENDED
SELECT c FROM t WHERE c BETWEEN '00:00:00' AND '00:00:00' ORDER BY d;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t	index	PRIMARY,c	c	80	NULL	2	50.00	Using where; Using index; Using filesort
Warnings:
Note	1003	select `test`.`t`.`c` AS `c` from `test`.`t` where `test`.`t`.`c` between '00:00:00.000000' and '00:00:00.000000' order by `test`.`t`.`d`



 Comments   
Comment by Alice Sherepa [ 2023-04-25 ]

also on 11.0

Version: '11.0.2-MariaDB-debug-log'  
mariadbd: /11.0/src/sql/field.cc:7929: virtual String* Field_varstring::val_str(String*, String*): Assertion `marked_for_read()' failed.
230425 14:36:51 [ERROR] mysqld got signal 6 ;
 
Server version: 11.0.2-MariaDB-debug-log source revision: c7fe8e51de4e67f8515b3cf8b6bcd1c5bf1d184b
 
sanitizer_common/sanitizer_common_interceptors.inc:4022(__interceptor_backtrace.part.0)[0x7ff0b4aafd40]
mysys/stacktrace.c:215(my_print_stacktrace)[0x5633da792bb5]
sql/signal_handler.cc:241(handle_fatal_signal)[0x5633d93843e2]
sql/field.cc:7930(Field_varstring::val_str(String*, String*))[0x5633d932df6c]
sql/field.h:1047(Field::val_str(String*))[0x5633d874c13e]
sql/field.h:760(Field::save_in_field_str(Field*))[0x5633d8ef0f4c]
sql/field.h:2129(Field_str::save_in_field(Field*))[0x5633d8ef4467]
sql/field.h:928(Field::store_field(Field*))[0x5633d8ef1561]
sql/field_conv.cc:851(field_conv_incompatible(Field*, Field*))[0x5633d9364a25]
sql/field_conv.cc:864(field_conv(Field*, Field*))[0x5633d9364ac6]
sql/item.cc:6719(save_field_in_field(Field*, bool*, Field*, bool))[0x5633d9416d28]
sql/item.cc:6770(Item_field::save_in_field(Field*, bool))[0x5633d94174ae]
sql/table.cc:9033(TABLE::update_virtual_fields(handler*, enum_vcol_update_mode))[0x5633d8e72f5c]
sql/handler.cc:3605(handler::ha_rnd_next(unsigned char*))[0x5633d93a1f9b]
sql/records.cc:514(rr_sequential(READ_RECORD*))[0x5633d8788a11]
sql/records.h:81(READ_RECORD::read_record())[0x5633d87541ae]
sql/sql_select.cc:24076(join_init_read_record(st_join_table*))[0x5633d8c19f47]
sql/sql_select.cc:23049(sub_select(JOIN*, st_join_table*, bool))[0x5633d8c12b39]
sql/sql_select.cc:22582(do_select(JOIN*, Procedure*))[0x5633d8c10a1e]
sql/sql_select.cc:4900(JOIN::exec_inner())[0x5633d8b915d3]
sql/sql_select.cc:4677(JOIN::exec())[0x5633d8b8e990]
sql/sql_select.cc:5158(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*))[0x5633d8b9308c]
sql/sql_select.cc:616(handle_select(THD*, LEX*, select_result*, unsigned long long))[0x5633d8b62ae5]
sql/sql_parse.cc:6279(execute_sqlcom_select(THD*, TABLE_LIST*))[0x5633d8a82d86]
sql/sql_parse.cc:3949(mysql_execute_command(THD*, bool))[0x5633d8a7143e]
sql/sql_parse.cc:8014(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x5633d8a8dbda]
sql/sql_parse.cc:1896(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x5633d8a63b24]
sql/sql_parse.cc:1407(do_command(THD*, bool))[0x5633d8a60854]
sql/sql_connect.cc:1416(do_handle_one_connection(CONNECT*, bool))[0x5633d8f38b77]
sql/sql_connect.cc:1320(handle_one_connection)[0x5633d8f384d4]
perfschema/pfs.cc:2203(pfs_spawn_thread)[0x5633d9b6ce38]
nptl/pthread_create.c:478(start_thread)[0x7ff0b45c2609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7ff0b4193133]

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