[MDEV-16240]  Assertion `0' failed in row_sel_convert_mysql_key_to_innobase Created: 2018-05-22  Updated: 2020-02-21  Resolved: 2019-04-25

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Update, Views
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.2.24, 10.3.15, 10.4.5

Type: Bug Priority: Critical
Reporter: Alice Sherepa Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: affects-tests

Issue Links:
Relates
relates to MDEV-11167 InnoDB: Warning: using a partial-fiel... Closed
relates to MDEV-21245 Assertion `0' failed in row_sel_conve... Closed
relates to MDEV-21798 Assertion `0' failed in row_sel_conve... Closed
relates to MDEV-18793 Assertion `0' failed in row_sel_conve... Closed
relates to MDEV-19677 Assertion `0' failed in row_sel_conv... Closed

 Description   

--source include/have_innodb.inc
 
set sql_mode='';
 
CREATE TABLE `DD` ( 
	`col_varchar_nokey` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(), 
    `col_varchar_key` datetime DEFAULT '2000-01-01 00:00:00' ON UPDATE current_timestamp(), 
    `col_int_nokey` TIMESTAMP NULL DEFAULT '2000-01-01 00:00:00', 
    `pk` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 
    `col_int_key` datetime DEFAULT current_timestamp(), 
                   PRIMARY KEY (`pk`), 
                   UNIQUE KEY `col_varchar_key` (`col_varchar_key`),
                   KEY `col_int_key` (`col_int_key`)
    ) ENGINE=InnoDB;
 
INSERT INTO `DD` VALUES ('2018-05-18 15:08:07','2018-05-18 17:08:07','0000-00-00 00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00'),('0000-00-00 00:00:00','0000-00-00 00:00:00','1999-12-31 23:00:00','2002-07-03 23:04:40','0000-00-00 00:00:00');
 
CREATE VIEW `view_DD` AS 
SELECT `DD`.`pk` AS `pk`,
       `DD`.`col_int_nokey` AS `col_int_nokey`,
       `DD`.`col_int_key` AS `col_int_key`,
       `DD`.`col_varchar_key` AS `col_varchar_key`,
       `DD`.`col_varchar_nokey` AS `col_varchar_nokey`
FROM `DD`;
 
CREATE TABLE `C` (
  `col_varchar_nokey` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `col_int_nokey` timestamp NULL DEFAULT NULL,
  `col_varchar_key` timestamp NULL DEFAULT '1999-12-31 23:00:00' ON UPDATE current_timestamp(),
  `pk` int(11) NOT NULL,
  `col_int_key` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`pk`)
) ENGINE=InnoDB;
 
INSERT INTO `C` VALUES ('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,1,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,3,'2018-05-18 15:08:06'),('0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,1976,'0000-00-00 00:00:00'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2000,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2001,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2002,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2003,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00',NULL,2004,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2005,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2018,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2019,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','2018-05-18 15:08:06',2024,'2018-05-18 15:08:06'),('2018-05-18 17:08:06','0000-00-00 00:00:00','1999-12-31 23:00:00',2025,'2018-05-18 15:08:06'),('0000-00-00 00:00:00',NULL,'2018-05-18 15:08:06',2026,'2018-05-18 15:08:06'),('2018-05-18 17:08:07','0000-00-00 00:00:00','0000-00-00 00:00:00',2027,'0000-00-00 00:00:00');
 
UPDATE `view_DD` t1, `C` t2
SET t1.`col_varchar_key` = 6452736 WHERE t1.`col_int_key` = 6272000;

 10.2  afe5a51c2df9
Thread 1 (Thread 0x7f142058c700 (LWP 27097)):
#0  __pthread_kill (threadid=<optimized out>, signo=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:62
#1  0x000055b9f3f8d68d in my_write_core (sig=6) at /home/alice/git/10.2/mysys/stacktrace.c:477
#2  0x000055b9f382716b in handle_fatal_signal (sig=6) at /home/alice/git/10.2/sql/signal_handler.cc:305
#3  <signal handler called>
#4  0x00007f142d948428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#5  0x00007f142d94a02a in __GI_abort () at abort.c:89
#6  0x00007f142d940bd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x55b9f41fdc3b "0", file=file@entry=0x55b9f41fd8b0 "/home/alice/git/10.2/storage/innobase/row/row0sel.cc", line=line@entry=2725, function=function@entry=0x55b9f42016e0 <row_sel_convert_mysql_key_to_innobase(dtuple_t*, unsigned char*, unsigned long, dict_index_t*, unsigned char const*, unsigned long, trx_t*)::__PRETTY_FUNCTION__> "void row_sel_convert_mysql_key_to_innobase(dtuple_t*, byte*, ulint, dict_index_t*, const byte*, ulint, trx_t*)") at assert.c:92
#7  0x00007f142d940c82 in __GI___assert_fail (assertion=0x55b9f41fdc3b "0", file=0x55b9f41fd8b0 "/home/alice/git/10.2/storage/innobase/row/row0sel.cc", line=2725, function=0x55b9f42016e0 <row_sel_convert_mysql_key_to_innobase(dtuple_t*, unsigned char*, unsigned long, dict_index_t*, unsigned char const*, unsigned long, trx_t*)::__PRETTY_FUNCTION__> "void row_sel_convert_mysql_key_to_innobase(dtuple_t*, byte*, ulint, dict_index_t*, const byte*, ulint, trx_t*)") at assert.c:101
#8  0x000055b9f3cd9d9b in row_sel_convert_mysql_key_to_innobase (tuple=0x7f13d411ce88, buf=0x0, buf_len=0, index=0x7f13d4133a58, key_ptr=0x7f13d4130876 "\245\245\245\245\245\245\245\245\245\245", '\217' <repeats 190 times>..., key_len=5, trx=0x7f14280b0400) at /home/alice/git/10.2/storage/innobase/row/row0sel.cc:2725
#9  0x000055b9f3b6f136 in ha_innobase::index_read (this=0x7f13d411a9b8, buf=0x7f13d4006638 "\361Z\376\320\067\231\237\345\022\a", key_ptr=0x7f13d4130870 "\200", key_len=5, find_flag=HA_READ_KEY_EXACT) at /home/alice/git/10.2/storage/innobase/handler/ha_innodb.cc:9449
#10 0x000055b9f3b70817 in ha_innobase::rnd_pos (this=0x7f13d411a9b8, buf=0x7f13d4006638 "\361Z\376\320\067\231\237\345\022\a", pos=0x7f13d4130870 "\200") at /home/alice/git/10.2/storage/innobase/handler/ha_innodb.cc:10029
#11 0x000055b9f382dcbb in handler::ha_rnd_pos (this=0x7f13d411a9b8, buf=0x7f13d4006638 "\361Z\376\320\067\231\237\345\022\a", pos=0x7f13d4130870 "\200") at /home/alice/git/10.2/sql/handler.cc:2605
#12 0x000055b9f369f9b1 in prepare_record_for_error_message (error=121, table=0x7f13d41490c0) at /home/alice/git/10.2/sql/sql_update.cc:215
#13 0x000055b9f36a5917 in multi_update::send_data (this=0x7f13d4017470, not_used_values=...) at /home/alice/git/10.2/sql/sql_update.cc:2165
#14 0x000055b9f36281f0 in end_send (join=0x7f13d4017538, join_tab=0x7f13d4040ea8, end_of_records=false) at /home/alice/git/10.2/sql/sql_select.cc:19878
#15 0x000055b9f3625cca in evaluate_join_record (join=0x7f13d4017538, join_tab=0x7f13d4040af8, error=0) at /home/alice/git/10.2/sql/sql_select.cc:18930
#16 0x000055b9f36255bb in sub_select (join=0x7f13d4017538, join_tab=0x7f13d4040af8, end_of_records=false) at /home/alice/git/10.2/sql/sql_select.cc:18710
#17 0x000055b9f3625cca in evaluate_join_record (join=0x7f13d4017538, join_tab=0x7f13d4040748, error=0) at /home/alice/git/10.2/sql/sql_select.cc:18930
#18 0x000055b9f36255bb in sub_select (join=0x7f13d4017538, join_tab=0x7f13d4040748, end_of_records=false) at /home/alice/git/10.2/sql/sql_select.cc:18710
#19 0x000055b9f3624b56 in do_select (join=0x7f13d4017538, procedure=0x0) at /home/alice/git/10.2/sql/sql_select.cc:18254
#20 0x000055b9f35ff6e7 in JOIN::exec_inner (this=0x7f13d4017538) at /home/alice/git/10.2/sql/sql_select.cc:3585
#21 0x000055b9f35feb96 in JOIN::exec (this=0x7f13d4017538) at /home/alice/git/10.2/sql/sql_select.cc:3380
#22 0x000055b9f35ffd58 in mysql_select (thd=0x7f13d4000b00, tables=0x7f13d40125d8, wild_num=0, fields=..., conds=0x7f13d4013640, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=1342177408, result=0x7f13d4017470, unit=0x7f13d40046a0, select_lex=0x7f13d4004dd8) at /home/alice/git/10.2/sql/sql_select.cc:3780
#23 0x000055b9f36a392d in mysql_multi_update (thd=0x7f13d4000b00, table_list=0x7f13d40125d8, fields=0x7f13d4004f00, values=0x7f13d40053d0, conds=0x7f13d4013640, options=0, handle_duplicates=DUP_ERROR, ignore=false, unit=0x7f13d40046a0, select_lex=0x7f13d4004dd8, result=0x7f142058a910) at /home/alice/git/10.2/sql/sql_update.cc:1604
#24 0x000055b9f35b80f0 in mysql_execute_command (thd=0x7f13d4000b00) at /home/alice/git/10.2/sql/sql_parse.cc:4347
#25 0x000055b9f35c38c9 in mysql_parse (thd=0x7f13d4000b00, rawbuf=0x7f13d4012448 "UPDATE `view_DD` t1, `C` t2\nSET t1.`col_varchar_key` = 6452736 WHERE t1.`col_int_key` = 6272000", length=95, parser_state=0x7f142058b200, is_com_multi=false, is_next_command=false) at /home/alice/git/10.2/sql/sql_parse.cc:7941
#26 0x000055b9f35b12a0 in dispatch_command (command=COM_QUERY, thd=0x7f13d4000b00, packet=0x7f13d40088a1 "UPDATE `view_DD` t1, `C` t2\nSET t1.`col_varchar_key` = 6452736 WHERE t1.`col_int_key` = 6272000", packet_length=95, is_com_multi=false, is_next_command=false) at /home/alice/git/10.2/sql/sql_parse.cc:1820
#27 0x000055b9f35afbfc in do_command (thd=0x7f13d4000b00) at /home/alice/git/10.2/sql/sql_parse.cc:1374
#28 0x000055b9f36febb9 in do_handle_one_connection (connect=0x55b9f69307b0) at /home/alice/git/10.2/sql/sql_connect.cc:1335
#29 0x000055b9f36fe939 in handle_one_connection (arg=0x55b9f69307b0) at /home/alice/git/10.2/sql/sql_connect.cc:1241
#30 0x000055b9f3f2adbe in pfs_spawn_thread (arg=0x55b9f6913980) at /home/alice/git/10.2/storage/perfschema/pfs.cc:1862
#31 0x00007f142e5856ba in start_thread (arg=0x7f142058c700) at pthread_create.c:333
#32 0x00007f142da1a41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

 [Warning] InnoDB: Using a partial-field key prefix in search, index `col_int_key` of table `test`.`DD`. Last data field length 6 bytes, key ptr now exceeds key end by 1 bytes. Key value in the MySQL format:
 len 5; hex 8000000000; asc      ;
mysqld: /home/alice/git/10.2/storage/innobase/row/row0sel.cc:2725: void row_sel_convert_mysql_key_to_innobase(dtuple_t*, byte*, ulint, dict_index_t*, const byte*, ulint, trx_t*): Assertion `0' failed.
 
