[MDEV-19406] Assertion on updating view of join with versioned table Created: 2019-05-07  Updated: 2020-05-13  Resolved: 2019-10-09

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types, Versioned Tables
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.3.19, 10.4.9

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


 Description   

Assertion `marked_for_write_or_computed()' failed in Field_date_common::store_TIME_with_warning and variations

Test case 1, with NO_ZERO_IN_DATE

--source include/have_innodb.inc
 
CREATE TABLE t1 ( 
    pk INT,
    a DATE,
    b INT,
    PRIMARY KEY(pk),
    INDEX(b)
) ENGINE=InnoDB WITH SYSTEM VERSIONING;
INSERT INTO t1 (pk) VALUES (1),(2);
 
CREATE TABLE t2 (c INT);
INSERT IGNORE INTO t2 VALUES (3),(4);
 
CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
 
UPDATE t1 SET a = '2012-12-12' ORDER BY b LIMIT 1;
 
SET SQL_MODE= 'NO_ZERO_IN_DATE';
UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1;
 
# Cleanup
DROP VIEW v;
DROP TABLE t1, t2;

10.4 d18ef804, with NO_ZERO_IN_DATE

mysqld: /data/src/10.4/sql/field.cc:6368: int Field_date_common::store_TIME_with_warning(const Datetime*, const ErrConv*, int): Assertion `marked_for_write_or_computed()' failed.
190507 13:40:45 [ERROR] mysqld got signal 6 ;
 
#6  0x00007f815e0b0e67 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x55fbeb508eb8 "marked_for_write_or_computed()", file=file@entry=0x55fbeb508c24 "/data/src/10.4/sql/field.cc", line=line@entry=6368, function=function@entry=0x55fbeb50cd20 <Field_date_common::store_TIME_with_warning(Datetime const*, ErrConv const*, int)::__PRETTY_FUNCTION__> "int Field_date_common::store_TIME_with_warning(const Datetime*, const ErrConv*, int)") at assert.c:92
#7  0x00007f815e0b0f12 in __GI___assert_fail (assertion=0x55fbeb508eb8 "marked_for_write_or_computed()", file=0x55fbeb508c24 "/data/src/10.4/sql/field.cc", line=6368, function=0x55fbeb50cd20 <Field_date_common::store_TIME_with_warning(Datetime const*, ErrConv const*, int)::__PRETTY_FUNCTION__> "int Field_date_common::store_TIME_with_warning(const Datetime*, const ErrConv*, int)") at assert.c:101
#8  0x000055fbeaaa03b6 in Field_date_common::store_TIME_with_warning (this=0x7f80fc154580, dt=0x7f8158080d00, str=0x7f8158080d30, was_cut=0) at /data/src/10.4/sql/field.cc:6368
#9  0x000055fbeaaa0895 in Field_date_common::store_time_dec (this=0x7f80fc154580, ltime=0x7f8158080f80, dec=0) at /data/src/10.4/sql/field.cc:6414
#10 0x000055fbeaaba386 in Field::do_field_temporal (copy=0x7f80fc1bdeb0, fuzzydate=...) at /data/src/10.4/sql/field_conv.cc:435
#11 0x000055fbeaaba3fb in Field::do_field_date (copy=0x7f80fc1bdeb0) at /data/src/10.4/sql/field_conv.cc:447
#12 0x000055fbeaab995f in do_copy_null (copy=0x7f80fc1bdeb0) at /data/src/10.4/sql/field_conv.cc:246
#13 0x000055fbea89bc5b in multi_update::do_updates (this=0x7f80fc1bcd68) at /data/src/10.4/sql/sql_update.cc:2781
#14 0x000055fbea89c4a4 in multi_update::send_eof (this=0x7f80fc1bcd68) at /data/src/10.4/sql/sql_update.cc:2922
#15 0x000055fbea80a4fa in do_select (join=0x7f80fc1bce40, procedure=0x0) at /data/src/10.4/sql/sql_select.cc:19637
#16 0x000055fbea7e13ef in JOIN::exec_inner (this=0x7f80fc1bce40) at /data/src/10.4/sql/sql_select.cc:4389
#17 0x000055fbea7e059c in JOIN::exec (this=0x7f80fc1bce40) at /data/src/10.4/sql/sql_select.cc:4171
#18 0x000055fbea7e1c41 in mysql_select (thd=0x7f80fc000b00, tables=0x7f80fc015748, wild_num=0, fields=..., conds=0x0, og_num=1, order=0x7f80fc016140, group=0x0, having=0x0, proc_param=0x0, select_options=1342177408, result=0x7f80fc1bcd68, unit=0x7f80fc004a28, select_lex=0x7f80fc005200) at /data/src/10.4/sql/sql_select.cc:4603
#19 0x000055fbea8989e6 in mysql_multi_update (thd=0x7f80fc000b00, table_list=0x7f80fc015748, fields=0x7f80fc005348, values=0x7f80fc0058d0, conds=0x0, options=0, handle_duplicates=DUP_ERROR, ignore=true, unit=0x7f80fc004a28, select_lex=0x7f80fc005200, result=0x7f8158081910) at /data/src/10.4/sql/sql_update.cc:1886
#20 0x000055fbea7936d3 in mysql_execute_command (thd=0x7f80fc000b00) at /data/src/10.4/sql/sql_parse.cc:4702
#21 0x000055fbea79f97f in mysql_parse (thd=0x7f80fc000b00, rawbuf=0x7f80fc0155d8 "UPDATE IGNORE `v7` SET `col_date` = '' ORDER BY `col_int` LIMIT 1 /* QNO 1647 CON_ID 16 */", length=90, parser_state=0x7f8158082180, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:8149
#22 0x000055fbea78b05a in dispatch_command (command=COM_QUERY, thd=0x7f80fc000b00, packet=0x7f80fc13a2a1 "UPDATE IGNORE `v7` SET `col_date` = '' ORDER BY `col_int` LIMIT 1 /* QNO 1647 CON_ID 16 */", packet_length=90, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1828
#23 0x000055fbea78981a in do_command (thd=0x7f80fc000b00) at /data/src/10.4/sql/sql_parse.cc:1361
#24 0x000055fbea901089 in do_handle_one_connection (connect=0x55fbecf1bcd0) at /data/src/10.4/sql/sql_connect.cc:1398
#25 0x000055fbea900ded in handle_one_connection (arg=0x55fbecf1bcd0) at /data/src/10.4/sql/sql_connect.cc:1301
#26 0x000055fbeb22db5b in pfs_spawn_thread (arg=0x55fbedbb36b0) at /data/src/10.4/storage/perfschema/pfs.cc:1862
#27 0x00007f815fc254a4 in start_thread (arg=0x7f8158083700) at pthread_create.c:456
#28 0x00007f815e16dd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

