[MDEV-10773] ANALYZE FORMAT=JSON query_with_CTE crashes Created: 2016-09-08  Updated: 2017-01-30  Resolved: 2017-01-30

Status: Closed
Project: MariaDB Server
Component/s: Admin statements, Optimizer - CTE
Affects Version/s: 10.2
Fix Version/s: 10.2.4

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

Sprint: 10.2.4-2

 Description   

Here's a query that crashes:

analyze format=json 
with recursive src(counter) as 
(select 1 
 union 
 select counter+1 from src where counter<10
) select * from src

  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7ffff43b7300 (LWP 1045)]
  0x0000555555d43a10 in Item_field::print (this=0x7fff98012b98, str=0x7ffff43b4430, query_type=QT_EXPLAIN) at /home/psergey/dev-git/10.2/sql/item.cc:6899
(gdb) p this
  $2 = (Item_field * const) 0x7fff98012b98
(gdb) p field
  $4 = (Field *) 0x7fff9801eaa8
(gdb) p field->table
  $6 = (TABLE *) 0x8f8f8f8f8f8f8f8f
(gdb) p this->fixed
  $8 = true

(gdb) wher
  #0  0x0000555555d43a10 in Item_field::print (this=0x7fff98012b98, str=0x7ffff43b4430, query_type=QT_EXPLAIN) at /home/psergey/dev-git/10.2/sql/item.cc:6899
  #1  0x0000555555d8951c in Item_func::print_op (this=0x7fff98012d28, str=0x7ffff43b4430, query_type=QT_EXPLAIN) at /home/psergey/dev-git/10.2/sql/item_func.cc:477
  #2  0x0000555555d6aa57 in Item_bool_rowready_func2::print (this=0x7fff98012d28, str=0x7ffff43b4430, query_type=QT_EXPLAIN) at /home/psergey/dev-git/10.2/sql/item_cmpfunc.h:481
  #3  0x0000555555c4070b in write_item (writer=0x7ffff43b4b80, item=0x7fff98012d28) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:1346
  #4  0x0000555555c409ce in Explain_table_access::tag_to_json (this=0x7fff98021488, writer=0x7ffff43b4b80, tag=ET_USING_WHERE) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:1404
  #5  0x0000555555c41569 in Explain_table_access::print_explain_json (this=0x7fff98021488, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:1651
  #6  0x0000555555c3f52c in Explain_basic_join::print_explain_json_interns (this=0x7fff98016c80, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:1000
  #7  0x0000555555c3f0c0 in Explain_select::print_explain_json (this=0x7fff98016c80, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:905
  #8  0x0000555555c3e24a in Explain_union::print_explain_json (this=0x7fff980234b0, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:585
  #9  0x0000555555c41841 in Explain_table_access::print_explain_json (this=0x7fff98022fa0, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:1691
  #10 0x0000555555c3f52c in Explain_basic_join::print_explain_json_interns (this=0x7fff98022ea0, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:1000
  #11 0x0000555555c3f0c0 in Explain_select::print_explain_json (this=0x7fff98022ea0, query=0x7fff980151c0, writer=0x7ffff43b4b80, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:905
  #12 0x0000555555c3ccca in Explain_query::print_explain_json (this=0x7fff980151c0, output=0x7fff98023688, is_analyze=true) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:224
  #13 0x0000555555c3ca0d in Explain_query::send_explain (this=0x7fff980151c0, thd=0x7fff98000b00) at /home/psergey/dev-git/10.2/sql/sql_explain.cc:167
  #14 0x0000555555ad87ba in execute_sqlcom_select (thd=0x7fff98000b00, all_tables=0x7fff980130c0) at /home/psergey/dev-git/10.2/sql/sql_parse.cc:6345
  #15 0x0000555555ace2ac in mysql_execute_command (thd=0x7fff98000b00) at /home/psergey/dev-git/10.2/sql/sql_parse.cc:3364
  #16 0x0000555555adbe46 in mysql_parse (thd=0x7fff98000b00, rawbuf=0x7fff98010d58 "analyze format=json with recursive src(counter) as (select 1 union select counter+1 from src where counter<10) select * from src", length=128, parser_state=0x7ffff43b5ca0, is_com_multi=false, is_next_command=false) at /home/psergey/dev-git/10.2/sql/sql_parse.cc:7759
  #17 0x0000555555ac9fa8 in dispatch_command (command=COM_QUERY, thd=0x7fff98000b00, packet=0x7fff98008611 "", packet_length=128, is_com_multi=false, is_next_command=false) at /home/psergey/dev-git/10.2/sql/sql_parse.cc:1793
  #18 0x0000555555ac89c4 in do_command (thd=0x7fff98000b00) at /home/psergey/dev-git/10.2/sql/sql_parse.cc:1353



 Comments   
Comment by Sergei Petrunia [ 2016-09-08 ]

The query itself works:

MariaDB [ontime]> with recursive src(counter) as (select 1 union select counter+1 from src where counter<10) select * from src;
+---------+
| counter |
+---------+
|       1 |
|       2 |
|       3 |
|       4 |
|       5 |
|       6 |
|       7 |
|       8 |
|       9 |
|      10 |
+---------+
10 rows in set (0.01 sec)

and so does the tabular ANALYZE:

MariaDB [test]> analyze with recursive src(counter) as (select 1 union select counter+1 from src where counter<10) select * from src;                  
+------+-----------------+------------+------+---------------+------+---------+------+------+--------+----------+------------+----------------+        
| id   | select_type     | table      | type | possible_keys | key  | key_len | ref  | rows | r_rows | filtered | r_filtered | Extra          |        
+------+-----------------+------------+------+---------------+------+---------+------+------+--------+----------+------------+----------------+        
|    1 | PRIMARY         | <derived2> | ALL  | NULL          | NULL | NULL    | NULL |    2 |  10.00 |   100.00 |     100.00 |                |        
|    2 | SUBQUERY        | NULL       | NULL | NULL          | NULL | NULL    | NULL | NULL |   NULL |     NULL |       NULL | No tables used |
|    3 | RECURSIVE UNION | <derived2> | ALL  | NULL          | NULL | NULL    | NULL |    2 |   1.00 |   100.00 |      90.00 | Using where    |
| NULL | UNION RESULT    | <union2,3> | ALL  | NULL          | NULL | NULL    | NULL | NULL |   0.00 |     NULL |       NULL |                |
+------+-----------------+------------+------+---------------+------+---------+------+------+--------+----------+------------+----------------+
4 rows in set (0.00 sec)

Comment by Sergei Petrunia [ 2016-09-08 ]

EXPLAIN FORMAT=JSON also works.

Comment by Sergei Petrunia [ 2017-01-17 ]

Doesn't crash anymore on current 10.2

Comment by Sergei Petrunia [ 2017-01-17 ]

Not reproducible anymore. Added a testcase.

Comment by Sergei Petrunia [ 2017-01-18 ]

Still crashes, re-opening

Comment by Igor Babaev [ 2017-01-30 ]

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

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