Server version: 10.2.16-MariaDB-debug-log
Thread pointer: 0x7f13d4000b00
stack_bottom = 0x7f142058be70 thread_stack 0x49000
mysys/stacktrace.c:267(my_print_stacktrace)[0x55b9f3f8d59b]
sql/signal_handler.cc:168(handle_fatal_signal)[0x55b9f3826d43]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f142e58f390]
linux/raise.c:54(__GI_raise)[0x7f142d948428]
stdlib/abort.c:91(__GI_abort)[0x7f142d94a02a]
assert/assert.c:92(__assert_fail_base)[0x7f142d940bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f142d940c82]
row/row0sel.cc:2728(row_sel_convert_mysql_key_to_innobase(dtuple_t*, unsigned char*, unsigned long, dict_index_t*, unsigned char const*, unsigned long, trx_t*))[0x55b9f3cd9d9b]
handler/ha_innodb.cc:9449(ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function))[0x55b9f3b6f136]
handler/ha_innodb.cc:10029(ha_innobase::rnd_pos(unsigned char*, unsigned char*))[0x55b9f3b70817]
sql/handler.cc:2605(handler::ha_rnd_pos(unsigned char*, unsigned char*))[0x55b9f382dcbb]
sql/sql_update.cc:217(prepare_record_for_error_message(int, TABLE*))[0x55b9f369f9b1]
sql/sql_update.cc:2166(multi_update::send_data(List<Item>&))[0x55b9f36a5917]
sql/sql_select.cc:19878(end_send(JOIN*, st_join_table*, bool))[0x55b9f36281f0]
sql/sql_select.cc:18930(evaluate_join_record(JOIN*, st_join_table*, int))[0x55b9f3625cca]
sql/sql_select.cc:18710(sub_select(JOIN*, st_join_table*, bool))[0x55b9f36255bb]
sql/sql_select.cc:18930(evaluate_join_record(JOIN*, st_join_table*, int))[0x55b9f3625cca]
sql/sql_select.cc:18710(sub_select(JOIN*, st_join_table*, bool))[0x55b9f36255bb]
sql/sql_select.cc:18254(do_select(JOIN*, Procedure*))[0x55b9f3624b56]
sql/sql_select.cc:3585(JOIN::exec_inner())[0x55b9f35ff6e7]
sql/sql_select.cc:3381(JOIN::exec())[0x55b9f35feb96]
sql/sql_select.cc:3782(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x55b9f35ffd58]
sql/sql_update.cc:1604(mysql_multi_update(THD*, TABLE_LIST*, List<Item>*, List<Item>*, Item*, unsigned long long, enum_duplicates, bool, st_select_lex_unit*, st_select_lex*, multi_update**))[0x55b9f36a392d]
sql/sql_parse.cc:4347(mysql_execute_command(THD*))[0x55b9f35b80f0]
sql/sql_parse.cc:7941(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55b9f35c38c9]
sql/sql_parse.cc:1822(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55b9f35b12a0]
sql/sql_parse.cc:1374(do_command(THD*))[0x55b9f35afbfc]
sql/sql_connect.cc:1335(do_handle_one_connection(CONNECT*))[0x55b9f36febb9]
sql/sql_connect.cc:1242(handle_one_connection)[0x55b9f36fe939]
perfschema/pfs.cc:1864(pfs_spawn_thread)[0x55b9f3f2adbe]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f142e5856ba]
x86_64/clone.S:111(clone)[0x7f142da1a41d]
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x7f13d4012448): UPDATE `view_DD` t1, `C` t2 SET t1.`col_varchar_key` = 6452736 WHERE t1.`col_int_key` = 6272000
Connection ID (thread ID): 9
Status: NOT_KILLED



 Comments   
