[MDEV-9924] Assertion `((select_options & (1ULL << 17)) ? 1 : 0)' failed in bool JOIN::make_aggr_tables_info Created: 2016-04-14  Updated: 2020-05-05  Resolved: 2017-02-16

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions
Affects Version/s: 10.2
Fix Version/s: 10.2.5

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: 10.2-rc

Issue Links:
Relates
relates to MDEV-9896 Testing for window functions Open
relates to MDEV-22461 JOIN::make_aggr_tables_info(): Asser... Closed

 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



 Comments   
Comment by Sergei Petrunia [ 2016-04-14 ]

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

Comment by Elena Stepanova [ 2016-04-14 ]

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

Comment by Elena Stepanova [ 2016-09-22 ]

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;

Comment by Igor Babaev [ 2017-02-13 ]

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;

Comment by Igor Babaev [ 2017-02-15 ]

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.

Comment by Igor Babaev [ 2017-02-16 ]

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

Generated at Thu Feb 08 07:38:21 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.