• Neeraj Bisht's avatar
    Bug#17029399 - CRASH IN ITEM_REF::FIX_FIELDS WITH TRIGGER ERRORS · 356b6414
    Neeraj Bisht authored
    Problem:-
    In a Procedure, when we are comparing value of select query 
    with IN clause and they both have different collation, cause 
    error on first time execution and assert second time.
    procedure will have query like
    set @x = ((select a from t1) in (select d from t2));<---proc1
                  sel1                   sel2
    
    Analysis:-
    When we execute this proc1(first time)
    While resolving the fields of user variable, we will call 
    Item_in_subselect::fix_fields while will resolve sel2. There 
    in Item_in_subselect::select_transformer, we evaluate the 
    left expression(sel1) and store it in Item_cache_* object 
    (to avoid re-evaluating it many times during subquery execution) 
    by making Item_in_optimizer class.
    While evaluating left expression we will prepare sel1.
    After that, we will put a new condition in sel2  
    in Item_in_subselect::select_transformer() which will compare 
    t2.d and sel1(which is cached in Item_in_optimizer).
    
    Later while checking the collation in agg_item_collations() 
    we get error and we cleanup the item. While cleaning up we cleaned 
    the cached value in Item_in_optimizer object.
    
    When we execute the procedure second time, we have condition for 
    sel2 and while setup_cond(), we can't able to find reference item 
    as it is cleanup while item cleanup.So it assert.
    
    
    Solution:-
    We should not cleanup the cached value for Item_in_optimizer object, 
    if we have put the condition to subselect.
    
    
    356b6414
item_subselect.cc 72.8 KB