Comment by Marko Mäkelä [ 2018-05-23 ]

I debugged this a little bit.

The column DD.col_int_key can be NULL. The crash occurs on the second call to row_sel_convert_mysql_key_to_innobase(). Both calls involve converting DD.col_int_key to InnoDB format. The first call passes key_len=6 bytes 0x008000000000; I believe that the first byte are the NULL flags. But, the second call only passes key_len=5 bytes, omitting the first byte.

The column length inside InnoDB is 5 bytes. The problem is the missing first byte. The InnoDB error message about prefix index is misleading.

gdb 10.2 a4e7800701d0764fe4cbb85b81d7c7cb54677334

Thread 28 "mysqld" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffe335c700 (LWP 26095)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: Tiedostoa tai hakemistoa ei ole.
(gdb) up 4
#4  0x00005555571daadd in row_sel_convert_mysql_key_to_innobase (
    tuple=0x621000081138, buf=0x0, buf_len=0, index=0x618000031508, 
    key_ptr=0x6190000a574e "\245\245\245\245\245\245\245\245\245\245", '\217' <repeats 190 times>..., key_len=5, trx=0x7ffff1dadbe0)
    at /mariadb/10.2/storage/innobase/row/row0sel.cc:2725
(gdb) p/x *key_ptr@key_len
$1 = {0x80, 0x0, 0x0, 0x0, 0x0}
(gdb) p index->name
$5 = {m_name = 0x61c000053908 "col_int_key"}
(gdb) p *field
$6 = {col = 0x61b00004fb38, name = {m_name = 0x61b00004fbf3 "col_int_key"}, 
  prefix_len = 0, fixed_len = 5}