10.3 e8dd18a4, with NO_ZERO_IN_DATE

mysqld: /data/src/10.3/sql/field.cc:5627: int Field_temporal_with_date::store_TIME_with_warning(MYSQL_TIME*, const ErrConv*, int, int): Assertion `is_stat_field || !table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength))) || (table->vcol_set && bitmap_is_set(table->vcol_set, field_index))' failed.
190507 17:47:15 [ERROR] mysqld got signal 6 ;
 
#6  0x00007f4b05da0e67 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x563389157fa8 "is_stat_field || !table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength))) || (table->vcol_set && bi"..., file=file@entry=0x563389157c70 "/data/src/10.3/sql/field.cc", line=line@entry=5627, function=function@entry=0x56338915b020 <Field_temporal_with_date::store_TIME_with_warning(st_mysql_time*, ErrConv const*, int, int)::__PRETTY_FUNCTION__> "int Field_temporal_with_date::store_TIME_with_warning(MYSQL_TIME*, const ErrConv*, int, int)") at assert.c:92
#7  0x00007f4b05da0f12 in __GI___assert_fail (assertion=0x563389157fa8 "is_stat_field || !table || (!table->write_set || bitmap_is_set(table->write_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength))) || (table->vcol_set && bi"..., file=0x563389157c70 "/data/src/10.3/sql/field.cc", line=5627, function=0x56338915b020 <Field_temporal_with_date::store_TIME_with_warning(st_mysql_time*, ErrConv const*, int, int)::__PRETTY_FUNCTION__> "int Field_temporal_with_date::store_TIME_with_warning(MYSQL_TIME*, const ErrConv*, int, int)") at assert.c:101
#8  0x000056338875b09c in Field_temporal_with_date::store_TIME_with_warning (this=0x7f4ab4033360, ltime=0x7f4afb1064d0, str=0x7f4afb106500, was_cut=0, have_smth_to_conv=1) at /data/src/10.3/sql/field.cc:5627
#9  0x000056338875b6b5 in Field_temporal_with_date::store_time_dec (this=0x7f4ab4033360, ltime=0x7f4afb106750, dec=0) at /data/src/10.3/sql/field.cc:5719
#10 0x000056338877b9a9 in Field::do_field_temporal (copy=0x7f4ab403c3a0) at /data/src/10.3/sql/field_conv.cc:435
#11 0x000056338877af76 in do_copy_null (copy=0x7f4ab403c3a0) at /data/src/10.3/sql/field_conv.cc:246
#12 0x000056338858e6f0 in multi_update::do_updates (this=0x7f4ab4018660) at /data/src/10.3/sql/sql_update.cc:2677
#13 0x000056338858ef02 in multi_update::send_eof (this=0x7f4ab4018660) at /data/src/10.3/sql/sql_update.cc:2818
#14 0x00005633885020ea in do_select (join=0x7f4ab403b508, procedure=0x0) at /data/src/10.3/sql/sql_select.cc:18992
#15 0x00005633884daf37 in JOIN::exec_inner (this=0x7f4ab403b508) at /data/src/10.3/sql/sql_select.cc:4041
#16 0x00005633884da37a in JOIN::exec (this=0x7f4ab403b508) at /data/src/10.3/sql/sql_select.cc:3835
#17 0x00005633884db61b in mysql_select (thd=0x7f4ab4000b00, tables=0x7f4ab4012918, wild_num=0, fields=..., conds=0x0, og_num=1, order=0x7f4ab4013280, group=0x0, having=0x0, proc_param=0x0, select_options=1342177408, result=0x7f4ab4018660, unit=0x7f4ab40049c8, select_lex=0x7f4ab4005138) at /data/src/10.3/sql/sql_select.cc:4240
#18 0x000056338858b448 in mysql_multi_update (thd=0x7f4ab4000b00, table_list=0x7f4ab4012918, fields=0x7f4ab4005260, values=0x7f4ab4005768, conds=0x0, options=0, handle_duplicates=DUP_ERROR, ignore=false, unit=0x7f4ab40049c8, select_lex=0x7f4ab4005138, result=0x7f4afb106fd0) at /data/src/10.3/sql/sql_update.cc:1769
#19 0x0000563388490de0 in mysql_execute_command (thd=0x7f4ab4000b00) at /data/src/10.3/sql/sql_parse.cc:4643
#20 0x000056338849c14e in mysql_parse (thd=0x7f4ab4000b00, rawbuf=0x7f4ab4012808 "UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1", length=48, parser_state=0x7f4afb1075f0, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:8091
#21 0x000056338848919e in dispatch_command (command=COM_QUERY, thd=0x7f4ab4000b00, packet=0x7f4ab415fe81 "UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1", packet_length=48, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1858
#22 0x0000563388487bc3 in do_command (thd=0x7f4ab4000b00) at /data/src/10.3/sql/sql_parse.cc:1403
#23 0x00005633885ef965 in do_handle_one_connection (connect=0x56338b88cf50) at /data/src/10.3/sql/sql_connect.cc:1402
#24 0x00005633885ef6dc in handle_one_connection (arg=0x56338b88cf50) at /data/src/10.3/sql/sql_connect.cc:1308
#25 0x0000563388ec42c2 in pfs_spawn_thread (arg=0x56338b7d06f0) at /data/src/10.3/storage/perfschema/pfs.cc:1862
#26 0x00007f4b079154a4 in start_thread (arg=0x7f4afb108700) at pthread_create.c:456
#27 0x00007f4b05e5dd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Test case 2, without NO_ZERO_IN_DATE

--source include/have_innodb.inc
 
CREATE TABLE t1 ( 
    pk INT,
    a DATE,
    b INT,
    PRIMARY KEY(pk),
    INDEX(b)
) ENGINE=InnoDB WITH SYSTEM VERSIONING;
INSERT INTO t1 (pk) VALUES (1),(2);
 
CREATE TABLE t2 (c INT);
INSERT IGNORE INTO t2 VALUES (3),(4);
 
CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
 
UPDATE t1 SET a = '2012-12-12' ORDER BY b LIMIT 1;
 
UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1;
 
# Cleanup
DROP VIEW v;
DROP TABLE t1, t2;

10.3 e8dd18a4, without NO_ZERO_IN_DATE

mysqld: /data/src/10.3/sql/handler.cc:6300: int handler::ha_reset(): Assertion `bitmap_is_set_all(&table->s->all_set)' failed.
190507 17:49:48 [ERROR] mysqld got signal 6 ;
 
