[MDEV-27670] Assertion `(cs->state & 0x20000) == 0' failed in my_strnncollsp_nchars_generic_8bit Created: 2022-01-28  Updated: 2022-11-22  Resolved: 2022-11-22

Status: Closed
Project: MariaDB Server
Component/s: Character Sets, Storage Engine - InnoDB
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.11.2, 11.0.0, 10.4.28, 10.5.19, 10.6.12, 10.7.8, 10.9.5, 10.9.6, 10.10.3

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: regression

Issue Links:
Duplicate
is duplicated by MDEV-27768 MDEV-25440: Assertion `(cs->state & 0... Closed
Relates
relates to MDEV-25904 New collation functions to compare In... Closed
relates to MDEV-30034 UNIQUE USING HASH accepts duplicate e... Closed
relates to MDEV-30048 Prefix keys for CHAR work differently... Closed
relates to MDEV-30050 Inconsistent results of DISTINCT with... Closed
relates to MDEV-30072 Wrong ORDER BY for a partitioned pref... Closed

 Description   

--source include/have_innodb.inc
 
CREATE TABLE t1 (id INT PRIMARY KEY, a CHAR(8), KEY(a)) ENGINE=InnoDB COLLATE tis620_thai_nopad_ci;
INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
 
# Cleanup
DROP TABLE t1;

10.4 12cad0c3

mysqld: /data/src/10.4/strings/ctype.c:1239: my_strnncollsp_nchars_generic_8bit: Assertion `(cs->state & 0x20000) == 0' failed.
220128 18:24:01 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f376dae5662 in __GI___assert_fail (assertion=0x55c9241a3d12 "(cs->state & 0x20000) == 0", file=0x55c9241a34e8 "/data/src/10.4/strings/ctype.c", line=1239, function=0x55c9241a3d80 <__PRETTY_FUNCTION__.0> "my_strnncollsp_nchars_generic_8bit") at assert.c:101
#8  0x000055c923c14e1f in my_strnncollsp_nchars_generic_8bit (cs=0x55c9246725c0 <my_charset_tis620_thai_nopad_ci>, str1=0x7f3710170095 "foo     ", '\245' <repeats 19 times>, "\310", len1=8, str2=0x7f376313007e "foo     \200", len2=8, nchars=8) at /data/src/10.4/strings/ctype.c:1239
#9  0x000055c92380ff9a in cmp_whole_field (mtype=13, prtype=68288766, a=0x7f3710170095 "foo     ", '\245' <repeats 19 times>, "\310", a_length=8, b=0x7f376313007e "foo     \200", b_length=8) at /data/src/10.4/storage/innobase/rem/rem0cmp.cc:329
#10 0x000055c923812a4e in cmp_data (mtype=13, prtype=68288766, data1=0x7f3710170095 "foo     ", '\245' <repeats 19 times>, "\310", len1=8, data2=0x7f376313007e "foo     \200", len2=8) at /data/src/10.4/storage/innobase/rem/rem0cmp.cc:401
#11 0x000055c923810816 in cmp_dtuple_rec_with_match_low (dtuple=0x7f37101a60a8, rec=0x7f376313007e "foo     \200", offsets=0x7f37680a9480, n_cmp=2, matched_fields=0x7f37680a8ea8) at /data/src/10.4/storage/innobase/rem/rem0cmp.cc:669
#12 0x000055c923811362 in cmp_dtuple_rec (dtuple=0x7f37101a60a8, rec=0x7f376313007e "foo     \200", offsets=0x7f37680a9480) at /data/src/10.4/storage/innobase/rem/rem0cmp.cc:914
#13 0x000055c9239835dd in page_cur_tuple_insert (cursor=0x7f37680a93e8, tuple=0x7f37101a60a8, index=0x7f3710042670, offsets=0x7f37680a9388, heap=0x7f37680a9360, n_ext=0, mtr=0x7f37680a96e0) at /data/src/10.4/storage/innobase/include/page0cur.ic:289
#14 0x000055c923991bca in btr_cur_optimistic_insert (flags=0, cursor=0x7f37680a93e0, offsets=0x7f37680a9388, heap=0x7f37680a9360, entry=0x7f37101a60a8, rec=0x7f37680a9390, big_rec=0x7f37680a9398, n_ext=0, thr=0x7f3710174bd0, mtr=0x7f37680a96e0) at /data/src/10.4/storage/innobase/btr/btr0cur.cc:3609
#15 0x000055c9238510ce in row_ins_sec_index_entry_low (flags=0, mode=2, index=0x7f3710042670, offsets_heap=0x7f37100565c0, heap=0x7f3710056a50, entry=0x7f37101a60a8, trx_id=0, thr=0x7f3710174bd0) at /data/src/10.4/storage/innobase/row/row0ins.cc:3095
#16 0x000055c9238519b8 in row_ins_sec_index_entry (index=0x7f3710042670, entry=0x7f37101a60a8, thr=0x7f3710174bd0, check_foreign=true) at /data/src/10.4/storage/innobase/row/row0ins.cc:3297
#17 0x000055c923851bd9 in row_ins_index_entry (index=0x7f3710042670, entry=0x7f37101a60a8, thr=0x7f3710174bd0) at /data/src/10.4/storage/innobase/row/row0ins.cc:3345
#18 0x000055c923852483 in row_ins_index_entry_step (node=0x7f3710174988, thr=0x7f3710174bd0) at /data/src/10.4/storage/innobase/row/row0ins.cc:3512
#19 0x000055c92385299a in row_ins (node=0x7f3710174988, thr=0x7f3710174bd0) at /data/src/10.4/storage/innobase/row/row0ins.cc:3671
#20 0x000055c9238532db in row_ins_step (thr=0x7f3710174bd0) at /data/src/10.4/storage/innobase/row/row0ins.cc:3821
#21 0x000055c923878897 in row_insert_for_mysql (mysql_rec=0x7f3710170090 "\375\001", prebuilt=0x7f3710174460, ins_mode=ROW_INS_NORMAL) at /data/src/10.4/storage/innobase/row/row0mysql.cc:1401
#22 0x000055c9236caad6 in ha_innobase::write_row (this=0x7f3710173c68, record=0x7f3710170090 "\375\001") at /data/src/10.4/storage/innobase/handler/ha_innodb.cc:8112
#23 0x000055c923300706 in handler::ha_write_row (this=0x7f3710173c68, buf=0x7f3710170090 "\375\001") at /data/src/10.4/sql/handler.cc:6771
#24 0x000055c922f70276 in write_record (thd=0x7f3710000d90, table=0x7f3710172e00, info=0x7f37680aaad0) at /data/src/10.4/sql/sql_insert.cc:2072
#25 0x000055c922f6d101 in mysql_insert (thd=0x7f3710000d90, table_list=0x7f3710014890, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR, ignore=false) at /data/src/10.4/sql/sql_insert.cc:1078
#26 0x000055c922fbaf75 in mysql_execute_command (thd=0x7f3710000d90) at /data/src/10.4/sql/sql_parse.cc:4598
#27 0x000055c922fc66c0 in mysql_parse (thd=0x7f3710000d90, rawbuf=0x7f3710014798 "INSERT INTO t1 VALUES (1,'foo'),(2,'bar')", length=41, parser_state=0x7f37680ab550, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7995
#28 0x000055c922fb2b39 in dispatch_command (command=COM_QUERY, thd=0x7f3710000d90, packet=0x7f371000abf1 "INSERT INTO t1 VALUES (1,'foo'),(2,'bar')", packet_length=41, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1857
#29 0x000055c922fb13c6 in do_command (thd=0x7f3710000d90) at /data/src/10.4/sql/sql_parse.cc:1373
#30 0x000055c92313f52f in do_handle_one_connection (connect=0x55c926ca4cf0) at /data/src/10.4/sql/sql_connect.cc:1420
#31 0x000055c92313f1d7 in handle_one_connection (arg=0x55c926ca4cf0) at /data/src/10.4/sql/sql_connect.cc:1316
#32 0x000055c92365a989 in pfs_spawn_thread (arg=0x55c926c85260) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#33 0x00007f376dfb1ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#34 0x00007f376dbaedef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

The failure stared happening on 10.4 after this commit:

commit e9aac091537a7aaf18543c6abc228f0cbd0ec58f
Author: Marko Mäkelä
Date:   Wed Jan 26 12:42:17 2022 +0200
 
    MDEV-25440: Indexed CHAR columns are broken with NO_PAD collations

No obvious immediate effect on a non-debug build.



 Comments   
Comment by Elena Stepanova [ 2022-01-28 ]

Not raising to a blocker since the commit doesn't seem to be present in bb-10.4-release.

Comment by Alexander Barkov [ 2022-11-21 ]

A similar crash happens with these scripts:

CREATE OR REPLACE TABLE t1
(
  a VARCHAR(250) COLLATE tis620_thai_nopad_ci,
  UNIQUE KEY(a(100)) USING HASH
) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('a'),('A');

CREATE OR REPLACE TABLE t1
(
  a CHAR(250) COLLATE tis620_thai_nopad_ci,
  UNIQUE KEY(a(100)) USING HASH
) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('a'),('A');

Comment by Alexander Barkov [ 2022-11-22 ]

The fix appeared to be quite simple, but it required a lot of investigation,
which helped to find and report a number of new bugs.

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