• Aleksey Midenkov's avatar
    MDEV-23799 CREATE .. SELECT wrong result on join versioned table · a3c379ea
    Aleksey Midenkov authored
    For join to work correctly versioning condition must be added to table
    on_expr. Without that JOIN_CACHE gets expression (1)
    
      trigcond(xtitle.row_end = TIMESTAMP'2038-01-19 06:14:07.999999') and
      trigcond(xtitle.elementId = x.`id` and xtitle.pkey = 'title')
    
    instead of (2)
    
      trigcond(xtitle.elementId = x.`id` and xtitle.pkey = 'title')
    
    for join_null_complements(). It is NULL-row of xtitle for
    complementing the join and the above comparisons of course FALSE, but
    trigcond (Item_func_trig_cond) makes them TRUE via its trig_var
    property which is bound to some boolean properties of JOIN_TAB.
    
    Expression (2) evaluated to TRUE because its trig_var is bound to
    first_inner_tab->not_null_compl. The expression (1) does not evaluate
    correctly because row_end comparison's trig_var is bound to
    first_inner->found earlier. As a result JOIN_CACHE::check_match()
    skipped the row for join_null_complements().
    
    When we add versioning condition to table's on_expr the optimizer in
    make_join_select() distributes conditions differently. tmp_cond
    inherits on_expr value and in Good case it is full expression
    
    xgender.elementId = x.`id` and xgender.pkey = 'gender' and
    xgender.row_end = TIMESTAMP'2038-01-19 06:14:07.999999'
    
    while in Bad case it is only
    
    xgender.elementId = x.`id` and xgender.pkey = 'gender'.
    
    Later in Good row_end condition is optimized out and we get one
    trigcond in form of (2).
    a3c379ea
select.result 19.5 KB