[MDEV-20515] multi-update tries to position updated table by null reference Created: 2019-09-06  Updated: 2020-05-22  Resolved: 2020-04-02

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Update
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.3.23, 10.4.13, 10.5.3

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-13911 Support ORDER BY and LIMIT in multi-t... Closed
relates to MDEV-14551 Can't find record in table on multi-t... Closed
relates to MDEV-22667 Multi-delete on table with unique blo... Confirmed

 Description   

Table corruption or Assertion `bitmap_is_set(&(m_part_info->read_partitions), part_id)' failed upon multi-update on a versioned partitioned table

--source include/have_partition.inc
 
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1);
 
CREATE TABLE t2 (b INT) WITH SYSTEM VERSIONING PARTITION BY system_time INTERVAL 1 WEEK (PARTITION p1 HISTORY, PARTITION pn CURRENT);
INSERT INTO t2 VALUES (0),(2);
 
UPDATE t1 LEFT JOIN t2 ON a > b SET b = 2 ORDER BY b;
 
# Cleanup
DROP TABLE t1, t2;

10.3 2842c369 debug

mysqld: /data/src/10.3/sql/ha_partition.cc:5199: virtual int ha_partition::rnd_pos(uchar*, uchar*): Assertion `bitmap_is_set(&(m_part_info->read_partitions), part_id)' failed.
190906 16:25:25 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fa4abf42f12 in __GI___assert_fail (assertion=0x564bc5871a90 "bitmap_is_set(&(m_part_info->read_partitions), part_id)", file=0x564bc5870688 "/data/src/10.3/sql/ha_partition.cc", line=5199, function=0x564bc5874c00 <ha_partition::rnd_pos(unsigned char*, unsigned char*)::__PRETTY_FUNCTION__> "virtual int ha_partition::rnd_pos(uchar*, uchar*)") at assert.c:101
#8  0x0000564bc54025c2 in ha_partition::rnd_pos (this=0x7fa494182458, buf=0x7fa494184ff8 "\375\002", pos=0x7fa49403c159 "") at /data/src/10.3/sql/ha_partition.cc:5199
#9  0x0000564bc4bac460 in handler::ha_rnd_pos (this=0x7fa494182458, buf=0x7fa494184ff8 "\375\002", pos=0x7fa49403c159 "") at /data/src/10.3/sql/handler.cc:2872
#10 0x0000564bc49926f4 in multi_update::do_updates (this=0x7fa4940144e8) at /data/src/10.3/sql/sql_update.cc:2669
#11 0x0000564bc4992ffa in multi_update::send_eof (this=0x7fa4940144e8) at /data/src/10.3/sql/sql_update.cc:2832
#12 0x0000564bc49004f1 in do_select (join=0x7fa4940145c0, procedure=0x0) at /data/src/10.3/sql/sql_select.cc:19100
#13 0x0000564bc48d716f in JOIN::exec_inner (this=0x7fa4940145c0) at /data/src/10.3/sql/sql_select.cc:4044
#14 0x0000564bc48d6534 in JOIN::exec (this=0x7fa4940145c0) at /data/src/10.3/sql/sql_select.cc:3838
#15 0x0000564bc48d7853 in mysql_select (thd=0x7fa494000b00, tables=0x7fa494012930, wild_num=0, fields=..., conds=0x0, og_num=1, order=0x7fa494014400, group=0x0, having=0x0, proc_param=0x0, select_options=1342177408, result=0x7fa4940144e8, unit=0x7fa4940049d0, select_lex=0x7fa494005150) at /data/src/10.3/sql/sql_select.cc:4243
#16 0x0000564bc498f44e in mysql_multi_update (thd=0x7fa494000b00, table_list=0x7fa494012930, fields=0x7fa494005278, values=0x7fa494005780, conds=0x0, options=0, handle_duplicates=DUP_ERROR, ignore=false, unit=0x7fa4940049d0, select_lex=0x7fa494005150, result=0x7fa4a6140fd0) at /data/src/10.3/sql/sql_update.cc:1789
#17 0x0000564bc4888b91 in mysql_execute_command (thd=0x7fa494000b00) at /data/src/10.3/sql/sql_parse.cc:4366
#18 0x0000564bc48949ff in mysql_parse (thd=0x7fa494000b00, rawbuf=0x7fa494012818 "UPDATE t1 LEFT JOIN t2 ON a > b SET b = 2 ORDER BY b", length=52, parser_state=0x7fa4a61415e0, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7830
#19 0x0000564bc48812fd in dispatch_command (command=COM_QUERY, thd=0x7fa494000b00, packet=0x7fa494008c71 "UPDATE t1 LEFT JOIN t2 ON a > b SET b = 2 ORDER BY b", packet_length=52, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1856
#20 0x0000564bc487fc24 in do_command (thd=0x7fa494000b00) at /data/src/10.3/sql/sql_parse.cc:1401
#21 0x0000564bc49f8b94 in do_handle_one_connection (connect=0x564bc742c130) at /data/src/10.3/sql/sql_connect.cc:1403
#22 0x0000564bc49f88f6 in handle_one_connection (arg=0x564bc742c130) at /data/src/10.3/sql/sql_connect.cc:1308
#23 0x0000564bc53db060 in pfs_spawn_thread (arg=0x564bc74470b0) at /data/src/10.3/storage/perfschema/pfs.cc:1862
#24 0x00007fa4adab74a4 in start_thread (arg=0x7fa4a6142700) at pthread_create.c:456
#25 0x00007fa4abfffd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Reproducible with at least MyISAM, InnoDB, Aria.

Non-debug builds don't crash, but produce corruption-like messages, different for different engine.

MyISAM: ER_KEY_NOT_FOUND

mysqltest: At line 9: query 'UPDATE t1 LEFT JOIN t2 ON a > b SET b = 2 ORDER BY b' failed: 1032: Can't find record in 't2'

InnoDB: ER_NOT_KEYFILE

mysqltest: At line 9: query 'UPDATE t1 LEFT JOIN t2 ON a > b SET b = 2 ORDER BY b' failed: 1034: Index for table 't2' is corrupt; try to repair it

Aria: ER_GET_ERRNO

mysqltest: At line 9: query 'UPDATE t1 LEFT JOIN t2 ON a > b SET b = 2 ORDER BY b' failed: 1030: Got error 176 "Read page with wrong checksum" from storage engine Aria



 Comments   
Comment by Aleksey Midenkov [ 2020-03-23 ]

Cause

Join tmp table inserts null row because of OUTER JOIN, that's expected. Since multi_update::prepare2() converted Item_temptable_rowid into Item_field (MDEV-14551 ) multi_update::send_data() accesses join tmp record directly and treats it as a normal row ignoring null status of ref field. NULL ref field is then treated as normal in multi_update::do_updates() which tries to position updated table by reference 0.

Fix

Don't add row into multi-update tmp table in case of null ref field. Join tmp table does not have null_row status at this time (as well as STATUS_NULL_ROW), but it has all null fields (including ref field).

Anlysis

Comment by Aleksey Midenkov [ 2020-03-24 ]

Reproducible without System Versioning:

create or replace table t1 (a int) engine=myisam;
insert into t1 values (0), (2);
 
create or replace table t2 (b int) engine=myisam;
insert into t2 values (1), (2);
 
select * from t1 left join t2 on a = b order by b;
update t1 left join t2 on a = b set b= 3 order by b;
select * from t2;
 
drop tables t1, t2;

Result

select * from t2;
b
3
3

Expected

select * from t2;
b
1
3

Note: this bug leads to wrong data modified.

Comment by Oleksandr Byelkin [ 2020-04-02 ]

OK, to push

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