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

Assertion `key_read == 0' failed in TABLE::enable_keyread with SELECT SQ and WHERE SQ

Details

    Description

      CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (4),(8);
       
      CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM;
      INSERT INTO t2 VALUES (6),(9);
       
      SELECT ( SELECT MAX(sq.f2) FROM t1 ) FROM ( SELECT * FROM t2 ) AS sq WHERE f2 = 2;

      Stack trace from 5.5 commit 86f46a3da4a6d82cb510dc4c270d46cfd6a8965b

      sql/table.h:1283: void TABLE::enable_keyread(): Assertion `key_read == 0' failed.
      150325  0:34:39 [ERROR] mysqld got signal 6 ;
       
      #6  0x00007f02002a5311 in *__GI___assert_fail (assertion=0xd6a5f8 "key_read == 0", file=<optimized out>, line=1283, function=0xd6d830 "void TABLE::enable_keyread()") at assert.c:81
      #7  0x00000000006a05a0 in TABLE::enable_keyread (this=0x7f01fadb4860) at 5.5/sql/table.h:1283
      #8  0x000000000090a968 in find_key_for_maxmin (max_fl=true, ref=0x7f01fb7b3690, field=0x7f01fac59998, cond=0x0, range_fl=0x7f01fb7b430c, prefix_len=0x7f01fb7b4308) at 5.5/sql/opt_sum.cc:967
      #9  0x00000000009092e0 in opt_sum_query (thd=0x7f01fbd50060, tables=..., all_fields=..., conds=0x0) at 5.5/sql/opt_sum.cc:391
      #10 0x00000000006658dc in JOIN::optimize (this=0x7f01fad3fd48) at 5.5/sql/sql_select.cc:1172
      #11 0x000000000062b2d0 in st_select_lex::optimize_unflattened_subqueries (this=0x7f01fbd53a60, const_only=false) at 5.5/sql/sql_lex.cc:3506
      #12 0x000000000077ada2 in JOIN::optimize_unflattened_subqueries (this=0x7f01fad3f078) at 5.5/sql/opt_subselect.cc:4944
      #13 0x0000000000667667 in JOIN::optimize (this=0x7f01fad3f078) at 5.5/sql/sql_select.cc:1665
      #14 0x000000000066c45b in mysql_select (thd=0x7f01fbd50060, rref_pointer_array=0x7f01fbd53cd0, tables=0x7f01fad6a4f8, wild_num=0, fields=..., conds=0x7f01fad6ac78, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f01fad6ae88, unit=0x7f01fbd53380, select_lex=0x7f01fbd53a60) at 5.5/sql/sql_select.cc:3080
      #15 0x0000000000662fbd in handle_select (thd=0x7f01fbd50060, lex=0x7f01fbd532d0, result=0x7f01fad6ae88, setup_tables_done_option=0) at 5.5/sql/sql_select.cc:319
      #16 0x000000000063c1fc in execute_sqlcom_select (thd=0x7f01fbd50060, all_tables=0x7f01fad6a4f8) at 5.5/sql/sql_parse.cc:4689
      #17 0x00000000006353de in mysql_execute_command (thd=0x7f01fbd50060) at 5.5/sql/sql_parse.cc:2234
      #18 0x000000000063ece2 in mysql_parse (thd=0x7f01fbd50060, rawbuf=0x7f01fae87078 "SELECT ( SELECT MAX(sq.f2) FROM t1 ) FROM ( SELECT * FROM t2 ) AS sq WHERE f2 = 2", length=81, parser_state=0x7f01fb7b5620) at 5.5/sql/sql_parse.cc:5909
      #19 0x0000000000632925 in dispatch_command (command=COM_QUERY, thd=0x7f01fbd50060, packet=0x7f01fbe09061 "SELECT ( SELECT MAX(sq.f2) FROM t1 ) FROM ( SELECT * FROM t2 ) AS sq WHERE f2 = 2", packet_length=81) at 5.5/sql/sql_parse.cc:1079
      #20 0x0000000000631ab1 in do_command (thd=0x7f01fbd50060) at 5.5/sql/sql_parse.cc:793
      #21 0x0000000000734122 in do_handle_one_connection (thd_arg=0x7f01fbd50060) at 5.5/sql/sql_connect.cc:1266
      #22 0x0000000000733be1 in handle_one_connection (arg=0x7f01fbd50060) at 5.5/sql/sql_connect.cc:1181
      #23 0x0000000000b6c629 in pfs_spawn_thread (arg=0x7f01fbd71fc0) at 5.5/storage/perfschema/pfs.cc:1015
      #24 0x00007f02020a0b50 in start_thread (arg=<optimized out>) at pthread_create.c:304
      #25 0x00007f020035670d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 60217 ] MariaDB v3 [ 66528 ]
            jplindst Jan Lindström (Inactive) made changes -
            Assignee Oleksandr Byelkin [ sanja ] Jan Lindström [ jplindst ]
            jplindst Jan Lindström (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]

            This was most simples fix I could find. I could not find counter example where this would not work.

            jplindst Jan Lindström (Inactive) added a comment - This was most simples fix I could find. I could not find counter example where this would not work.
            jplindst Jan Lindström (Inactive) made changes -
            Assignee Jan Lindström [ jplindst ] Oleksandr Byelkin [ sanja ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            sanja,

            If it's only about push and there is nothing else to do, please push it, so it gets merged up to 10.x.

            elenst Elena Stepanova added a comment - sanja , If it's only about push and there is nothing else to do, please push it, so it gets merged up to 10.x.

            In my understanding query can use two indexes SELECT ( SELECT MAX(sq.f2) FROM t1 ) FROM ( SELECT * FROM t2 ) AS sq WHERE f2 = 2; i.e. index from t1 and index from t2, we call table::enable_keyread() for t2 from /home/jan/mysql/5.5-innodb-git/sql/sql_select.cc:10303 and then again from /home/jan/mysql/5.5-innodb-git/sql/opt_sum.cc:967 between these two no table::disable_keyread() is not called, I have no idea where that disable_keyread should be called

            jplindst Jan Lindström (Inactive) added a comment - In my understanding query can use two indexes SELECT ( SELECT MAX(sq.f2) FROM t1 ) FROM ( SELECT * FROM t2 ) AS sq WHERE f2 = 2; i.e. index from t1 and index from t2, we call table::enable_keyread() for t2 from /home/jan/mysql/5.5-innodb-git/sql/sql_select.cc:10303 and then again from /home/jan/mysql/5.5-innodb-git/sql/opt_sum.cc:967 between these two no table::disable_keyread() is not called, I have no idea where that disable_keyread should be called
            sanja Oleksandr Byelkin made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            sanja Oleksandr Byelkin made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]

            Fixed together with MDEV-10146

            serg Sergei Golubchik added a comment - Fixed together with MDEV-10146
            serg Sergei Golubchik made changes -
            Fix Version/s 5.5.57 [ 22539 ]
            Fix Version/s 10.0.32 [ 22504 ]
            Fix Version/s 10.1.26 [ 22553 ]
            Fix Version/s 10.2.7 [ 22543 ]
            Fix Version/s 5.5 [ 15800 ]
            Fix Version/s 10.0 [ 16000 ]
            Fix Version/s 10.1 [ 16100 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 66528 ] MariaDB v4 [ 148933 ]

            People

              sanja Oleksandr Byelkin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.