Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-21242

Wrong result or failed assertion upon SELECT under READ UNCOMMITTED with index on virtual column

    XMLWordPrintable

    Details

      Description

      --source include/have_innodb.inc
       
      CREATE TABLE t1 ( 
          a CHAR(3),
          b INT,
          c INT,
          d CHAR(3) AS (a) VIRTUAL,
          KEY(b,d)
      ) ENGINE=InnoDB;
       
      INSERT INTO t1 (a,b,c) VALUES ('foo',0,10),('bar',1,11);
       
      SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
      SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
       
      # Cleanup
      DROP TABLE t1;
      

      10.3 e5e58777 non-debug

      SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
      a	b	c	d
      foo	0	10	NULL
      bar	1	11	NULL
      

      Values in the last (virtual) column are obviously wrong.

      10.3 e5e58777 debug

      mysqld: /data/src/10.3/sql/field.cc:7247: virtual String* Field_string::val_str(String*, String*): Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength)))' failed.
      191206 17:32:07 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007ff2c7a1ef12 in __GI___assert_fail (assertion=0x561286600e60 "!table || (!table->read_set || bitmap_is_set(table->read_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength)))", file=0x561286600cb9 "/data/src/10.3/sql/field.cc", line=7247, function=0x561286605020 <Field_string::val_str(String*, String*)::__PRETTY_FUNCTION__> "virtual String* Field_string::val_str(String*, String*)") at assert.c:101
      #8  0x0000561285b33636 in Field_string::val_str (this=0x7ff264006b38, val_buffer=0x7ff2c4265c50, val_ptr=0x7ff2c4265c50) at /data/src/10.3/sql/field.cc:7247
      #9  0x000056128572ef5b in Field::val_str (this=0x7ff264006b38, str=0x7ff2c4265c50) at /data/src/10.3/sql/field.h:841
      #10 0x000056128572ca83 in Protocol_text::store (this=0x7ff2640010a8, field=0x7ff264006b38) at /data/src/10.3/sql/protocol.cc:1257
      #11 0x0000561285b891a5 in Item_field::send (this=0x7ff264013a20, protocol=0x7ff2640010a8, buffer=0x7ff2c4266030) at /data/src/10.3/sql/item.cc:7457
      #12 0x000056128572b5ad in Protocol::send_result_set_row (this=0x7ff2640010a8, row_items=0x7ff264005270) at /data/src/10.3/sql/protocol.cc:997
      #13 0x00005612857d889e in select_send::send_data (this=0x7ff264013480, items=...) at /data/src/10.3/sql/sql_class.cc:2938
      #14 0x00005612858bd4fa in end_send (join=0x7ff2640134a8, join_tab=0x7ff264015908, end_of_records=false) at /data/src/10.3/sql/sql_select.cc:20758
      #15 0x00005612858babb2 in evaluate_join_record (join=0x7ff2640134a8, join_tab=0x7ff264015578, error=0) at /data/src/10.3/sql/sql_select.cc:19798
      #16 0x00005612858ba471 in sub_select (join=0x7ff2640134a8, join_tab=0x7ff264015578, end_of_records=false) at /data/src/10.3/sql/sql_select.cc:19578
      #17 0x00005612858b98fb in do_select (join=0x7ff2640134a8, procedure=0x0) at /data/src/10.3/sql/sql_select.cc:19118
      #18 0x0000561285890af3 in JOIN::exec_inner (this=0x7ff2640134a8) at /data/src/10.3/sql/sql_select.cc:4092
      #19 0x000056128588fec6 in JOIN::exec (this=0x7ff2640134a8) at /data/src/10.3/sql/sql_select.cc:3886
      #20 0x00005612858911d7 in mysql_select (thd=0x7ff264000af0, tables=0x7ff264012840, wild_num=1, fields=..., conds=0x7ff2640130f8, og_num=1, order=0x7ff264013368, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7ff264013480, unit=0x7ff2640049c0, select_lex=0x7ff264005148) at /data/src/10.3/sql/sql_select.cc:4291
      #21 0x00005612858828dc in handle_select (thd=0x7ff264000af0, lex=0x7ff2640048f8, result=0x7ff264013480, setup_tables_done_option=0) at /data/src/10.3/sql/sql_select.cc:370
      #22 0x000056128584a2eb in execute_sqlcom_select (thd=0x7ff264000af0, all_tables=0x7ff264012840) at /data/src/10.3/sql/sql_parse.cc:6294
      #23 0x0000561285840ce7 in mysql_execute_command (thd=0x7ff264000af0) at /data/src/10.3/sql/sql_parse.cc:3821
      #24 0x000056128584e5e3 in mysql_parse (thd=0x7ff264000af0, rawbuf=0x7ff264012608 "SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c", length=51, parser_state=0x7ff2c4267630, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7818
      #25 0x000056128583b12f in dispatch_command (command=COM_QUERY, thd=0x7ff264000af0, packet=0x7ff264008c71 "", packet_length=51, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1856
      #26 0x0000561285839a77 in do_command (thd=0x7ff264000af0) at /data/src/10.3/sql/sql_parse.cc:1401
      #27 0x00005612859b0fb4 in do_handle_one_connection (connect=0x561289f38490) at /data/src/10.3/sql/sql_connect.cc:1403
      #28 0x00005612859b0d16 in handle_one_connection (arg=0x561289f38490) at /data/src/10.3/sql/sql_connect.cc:1308
      #29 0x00007ff2c95944a4 in start_thread (arg=0x7ff2c4268700) at pthread_create.c:456
      #30 0x00007ff2c7adbd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      Reproducible on 10.2-10.3.
      With the test case above, I couldn't reproduce it on 10.4, 10.5, but see the second test case below, which only differs from the first one in one value for `b` column (2 instead of 1):

      --source include/have_innodb.inc
       
      CREATE TABLE t1 ( 
          a CHAR(3),
          b INT,
          c INT,
          d CHAR(3) AS (a) VIRTUAL,
          KEY(b,d)
      ) ENGINE=InnoDB;
       
      INSERT INTO t1 (a,b,c) VALUES ('foo',0,10),('bar',2,11);
       
      SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
      SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
       
      # Cleanup
      DROP TABLE t1;
      

      10.4 f5b76d8c non-debug

      SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c;
      a	b	c	d
      foo	0	10	NULL
      

      Reproducible on 10.2-10.5.

      10.4 f5b76d8c debug

      mysqld: /data/src/10.4/sql/field.cc:7278: virtual String* Field_string::val_str(String*, String*): Assertion `marked_for_read()' failed.
      191206 17:44:06 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007f7dfe9e9f12 in __GI___assert_fail (assertion=0x561ec9c13bf0 "marked_for_read()", file=0x561ec9c13a2b "/data/src/10.4/sql/field.cc", line=7278, function=0x561ec9c18760 <Field_string::val_str(String*, String*)::__PRETTY_FUNCTION__> "virtual String* Field_string::val_str(String*, String*)") at assert.c:101
      #8  0x0000561ec90d5877 in Field_string::val_str (this=0x7f7dac03ffd8, val_buffer=0x7f7df3db1480, val_ptr=0x7f7df3db1480) at /data/src/10.4/sql/field.cc:7278
      #9  0x0000561ec8c7923b in Field::val_str (this=0x7f7dac03ffd8, str=0x7f7df3db1480) at /data/src/10.4/sql/field.h:840
      #10 0x0000561ec8c769c9 in Protocol_text::store (this=0x7f7dac0010b8, field=0x7f7dac03ffd8) at /data/src/10.4/sql/protocol.cc:1275
      #11 0x0000561ec912dc11 in Item_field::send (this=0x7f7dac0152a0, protocol=0x7f7dac0010b8, buffer=0x7f7df3db1860) at /data/src/10.4/sql/item.cc:7110
      #12 0x0000561ec8c759bb in Protocol::send_result_set_row (this=0x7f7dac0010b8, row_items=0x7f7dac013370) at /data/src/10.4/sql/protocol.cc:1035
      #13 0x0000561ec8d2a83e in select_send::send_data (this=0x7f7dac014cf8, items=...) at /data/src/10.4/sql/sql_class.cc:3002
      #14 0x0000561ec8e20fc1 in end_send (join=0x7f7dac014d20, join_tab=0x7f7dac0172e0, end_of_records=false) at /data/src/10.4/sql/sql_select.cc:21424
      #15 0x0000561ec8e1e652 in evaluate_join_record (join=0x7f7dac014d20, join_tab=0x7f7dac016f38, error=0) at /data/src/10.4/sql/sql_select.cc:20455
      #16 0x0000561ec8e1df38 in sub_select (join=0x7f7dac014d20, join_tab=0x7f7dac016f38, end_of_records=false) at /data/src/10.4/sql/sql_select.cc:20235
      #17 0x0000561ec8e1d3c7 in do_select (join=0x7f7dac014d20, procedure=0x0) at /data/src/10.4/sql/sql_select.cc:19773
      #18 0x0000561ec8df25b9 in JOIN::exec_inner (this=0x7f7dac014d20) at /data/src/10.4/sql/sql_select.cc:4433
      #19 0x0000561ec8df16f6 in JOIN::exec (this=0x7f7dac014d20) at /data/src/10.4/sql/sql_select.cc:4215
      #20 0x0000561ec8df2e0b in mysql_select (thd=0x7f7dac000af0, tables=0x7f7dac0137e8, wild_num=1, fields=..., conds=0x7f7dac014108, og_num=1, order=0x7f7dac014ba0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f7dac014cf8, unit=0x7f7dac004a20, select_lex=0x7f7dac013228) at /data/src/10.4/sql/sql_select.cc:4647
      #21 0x0000561ec8de2b12 in handle_select (thd=0x7f7dac000af0, lex=0x7f7dac004958, result=0x7f7dac014cf8, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:420
      #22 0x0000561ec8da928b in execute_sqlcom_select (thd=0x7f7dac000af0, all_tables=0x7f7dac0137e8) at /data/src/10.4/sql/sql_parse.cc:6360
      #23 0x0000561ec8d9e939 in mysql_execute_command (thd=0x7f7dac000af0) at /data/src/10.4/sql/sql_parse.cc:3899
      #24 0x0000561ec8dad397 in mysql_parse (thd=0x7f7dac000af0, rawbuf=0x7f7dac013158 "SELECT * FROM t1 WHERE b BETWEEN 0 AND 1 ORDER BY c", length=51, parser_state=0x7f7df3db3160, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7901
      #25 0x0000561ec8d9853c in dispatch_command (command=COM_QUERY, thd=0x7f7dac000af0, packet=0x7f7dac1363c1 "", packet_length=51, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1842
      #26 0x0000561ec8d96bc9 in do_command (thd=0x7f7dac000af0) at /data/src/10.4/sql/sql_parse.cc:1360
      #27 0x0000561ec8f1f6b7 in do_handle_one_connection (connect=0x561ecbb30180) at /data/src/10.4/sql/sql_connect.cc:1412
      #28 0x0000561ec8f1f406 in handle_one_connection (arg=0x561ecbb30180) at /data/src/10.4/sql/sql_connect.cc:1316
      #29 0x0000561ec99216bd in pfs_spawn_thread (arg=0x561ecbaad870) at /data/src/10.4/storage/perfschema/pfs.cc:1862
      #30 0x00007f7e0055f4a4 in start_thread (arg=0x7f7df3db4700) at pthread_create.c:456
      #31 0x00007f7dfeaa6d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      Reproducible on 10.4, 10.5. With 10.2-10.3 it produces the same assertion failure as the first test case.

        Attachments

          Activity

            People

            Assignee:
            nikitamalyavin Nikita Malyavin
            Reporter:
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: