Comment 2 for bug 849776

Revision history for this message
Sergey Petrunia (sergefp) wrote :

(gdb) wher 4
  #0 simplify_joins (join=0xa679d00, join_list=0xa65f188, conds=0xa679000, top=true, in_sj=true) at sql_select.cc:11892
  #1 0x0835d5e8 in simplify_joins (join=0xa679d00, join_list=0xa678ce8, conds=0xa679000, top=true, in_sj=true) at sql_select.cc:11857
  #2 0x0835d5e8 in simplify_joins (join=0xa679d00, join_list=0xa5fdd2c, conds=0xa679000, top=true, in_sj=false) at sql_select.cc:11857
  #3 0x08371073 in JOIN::optimize (this=0xa679d00) at sql_select.cc:960
  (More stack frames follow...)

(gdb) p (Item*)conds
  $63 = (Item_cond_and *) 0xa679000
(gdb) p dbug_print_item(((Item*)conds)->list.nth_element(0))
  $64 = 0x8b78000 "1"
(gdb) p dbug_print_item(((Item*)conds)->list.nth_element(1))
  $65 = 0x8b78000 "(not(<in_optimizer>(`bug849776`.`t2`.`b`,<exists>(select `bug849776`.`t4`.`b` from `bug849776`.`t4` where (`bug849776`.`t4`.`b` < `bug849776`.`t1`.`b`)))))"
(gdb) p dbug_print_item(((Item*)conds)->list.nth_element(2))
  $66 = 0x8b78000 "(`bug849776`.`t5`.`a` = `bug849776`.`t1`.`a`)"
(gdb) p dbug_print_item(((Item*)conds)->list.nth_element(3))
  $67 = 0x88d9fc4 "(Item*)NULL"
(gdb) p/t conds->used_tables()
  $68 = 111

That is, the condition conds has form:

    1 AND t2.b NOT IN ( SELECT t4.b FROM t4 WHERE t4.b < t1.b ) AND t5.a=t1.a

not_null_tables() attribute seems to be wrong:

(gdb) p/t conds->not_null_tables()
  $69 = 111
## All three tables are NOT-NULL, this is what causes the left join be
## converted into inner join

(gdb) p ((Item*)conds)->list.nth_element(0)->not_null_tables()
  $71 = 0
(gdb) p ((Item*)conds)->list.nth_element(1)->not_null_tables()
  $72 = 0
(gdb) p ((Item*)conds)->list.nth_element(2)->not_null_tables()
  $73 = 3

# attributes of branches are correct. The problem is with Item_cond_and's
# attributes.