(gdb) p index->table->name
$12 = {m_name = 0x6020011962b0 "test/DD"}

Comment by Marko Mäkelä [ 2018-05-23 ]

If I change the crashing statement to access the table DD directly, instead of using view_DD, there will be only one call to row_sel_convert_mysql_key_to_innobase(), and the server will not crash but instead report an error:

10.2 a4e7800701d0764fe4cbb85b81d7c7cb54677334

mysqltest: At line 37: query 'UPDATE DD t1, `C` t2
SET t1.`col_varchar_key` = 6452736 WHERE t1.`col_int_key` = 6272000' failed: 1062: Duplicate entry '0000-00-00 00:00:00' for key 'col_varchar_key'

So, the issue seems to be that updating a view is doing unnecessary work.

Comment by Oleksandr Byelkin [ 2018-12-13 ]

revision-id: 7c782988845dec9f0f26a539911f66ed8cecdf83 (mariadb-10.2.19-51-g7c782988845)
parent(s): ad3346dddf419aed3e5d16066471fd5022af1795
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2018-12-13 15:29:52 +0100
message:

MDEV-16240: Assertion `0' failed in row_sel_convert_mysql_key_to_innobase

Set table in row ID position mode before using this function.

Comment by Oleksandr Byelkin [ 2019-03-14 ]

revision-id: 21a15ea673c9cda1635ce06391b9f56d7a461186 (mariadb-10.2.22-72-g21a15ea673c)
parent(s): bb8c82c66abddf796e8d44f817518e5ab38ae6e4
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-03-14 15:12:47 +0100
message:

MDEV-16240: Assertion `0' failed in row_sel_convert_mysql_key_to_innobase

Set table in row ID position mode before using this function.

Comment by Oleksandr Byelkin [ 2019-04-24 ]

revision-id: 3615a604f60d19390c5dd22712c77386bc7743dc (mariadb-10.2.23-75-g3615a604f60)
parent(s): 1f1a61cfc41a01ffa65d568eebdc037a54b5c463
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-04-24 16:17:00 +0200
message:

MDEV-16240: Assertion `0' failed in row_sel_convert_mysql_key_to_innobase

Set table in row ID position mode before using this function.

Comment by Oleksandr Byelkin [ 2019-04-25 ]

revision-id: 4e01bc8c963d9513625dd984cd1aca24b8a7b516 (mariadb-10.2.23-79-g4e01bc8c963)
parent(s): 3dffdee667666df9ade9f2c458bf1ea495ffba02
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2019-04-25 18:02:31 +0200
message:

MDEV-16240: Assertion `0' failed in row_sel_convert_mysql_key_to_innobase

Set table in row ID position mode before using this function.

Generated at Thu Feb 08 08:27:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.