#6  0x00007f122d281e67 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x5598d0960090 "bitmap_is_set_all(&table->s->all_set)", file=file@entry=0x5598d095e3a8 "/data/src/10.3/sql/handler.cc", line=line@entry=6300, function=function@entry=0x5598d0961e50 <handler::ha_reset()::__PRETTY_FUNCTION__> "int handler::ha_reset()") at assert.c:92
#7  0x00007f122d281f12 in __GI___assert_fail (assertion=0x5598d0960090 "bitmap_is_set_all(&table->s->all_set)", file=0x5598d095e3a8 "/data/src/10.3/sql/handler.cc", line=6300, function=0x5598d0961e50 <handler::ha_reset()::__PRETTY_FUNCTION__> "int handler::ha_reset()") at assert.c:101
#8  0x00005598cff938ff in handler::ha_reset (this=0x7f11dc0a70a8) at /data/src/10.3/sql/handler.cc:6300
#9  0x00005598cfbfa101 in close_thread_table (thd=0x7f11dc000b00, table_ptr=0x7f11dc000be0) at /data/src/10.3/sql/sql_base.cc:903
#10 0x00005598cfbf9e04 in close_thread_tables (thd=0x7f11dc000b00) at /data/src/10.3/sql/sql_base.cc:854
#11 0x00005598cfc95460 in mysql_execute_command (thd=0x7f11dc000b00) at /data/src/10.3/sql/sql_parse.cc:6369
#12 0x00005598cfc9a14e in mysql_parse (thd=0x7f11dc000b00, rawbuf=0x7f11dc012808 "UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1", length=48, parser_state=0x7f12225f85f0, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:8091
#13 0x00005598cfc8719e in dispatch_command (command=COM_QUERY, thd=0x7f11dc000b00, packet=0x7f11dc15fe81 "UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1", packet_length=48, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1858
#14 0x00005598cfc85bc3 in do_command (thd=0x7f11dc000b00) at /data/src/10.3/sql/sql_parse.cc:1403
#15 0x00005598cfded965 in do_handle_one_connection (connect=0x5598d2289f50) at /data/src/10.3/sql/sql_connect.cc:1402
#16 0x00005598cfded6dc in handle_one_connection (arg=0x5598d2289f50) at /data/src/10.3/sql/sql_connect.cc:1308
#17 0x00005598d06c22c2 in pfs_spawn_thread (arg=0x5598d21cd6f0) at /data/src/10.3/storage/perfschema/pfs.cc:1862
#18 0x00007f122edf64a4 in start_thread (arg=0x7f12225f9700) at pthread_create.c:456
#19 0x00007f122d33ed0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97

