[MDEV-14695] Assertion `n < m_size' failed in Bounds_checked_array<Element_type>::operator Created: 2017-12-17  Updated: 2018-05-16  Resolved: 2018-05-16

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.2, 10.3
Fix Version/s: 10.2.15, 10.3.7

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Varun Gupta (Inactive)
Resolution: Fixed Votes: 0
Labels: affects-tests


 Description   

CREATE TABLE t1 (b1 BIT, b2 BIT, b3 BIT, b4 BIT , b5 BIT, b6 BIT);
INSERT INTO t1 VALUES (1,0,0,1,0,1),(0,1,0,0,1,0);
 
SELECT DISTINCT * FROM t1;
 
# Cleanup
DROP TABLE t1;

10.2 a3476a5de2ee87e

mysqld: /data/src/10.2/sql/sql_array.h:64: Element_type& Bounds_checked_array<Element_type>::operator[](size_t) [with Element_type = Item*; size_t = long unsigned int]: Assertion `n < m_size' failed.
171217 17:01:30 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f1a12533ee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000560714ec2d31 in Bounds_checked_array<Item*>::operator[] (this=0x7f1a0c80db40, n=11) at /data/src/10.2/sql/sql_array.h:64
#9  0x0000560714f9c4ba in change_to_use_tmp_fields (thd=0x7f19fc000b00, ref_pointer_array=..., res_selected_fields=..., res_all_fields=..., elements=6, all_fields=...) at /data/src/10.2/sql/sql_select.cc:23382
#10 0x0000560714f66b22 in JOIN::make_aggr_tables_info (this=0x7f19fc012de0) at /data/src/10.2/sql/sql_select.cc:2492
#11 0x0000560714f65615 in JOIN::optimize_inner (this=0x7f19fc012de0) at /data/src/10.2/sql/sql_select.cc:2159
#12 0x0000560714f61ac9 in JOIN::optimize (this=0x7f19fc012de0) at /data/src/10.2/sql/sql_select.cc:1085
#13 0x0000560714f6aaf4 in mysql_select (thd=0x7f19fc000b00, tables=0x7f19fc0126d0, wild_num=1, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748609, result=0x7f19fc012dc0, unit=0x7f19fc0046a0, select_lex=0x7f19fc004dd8) at /data/src/10.2/sql/sql_select.cc:3695
#14 0x0000560714f5f3e8 in handle_select (thd=0x7f19fc000b00, lex=0x7f19fc0045d8, result=0x7f19fc012dc0, setup_tables_done_option=0) at /data/src/10.2/sql/sql_select.cc:373
#15 0x0000560714f2b4e0 in execute_sqlcom_select (thd=0x7f19fc000b00, all_tables=0x7f19fc0126d0) at /data/src/10.2/sql/sql_parse.cc:6455
#16 0x0000560714f214e3 in mysql_execute_command (thd=0x7f19fc000b00) at /data/src/10.2/sql/sql_parse.cc:3462
#17 0x0000560714f2eea2 in mysql_parse (thd=0x7f19fc000b00, rawbuf=0x7f19fc0124e8 "SELECT DISTINCT * FROM t1", length=25, parser_state=0x7f1a0c80f200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7896
#18 0x0000560714f1cdd4 in dispatch_command (command=COM_QUERY, thd=0x7f19fc000b00, packet=0x7f19fc1703b1 "SELECT DISTINCT * FROM t1", packet_length=25, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1805
#19 0x0000560714f1b732 in do_command (thd=0x7f19fc000b00) at /data/src/10.2/sql/sql_parse.cc:1360
#20 0x0000560715069351 in do_handle_one_connection (connect=0x560718a1a110) at /data/src/10.2/sql/sql_connect.cc:1354
#21 0x00005607150690de in handle_one_connection (arg=0x560718a1a110) at /data/src/10.2/sql/sql_connect.cc:1260
#22 0x0000560715487a76 in pfs_spawn_thread (arg=0x560718979000) at /data/src/10.2/storage/perfschema/pfs.cc:1863
#23 0x00007f1a1420a494 in start_thread (arg=0x7f1a0c810700) at pthread_create.c:333
#24 0x00007f1a125f093f in clone () from /lib/x86_64-linux-gnu/libc.so.6

Reproducible with MyISAM and InnoDB.
Also reproducible on 10.3.
Not reproducible on 5.5, 10.0, 10.1.
No visible effect on non-debug builds.



 Comments   
Comment by Elena Stepanova [ 2018-03-21 ]

Still reproducible and highly annoying in tests.

Comment by Varun Gupta (Inactive) [ 2018-05-08 ]

After first round of investigations, I see that for BIT fields with DISTINCT we create new fields for all the fields belonged in the select list for GROUP BY. The function that does this is create_distinct_group. So in this function we add these new fields (called hidden group by fields) to the all_fields list.

We are hitting the assert in my opinion because we don't consider these hidden fields estimate during calculating the size of the ref_pointer_array.

Comment by Varun Gupta (Inactive) [ 2018-05-12 ]

Patch
http://lists.askmonty.org/pipermail/commits/2018-May/012530.html

Comment by Oleksandr Byelkin [ 2018-05-14 ]

OK to push after moving variable declaration as we discussed

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