[MDEV-24726] Assertion `0' failed in Field_varstring_compressed::key_cmp Created: 2021-01-28  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Data types, Server
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.4, 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 t1 (a VARCHAR(8) COMPRESSED) CHARACTER SET utf8mb4;
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES ('foo'),('bar'),('foo');
 
SELECT * FROM v1 WHERE a IN (SELECT a FROM t1);
 
# Cleanup
DROP VIEW v1;
DROP TABLE t1;

10.5 700ae20d

mariadbd: /data/src/10.5/sql/field.h:4266: virtual int Field_varstring_compressed::key_cmp(const uchar*, uint) const: Assertion `0' failed.
210128 19:28:08 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f0f8f871f36 in __GI___assert_fail (assertion=0x55c83aa37f07 "0", file=0x55c83aa37da4 "/data/src/10.5/sql/field.h", line=4266, function=0x55c83aa38600 "virtual int Field_varstring_compressed::key_cmp(const uchar*, uint) const") at assert.c:101
#8  0x000055c839df374b in Field_varstring_compressed::key_cmp (this=0x7f0f7805c7e0, str=0x7f0f78060751 "\004", length=33) at /data/src/10.5/sql/field.h:4266
#9  0x000055c839f3b06b in key_cmp_if_same (table=0x7f0f7805baf0, key=0x7f0f78060751 "\004", idx=0, key_length=36) at /data/src/10.5/sql/key.cc:315
#10 0x000055c839e16c34 in handler::index_next_same (this=0x7f0f7805cc50, buf=0x7f0f7805c8d0 "\375\004", key=0x7f0f78060750 "", keylen=36) at /data/src/10.5/sql/handler.cc:5248
#11 0x000055c839e11d7f in handler::ha_index_next_same (this=0x7f0f7805cc50, buf=0x7f0f7805c8d0 "\375\004", key=0x7f0f78060750 "", keylen=36) at /data/src/10.5/sql/handler.cc:3257
#12 0x000055c839b23705 in join_read_next_same (info=0x7f0f7805fce0) at /data/src/10.5/sql/sql_select.cc:21518
#13 0x000055c8399e3969 in READ_RECORD::read_record (this=0x7f0f7805fce0) at /data/src/10.5/sql/records.h:80
#14 0x000055c839b2192a in sub_select (join=0x7f0f78056a30, join_tab=0x7f0f7805fc18, end_of_records=false) at /data/src/10.5/sql/sql_select.cc:20707
#15 0x000055c839b21fb7 in evaluate_join_record (join=0x7f0f78056a30, join_tab=0x7f0f7805f870, error=0) at /data/src/10.5/sql/sql_select.cc:20911
#16 0x000055c839b2186e in sub_select (join=0x7f0f78056a30, join_tab=0x7f0f7805f870, end_of_records=false) at /data/src/10.5/sql/sql_select.cc:20688
#17 0x000055c839b20d04 in do_select (join=0x7f0f78056a30, procedure=0x0) at /data/src/10.5/sql/sql_select.cc:20222
#18 0x000055c839af46a0 in JOIN::exec_inner (this=0x7f0f78056a30) at /data/src/10.5/sql/sql_select.cc:4466
#19 0x000055c839af37c1 in JOIN::exec (this=0x7f0f78056a30) at /data/src/10.5/sql/sql_select.cc:4246
#20 0x000055c839af4ff5 in mysql_select (thd=0x7f0f78000db8, tables=0x7f0f780145d8, fields=..., conds=0x7f0f780162f8, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f0f78019df0, unit=0x7f0f78004f58, select_lex=0x7f0f78013fe8) at /data/src/10.5/sql/sql_select.cc:4719
#21 0x000055c839ae4a73 in handle_select (thd=0x7f0f78000db8, lex=0x7f0f78004e90, result=0x7f0f78019df0, setup_tables_done_option=0) at /data/src/10.5/sql/sql_select.cc:417
#22 0x000055c839aa7449 in execute_sqlcom_select (thd=0x7f0f78000db8, all_tables=0x7f0f780145d8) at /data/src/10.5/sql/sql_parse.cc:6281
#23 0x000055c839a9e4d5 in mysql_execute_command (thd=0x7f0f78000db8) at /data/src/10.5/sql/sql_parse.cc:3977
#24 0x000055c839aac2f0 in mysql_parse (thd=0x7f0f78000db8, rawbuf=0x7f0f78013f30 "SELECT * FROM v1 WHERE a IN (SELECT a FROM t1)", length=46, parser_state=0x7f0f8a22c510, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:8062
#25 0x000055c839a98277 in dispatch_command (command=COM_QUERY, thd=0x7f0f78000db8, packet=0x7f0f780090a9 "", packet_length=46, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:1889
#26 0x000055c839a96a6b in do_command (thd=0x7f0f78000db8) at /data/src/10.5/sql/sql_parse.cc:1370
#27 0x000055c839c448d1 in do_handle_one_connection (connect=0x55c83dd4a848, put_in_cache=true) at /data/src/10.5/sql/sql_connect.cc:1410
#28 0x000055c839c44634 in handle_one_connection (arg=0x55c83ddb7208) at /data/src/10.5/sql/sql_connect.cc:1312
#29 0x000055c83a1a35cb in pfs_spawn_thread (arg=0x55c83dd4a488) at /data/src/10.5/storage/perfschema/pfs.cc:2201
#30 0x00007f0f8fd89609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#31 0x00007f0f8f95d293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Reproducible on 10.5+. Not reproducible on 10.4.
No obvious immediate problem on a non-debug build.
Reproducible with InnoDB and MyISAM. Not reproducible with Aria.

