[MDEV-273] SHOW EXPLAIN: server crashes in JOIN::print_explain on a query with impossible WHERE Created: 2012-05-16  Updated: 2012-05-16  Resolved: 2012-05-16

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: 10.0.0

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-165 MWL#182: Explain running statements: ... Closed

 Description   

#3  <signal handler called>
#4  0x00000000007a86e2 in JOIN::print_explain (this=0x1d404b8, result=0x1cb3ab8, 
    explain_flags=0 '\000', on_the_fly=true, need_tmp_table=false, need_order=false, 
    distinct=false, message=0x0) at sql_select.cc:21264
#5  0x00000000005d611d in st_select_lex::print_explain (this=0x1cf1100, 
    output=0x1cb3ab8, explain_flags=0 '\000') at sql_lex.cc:3769
#6  0x00000000005d628f in st_select_lex_unit::print_explain (this=0x1cf1450, 
    output=0x1cb3ab8, explain_flags=0 '\000') at sql_lex.cc:3820
#7  0x00000000005d6189 in st_select_lex::print_explain (this=0x1ce2098, 
    output=0x1cb3ab8, explain_flags=0 '\000') at sql_lex.cc:3784
#8  0x00000000005d628f in st_select_lex_unit::print_explain (this=0x1ce1b90, 
    output=0x1cb3ab8, explain_flags=0 '\000') at sql_lex.cc:3820
#9  0x00000000006ccbc5 in Show_explain_request::get_explain_data (arg=0x7f5ae1c5bba0)
    at sql_class.cc:3042
#10 0x000000000095b335 in Apc_target::process_apc_requests (this=0x1ce1900)
    at my_apc.cc:255
#11 0x00000000006c8a30 in THD::check_killed (this=0x1cdf5e8) at sql_class.cc:1904
#12 0x0000000000744c9f in JOIN_CACHE::join_matching_records (this=0x1d4d658, 
    skip_last=false) at sql_join_cache.cc:2238
#13 0x00000000007447fa in JOIN_CACHE::join_records (this=0x1d4d658, skip_last=false)
    at sql_join_cache.cc:2064
#14 0x0000000000799de5 in sub_select_cache (join=0x1d3fe78, join_tab=0x1d4d158, 
    end_of_records=true) at sql_select.cc:15532
#15 0x000000000079a004 in sub_select (join=0x1d3fe78, join_tab=0x1d4ce38, 
    end_of_records=true) at sql_select.cc:15694
#16 0x0000000000799ab5 in do_select (join=0x1d3fe78, fields=0x1ce21a0, table=0x0, 
    procedure=0x0) at sql_select.cc:15416
#17 0x000000000077aa4e in JOIN::exec_inner (this=0x1d3fe78) at sql_select.cc:2810
#18 0x0000000000777e31 in JOIN::exec (this=0x1d3fe78) at sql_select.cc:2125
#19 0x000000000077b2e7 in mysql_select (thd=0x1cdf5e8, rref_pointer_array=0x1ce22f0, 
    tables=0x1cf07a0, wild_num=0, fields=..., conds=0x1d3fcc8, og_num=0, order=0x0, 
    group=0x0, having=0x0, proc_param=0x0, select_options=2147764736, result=0x1d3fe58, 
    unit=0x1ce1b90, select_lex=0x1ce2098) at sql_select.cc:3031
#20 0x0000000000771d62 in handle_select (thd=0x1cdf5e8, lex=0x1ce1af0, result=0x1d3fe58, 
    setup_tables_done_option=0) at sql_select.cc:332
#21 0x00000000007002d9 in execute_sqlcom_select (thd=0x1cdf5e8, all_tables=0x1cf07a0)
    at sql_parse.cc:5178
#22 0x00000000006f721f in mysql_execute_command (thd=0x1cdf5e8) at sql_parse.cc:2285
#23 0x0000000000702cb4 in mysql_parse (thd=0x1cdf5e8, 
    rawbuf=0x1cf0520 "SELECT a1 FROM A, B \nWHERE a1 < ALL ( \nSELECT a1 FROM A \nWHERE a1 IN ( SELECT a1 FROM A, C ) \n)", length=95, found_semicolon=0x7f5ae1c14c98)
    at sql_parse.cc:6179
#24 0x00000000006f49ce in dispatch_command (command=COM_QUERY, thd=0x1cdf5e8, 
    packet=0x1ce9bb9 "", packet_length=95) at sql_parse.cc:1229
#25 0x00000000006f3d02 in do_command (thd=0x1cdf5e8) at sql_parse.cc:924
#26 0x00000000006f0b46 in handle_one_connection (arg=0x1cdf5e8) at sql_connect.cc:1218

Reproducible with the default optimizer switch as well as with all OFF values (except for in_to_exists which is required to execute the query).

Default optimizer switch:

index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

EXPLAIN (with default optimizer_switch):

id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered  Extra
1       PRIMARY A       index   NULL    a1      5       NULL    20      100.00  Using where; Using index
1       PRIMARY B       ALL     NULL    NULL    NULL    NULL    87      100.00  Using join buffer (flat, BNL join)
2       SUBQUERY        NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
Warnings:
Note    1003    select `test`.`A`.`a1` AS `a1` from `test`.`A` join `test`.`B` where <not>(<in_optimizer>(`test`.`A`.`a1`,(<min>(select `test`.`A`.`a1` from `test`.`A` semi join (`test`.`A` join `test`.`C`) where 0) <= <cache>(`test`.`A`.`a1`))))

bzr version-info

revision-id: psergey@askmonty.org-20120515115650-kqeip9cgxltgzx75
date: 2012-05-15 15:56:50 +0400
revno: 3511

Test case:

CREATE TABLE A (a1 INT, KEY(a1)) ENGINE=MyISAM;
INSERT INTO A VALUES
  (4),(6),(7),(1),(0),(7),(7),(1),(7),(1),
  (5),(2),(0),(1),(8),(1),(1),(9),(1),(5);
 
CREATE TABLE B (b1 INT) ENGINE=MyISAM;
INSERT INTO B VALUES
  (4),(5),(8),(4),(8),(2),(9),(6),(4),(8),
  (3),(5),(9),(6),(8),(3),(2),(6),(3),(1),
  (4),(3),(1),(7),(0),(0),(9),(5),(9),(0),
  (2),(2),(5),(9),(1),(4),(8),(6),(5),(5),
  (1),(7),(2),(8),(9),(3),(2),(6),(6),(5),
  (4),(3),(2),(7),(4),(6),(0),(8),(5),(8),
  (2),(9),(7),(5),(7),(0),(4),(3),(1),(0),
  (6),(2),(8),(3),(7),(3),(5),(5),(1),(2),
  (1),(7),(1),(9),(9),(8),(3);
 
CREATE TABLE C (c1 INT) ENGINE=MyISAM;
 
--connect (con1,localhost,root,,)
--let $con_id = `SELECT CONNECTION_ID()`
 
--send
SELECT a1 FROM A, B
WHERE a1 < ALL ( 
  SELECT a1 FROM A
  WHERE a1 IN ( SELECT a1 FROM A, C )
);
 
--connection default
--let $run = 100
while ($run)
{
  --error 0,1220
  --eval SHOW EXPLAIN FOR $con_id
  --dec $run
}
 
--connection con1
--reap
 
DROP TABLE A, B, C;
 


Generated at Thu Feb 08 06:27:31 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.