Assertion `tree1->keys[key_no] && tree2->keys[key_no]' in sel_trees_can_be_ored()

Bug #891953 reported by Philip Stoev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
Critical
Igor Babaev

Bug Description

The following query:

SELECT * FROM t1
WHERE b BETWEEN 4 AND 5
AND a IN ( 255 , 4 )
OR b IN ( 2 , 14 , 25 )
OR b != 2;

asserts as follows:

mysqld: opt_range.cc:8088: bool sel_trees_can_be_ored(RANGE_OPT_PARAM*, SEL_TREE*, SEL_TREE*, key_map*): Assertion `tree1->keys[key_no] && tree2->keys[key_no]' failed.

#8 0x006b0d98 in __assert_fail () from /lib/libc.so.6
#9 0x083e3ef8 in sel_trees_can_be_ored (param=0xae87f608, tree1=0xae5294f0, tree2=0xae529148, common_keys=0xae87f330) at opt_range.cc:8088
#10 0x083d6196 in SEL_IMERGE::or_sel_tree_with_checks (this=0xae529380, param=0xae87f608, n_trees=2, tree=0xae529148, is_first_check_pass=false,
    is_last_check_pass=0xae87f39b) at opt_range.cc:1173
#11 0x083d6a47 in imerge_list_or_tree (param=0xae87f608, merges=0xae87f400, tree=0xae528bb0) at opt_range.cc:1558
#12 0x083e4a29 in tree_or (param=0xae87f608, tree1=0xae528398, tree2=0xae528a78) at opt_range.cc:8411
#13 0x083e1def in get_mm_tree (param=0xae87f608, cond=0xae513b90) at opt_range.cc:7197
#14 0x083d9ef4 in SQL_SELECT::test_quick_select (this=0xae5147c0, thd=0xabd98f8, keys_to_use=..., prev_tables=0, limit=18446744073709551615,
    force_quick_range=false, ordered_output=false) at opt_range.cc:3041
#15 0x0832e13f in get_quick_record_count (thd=0xabd98f8, select=0xae5147c0, table=0xae6175f8, keys=0xae514400, limit=18446744073709551615)
    at sql_select.cc:2955
#16 0x0832ff46 in make_join_statistics (join=0xae523110, tables_list=..., conds=0xae513b90, keyuse_array=0xae528250) at sql_select.cc:3470
#17 0x083281a2 in JOIN::optimize (this=0xae523110) at sql_select.cc:1116
#18 0x0832de5f in mysql_select (thd=0xabd98f8, rref_pointer_array=0xabdb474, tables=0xae5130a0, wild_num=1, fields=..., conds=0xae513b90, og_num=0,
    order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147764736, result=0xae513ec8, unit=0xabdb058, select_lex=0xabdb338)
    at sql_select.cc:2892
#19 0x08325cfb in handle_select (thd=0xabd98f8, lex=0xabdaffc, result=0xae513ec8, setup_tables_done_option=0) at sql_select.cc:283
#20 0x082c0418 in execute_sqlcom_select (thd=0xabd98f8, all_tables=0xae5130a0) at sql_parse.cc:5112
#21 0x082b71d5 in mysql_execute_command (thd=0xabd98f8) at sql_parse.cc:2250
#22 0x082c2a59 in mysql_parse (thd=0xabd98f8,
    rawbuf=0xae512ec0 "SELECT * FROM t1\nWHERE b BETWEEN 4 AND 5\nAND a IN ( 255 , 4 ) \nOR b IN ( 2 , 14 , 25 ) \nOR b != 2", length=97,
    found_semicolon=0xae883228) at sql_parse.cc:6113
#23 0x082b4e24 in dispatch_command (command=COM_QUERY, thd=0xabd98f8,
    packet=0xac32789 "SELECT * FROM t1\nWHERE b BETWEEN 4 AND 5\nAND a IN ( 255 , 4 ) \nOR b IN ( 2 , 14 , 25 ) \nOR b != 2", packet_length=97)
    at sql_parse.cc:1221
#24 0x082b427f in do_command (thd=0xabd98f8) at sql_parse.cc:916
#25 0x082b1263 in handle_one_connection (arg=0xabd98f8) at sql_connect.cc:1191
#26 0x00821919 in start_thread () from /lib/libpthread.so.0
#27 0x0076acce in clone () from /lib/libc.so.6

Observations:
 - repeatable on maria-5.3. Not repeatable on MySQL 5.5, maria-5.2, maria-5.5
 - EXPLAIN also crashes
 - not influenced by any particular switch. The crash happens even with all index_merge switches set to OFF
 - no valgrind warnings

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=off,derived_merge=off,derived_with_keys=off,firstmatch=on,loosescan=on,materialization=off,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=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

bzr version-info:

revision-id: <email address hidden>
date: 2011-11-17 08:00:22 -0800
build-date: 2011-11-18 10:37:37 +0200
revno: 3291
branch-nick: maria-5.3

test case:

CREATE TABLE t1 (a int, b int, PRIMARY KEY (b), KEY (a));
INSERT INTO t1 VALUES (167,9999),(168,10000);

SELECT * FROM t1
WHERE b BETWEEN 4 AND 5
AND a IN ( 255 , 4 )
OR b IN ( 2 , 14 , 25 )
OR b != 2;

Changed in maria:
milestone: none → 5.3
description: updated
Changed in maria:
assignee: nobody → Igor Babaev (igorb-seattle)
Changed in maria:
status: New → Confirmed
importance: Undecided → Critical
Changed in maria:
status: Confirmed → In Progress
Changed in maria:
status: In Progress → Fix Committed
Changed in maria:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.