Upd: Test case for 10.3+ and all engines is in comments.



 Comments   
Comment by Elena Stepanova [ 2022-09-20 ]

CREATE TABLE t1 (f1 VARCHAR(8)) CHARSET=eucjpms COLLATE=eucjpms_nopad_bin;
INSERT INTO t1 VALUES ('');
CREATE TABLE t2 (f2 VARCHAR(8) COMPRESSED) CHARSET=eucjpms COLLATE=eucjpms_nopad_bin;
INSERT INTO t2 VALUES ('a'),('b');
SELECT t1.* FROM t1 LEFT JOIN (SELECT DISTINCT f2 FROM t2) sq ON sq.f2 = t1.f1;
 
# Cleanup
DROP TABLE t1, t2;

10.3 65b4a2af

mysqld: /data/src/10.3/sql/field.h:3564: virtual int Field_varstring_compressed::key_cmp(const uchar*, uint): Assertion `0' failed.
220920 19:05:26 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fd824bd1662 in __GI___assert_fail (assertion=0x55bf19eb93c0 "0", file=0x55bf19eb90a0 "/data/src/10.3/sql/field.h", line=3564, function=0x55bf19eba680 "virtual int Field_varstring_compressed::key_cmp(const uchar*, uint)") at assert.c:101
#8  0x000055bf186b25ec in Field_varstring_compressed::key_cmp (this=0x61900008b210, str=0x62900009de41 "", length=25) at /data/src/10.3/sql/field.h:3564
#9  0x000055bf18980dca in key_cmp_if_same (table=0x622000022990, key=0x62900009de41 "", idx=0, key_length=28) at /data/src/10.3/sql/key.cc:313
#10 0x000055bf186fa32e in handler::index_next_same (this=0x61a000025f10, buf=0x61900008b308 "\375\002", key=0x62900009de40 "", keylen=28) at /data/src/10.3/sql/handler.cc:4913
#11 0x000055bf186ee47a in handler::ha_index_next_same (this=0x61a000025f10, buf=0x61900008b308 "\375\002", key=0x62900009de40 "", keylen=28) at /data/src/10.3/sql/handler.cc:3046
#12 0x000055bf180bbdc2 in join_read_next_same (info=0x62900009d420) at /data/src/10.3/sql/sql_select.cc:20765
#13 0x000055bf17dfbcd6 in READ_RECORD::read_record (this=0x62900009d420) at /data/src/10.3/sql/records.h:70
#14 0x000055bf180b63c9 in sub_select (join=0x62b000003360, join_tab=0x62900009d358, end_of_records=false) at /data/src/10.3/sql/sql_select.cc:19951
#15 0x000055bf180b4186 in do_select (join=0x62b000003360, procedure=0x0) at /data/src/10.3/sql/sql_select.cc:19470
#16 0x000055bf18048226 in JOIN::exec_inner (this=0x62b000003360) at /data/src/10.3/sql/sql_select.cc:4171
#17 0x000055bf18045bf7 in JOIN::exec (this=0x62b000003360) at /data/src/10.3/sql/sql_select.cc:3965
#18 0x000055bf18049559 in mysql_select (thd=0x62a000060270, tables=0x62b000000540, wild_num=1, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x62b000003330, unit=0x62a000064120, select_lex=0x62a0000648b8) at /data/src/10.3/sql/sql_select.cc:4374
#19 0x000055bf1801fd8f in handle_select (thd=0x62a000060270, lex=0x62a000064060, result=0x62b000003330, setup_tables_done_option=0) at /data/src/10.3/sql/sql_select.cc:372
#20 0x000055bf17f94c7b in execute_sqlcom_select (thd=0x62a000060270, all_tables=0x62b000000540) at /data/src/10.3/sql/sql_parse.cc:6340
#21 0x000055bf17f82d52 in mysql_execute_command (thd=0x62a000060270) at /data/src/10.3/sql/sql_parse.cc:3871
#22 0x000055bf17f9e5fc in mysql_parse (thd=0x62a000060270, rawbuf=0x62b000000290 "SELECT t1.* FROM t1 LEFT JOIN (SELECT DISTINCT f2 FROM t2) sq ON sq.f2 = t1.f1", length=78, parser_state=0x7fd81a23aa00, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7871
#23 0x000055bf17f75ba2 in dispatch_command (command=COM_QUERY, thd=0x62a000060270, packet=0x6290000eb271 "", packet_length=78, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1852
#24 0x000055bf17f7277e in do_command (thd=0x62a000060270) at /data/src/10.3/sql/sql_parse.cc:1398
#25 0x000055bf18333eb6 in do_handle_one_connection (connect=0x611000006230) at /data/src/10.3/sql/sql_connect.cc:1403
#26 0x000055bf183337b2 in handle_one_connection (arg=0x611000006230) at /data/src/10.3/sql/sql_connect.cc:1308
#27 0x000055bf198de7d1 in pfs_spawn_thread (arg=0x616000009ff0) at /data/src/10.3/storage/perfschema/pfs.cc:1869
#28 0x00007fd824d6aea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#29 0x00007fd824c9adef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Reproducible on 10.3+, MyISAM, InnoDB, Aria.

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