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

Assertion `((select_options & (1ULL << 17)) ? 1 : 0)' failed in bool JOIN::make_aggr_tables_info

Details

    Description

      create table t2 (i int);
      insert into t2 values (1),(2);
      select i, rank() over (order by i) rnk from t2 group by ( select rnk );
      

      Stack trace from 10.2 commit b532be9f8ce4872be4a3f1ef2fa296a1de347859

      mysqld: /src/10.2/sql/sql_select.cc:2491: bool JOIN::make_aggr_tables_info(): Assertion `((select_options & (1ULL << 17)) ? 1 : 0)' failed.
      160414 22:50:07 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007f21f51a51d2 in __assert_fail () from /lib64/libc.so.6
      #8  0x0000555c2ff93e07 in JOIN::make_aggr_tables_info (this=0x7f21c8e778e8) at /src/10.2/sql/sql_select.cc:2491
      #9  0x0000555c2ff92622 in JOIN::optimize_inner (this=0x7f21c8e778e8) at /src/10.2/sql/sql_select.cc:2068
      #10 0x0000555c2ff8f15a in JOIN::optimize (this=0x7f21c8e778e8) at /src/10.2/sql/sql_select.cc:1063
      #11 0x0000555c2ff97489 in mysql_select (thd=0x7f21c8e10e70, tables=0x7f21c8e76418, wild_num=0, fields=..., conds=0x0, og_num=1, order=0x0, group=0x7f21c8e777a8, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f21c8e778c8, unit=0x7f21c8e148c0, select_lex=0x7f21c8e14fe0) at /src/10.2/sql/sql_select.cc:3521
      #12 0x0000555c2ff8cd62 in handle_select (thd=0x7f21c8e10e70, lex=0x7f21c8e147f8, result=0x7f21c8e778c8, setup_tables_done_option=0) at /src/10.2/sql/sql_select.cc:377
      #13 0x0000555c2ff5c8d5 in execute_sqlcom_select (thd=0x7f21c8e10e70, all_tables=0x7f21c8e76418) at /src/10.2/sql/sql_parse.cc:6299
      #14 0x0000555c2ff52603 in mysql_execute_command (thd=0x7f21c8e10e70) at /src/10.2/sql/sql_parse.cc:3338
      #15 0x0000555c2ff5ff6a in mysql_parse (thd=0x7f21c8e10e70, rawbuf=0x7f21c8e75d88 "select i, rank() over (order by i) rnk from t2 group by ( select rnk )", length=70, parser_state=0x7f21f7456a30, is_next_command=false) at /src/10.2/sql/sql_parse.cc:7702
      #16 0x0000555c2ff4e4d5 in dispatch_command (command=COM_QUERY, thd=0x7f21c8e10e70, packet=0x7f21c8e6e8b1 "select i, rank() over (order by i) rnk from t2 group by ( select rnk )", packet_length=70, is_com_multi=false, is_next_command=false) at /src/10.2/sql/sql_parse.cc:1790
      #17 0x0000555c2ff4cf4a in do_command (thd=0x7f21c8e10e70) at /src/10.2/sql/sql_parse.cc:1353
      #18 0x0000555c30082c64 in do_handle_one_connection (connect=0x7f21f4c879d0) at /src/10.2/sql/sql_connect.cc:1358
      #19 0x0000555c300829f6 in handle_one_connection (arg=0x7f21f4c879d0) at /src/10.2/sql/sql_connect.cc:1264
      #20 0x00007f21f70ee0a4 in start_thread () from /lib64/libpthread.so.0
      

      Attachments

        Issue Links

          Activity

            psergei Sergei Petrunia added a comment - - edited

            This query should have returned an error. "rnk" refers to a window function, so it may not be used as a GROUP BY argument.

            psergei Sergei Petrunia added a comment - - edited This query should have returned an error. "rnk" refers to a window function, so it may not be used as a GROUP BY argument.

            Yes, I know. It works as expected (meaning returns an error) for HAVING, but causes an assertion failure for GROUP BY.

            elenst Elena Stepanova added a comment - Yes, I know. It works as expected (meaning returns an error) for HAVING, but causes an assertion failure for GROUP BY.
            elenst Elena Stepanova added a comment - - edited

            Still happens on current bb-10.2-vicentiu-window.
            Example without a window function in GROUP BY:

            CREATE TABLE t1 (i INT, c VARCHAR(8));
            INSERT INTO t1 VALUES (1,'foo'),(2,'foo'),(3,'bar');
             
            SELECT i, COUNT(*) OVER (PARTITION BY c) FROM t1 WHERE i = 4 GROUP BY i;
            

            elenst Elena Stepanova added a comment - - edited Still happens on current bb-10.2-vicentiu-window. Example without a window function in GROUP BY: CREATE TABLE t1 (i INT , c VARCHAR (8)); INSERT INTO t1 VALUES (1, 'foo' ),(2, 'foo' ),(3, 'bar' );   SELECT i, COUNT (*) OVER (PARTITION BY c) FROM t1 WHERE i = 4 GROUP BY i;
            igor Igor Babaev added a comment -

            This is a simpler query that fails in the same way:

            select i, rank() over (order by i) rnk from t2 group by 1+2;
            

            igor Igor Babaev added a comment - This is a simpler query that fails in the same way: select i, rank() over (order by i) rnk from t2 group by 1+2;
            igor Igor Babaev added a comment -

            If I remove the failing assertion (that is not valid anymore) I get

            MariaDB [test]> select i, row_number() over () from t2 group by 1+2;
            +------+----------------------+
            | i    | row_number() over () |
            +------+----------------------+
            |    1 |                    2 |
            +------+----------------------+
            

            The above is apparently not correct. At the same time I have:

            MariaDB [test]> select i, max(i), row_number() over () from t2;
            +------+--------+----------------------+
            | i    | max(i) | row_number() over () |
            +------+--------+----------------------+
            |    1 |      2 |                    1 |
            +------+--------+----------------------+
            

            And this is correct. I will investigate why we have this difference.

            igor Igor Babaev added a comment - If I remove the failing assertion (that is not valid anymore) I get MariaDB [test]> select i, row_number() over () from t2 group by 1+2; +------+----------------------+ | i | row_number() over () | +------+----------------------+ | 1 | 2 | +------+----------------------+ The above is apparently not correct. At the same time I have: MariaDB [test]> select i, max(i), row_number() over () from t2; +------+--------+----------------------+ | i | max(i) | row_number() over () | +------+--------+----------------------+ | 1 | 2 | 1 | +------+--------+----------------------+ And this is correct. I will investigate why we have this difference.
            igor Igor Babaev added a comment -

            The fix for this bug was pushed into the 10.2 tree.

            igor Igor Babaev added a comment - The fix for this bug was pushed into the 10.2 tree.

            People

              igor Igor Babaev
              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.