Non-debug build doesn't crash, but produces a warning, I'm not sure whether it is expected:

UPDATE v SET a = '2000-01-01' ORDER BY b LIMIT 1;
Warnings:
Note	1355	View being updated does not have complete key of underlying table in it



 Comments   
Comment by Elena Stepanova [ 2019-05-08 ]

Please ignore the complaint about the oddity of SET GLOBAL, it was a false alarm. I didn't take into account that SET SQL_MODE= DEFAULT sets the session variable to the current global value rather than to the built-in default.
I will update the description to remove irrelevant notes and simplify test case a bit.

Comment by Aleksey Midenkov [ 2019-05-11 ]

Cause

6901    void TABLE::mark_columns_needed_for_update()
6902    {
....
6950      /*
6951         For System Versioning we have to read all columns since we will store
6952         a copy of previous row with modified Sys_end column back to a table.
6953      */
6954      if (s->versioned)
6955      {
6956        // We will copy old columns to a new row.
6957        use_all_columns();
6958      }

TABLE::mark_columns_needed_for_update() -> use_all_columns() assigns ptr of all_set into read_set and write_set. Then TABLE::mark_columns_used_by_index_no_reset() changes all_set bitmap.

More details

Comment by Aleksey Midenkov [ 2019-05-13 ]

This might be reproducible without System Versioning because of this code:

    /*
      If the handler has no cursor capabilites, we have to read either
      the primary key, the hidden primary key or all columns to be
      able to do an update
    */
    if (s->primary_key == MAX_KEY)
      file->use_hidden_primary_key();

but relevant cases in federatedx and perfschema failed to satisfy all bug dependencies: federatedx could not execute ORDER BY (fails with 1032: Can't find record in 't1'). pefschema does not support indexes (but theoretically it might be reproduced when 8.0 perfschema indexes will be merged).

Comment by Aleksey Midenkov [ 2019-08-09 ]

Fix breaks stability of versioning.rpl,row in 10.3 without MDEV-16370 fixes applied.

Comment by Aleksey Midenkov [ 2019-10-07 ]

sanja https://github.com/mariadb/server/commit/decdc129e87d2289fc80eee456424207178e4d02

Comment by Oleksandr Byelkin [ 2019-10-08 ]

This bugfix is OK to push.

But check and fix signaling about the mask change in other parts of this file (as other commit)

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