• Alexander Nozdrin's avatar
    Patch for Bug 12652769 - 61470: CASE OPERATOR IN STORED ROUTINE RETAINS · 8b1566aa
    Alexander Nozdrin authored
    OLD VALUE OF INPUT PARAMETER.
    
    The user-visible problem was that CASE-control-flow function
    (not CASE-statement) misbehaved in stored routines under some
    circumstances. The problem resulted in a crash or wrong data
    returned. The error happened when expressions in CASE-function
    were not of the same character set.
    
    A CASE-function should return values of the same character set
    for all branches. Internally, that means a new Item-instance
    for the CONVERT(... USING <some charset>)-function is added
    to the item tree when needed. The problem was that such changes
    were not properly recorded using THD::change_item_tree(),
    thus dangling pointers remain in the item tree after
    THD::rollback_item_tree_changes(), which lead to undefined
    behavior (i.e. crash / wrong data) for subsequent executions of
    the stored routine.
    
    This bug was introduced by a patch for Bug 11753363
    (44793 - CHARACTER SETS: CASE CLAUSE, UCS2 OR UTF32, FAILURE).
    
    The fixed function is Item_func_case::fix_length_and_dec().
    New CONVERT-items are added in agg_item_set_converter(),
    which calls THD::change_item_tree().
    
    The problem was that an intermediate array was passed
    to agg_item_set_converter(). Thus, THD::change_item_tree() there
    was called on intermediate objects.
    
    Note: those intermediate objects are allocated on THD's
    memory root, so it's Ok to put them into "changed item lists".
    
    The fix is to track changes on the correct objects.
    8b1566aa
sp.result 177 KB