Skip to content
  • Sreeharsha Ramanavarapu's avatar
    6c82a894
    Bug #23205454: GCOLS: MEMORY LEAK AND GRADUAL PERFORMANCE · 6c82a894
    Sreeharsha Ramanavarapu authored
                   DEGRADATION
    
    
    ISSUE:
    ------
    This bug is in the function TABLE::refix_gc_items(). This
    function will be called for each query that uses the TABLE
    object. When the function calls fix_fields_gcol_func(), new
    items might be created. In this case new Item_cache_real
    objects are created. The items created by the call to
    fix_fields_gcol_func() are created in the table's mem_root.
    They are added to the field's gcol_info->item_free_list by
    the following code:
    
          // We need append the new items to orignal item lists
            Item *item= vfield->gcol_info->item_free_list;
            while(item->next)
              item= item->next;
            item->next= gcol_arena.free_list;
    
    The bug occurs due to the following:
    -each time refix_gc_items() is called for this generated
     column expression, two new item objects are produced and
     added to the end of the item_free_list which is on table's
     mem_root.
    -memory increase happens because item_free_list is growing.
    -the performance drop happens due to spending time in the
     above while loop to find the end of the ever growing
     item_free_list.
    
    The code that adds new items to the
    gcol_info->item_free_list was added in the fix for
    Bug#22392268. Before that fix, items added to the item tree
    for the generated column expression as part of calling
    TABLE::refix_gc_items() would be deleted when the statement
    ended, since they were created on the THD's stmt_arena. If
    the item was part of a permanent transformation, the next
    time this TABLE object was used, we could access deleted
    memory when using the item tree for the generated column
    expression.
    
    The fix for Bug#22392268 was to make sure that any created
    items that are added to gcol_info->item_free_list have the
    same life-span as the TABLE object. This worked fine for
    generated column expressions where TABLE::refix_gc_items()
    does permanent changes to the item tree but not in cases
    where new items are produced on every call to
    fix_fields_gcol_func().
    
    SOLUTION:
    ---------
    A new boolean flag permanent_changes_completed is added to
    the Generated_column class. This flag is set only when the
    permanent changes to the gcol function's item tree are
    completed.
    
    The fix for Bug#22392268 has been made subject to
    permanent_changes_completed. We create objects on the
    table's mem_root only when the permanent changes to the
    gcol function's item tree haven't been completed.
    6c82a894
    Bug #23205454: GCOLS: MEMORY LEAK AND GRADUAL PERFORMANCE
    Sreeharsha Ramanavarapu authored
                   DEGRADATION
    
    
    ISSUE:
    ------
    This bug is in the function TABLE::refix_gc_items(). This
    function will be called for each query that uses the TABLE
    object. When the function calls fix_fields_gcol_func(), new
    items might be created. In this case new Item_cache_real
    objects are created. The items created by the call to
    fix_fields_gcol_func() are created in the table's mem_root.
    They are added to the field's gcol_info->item_free_list by
    the following code:
    
          // We need append the new items to orignal item lists
            Item *item= vfield->gcol_info->item_free_list;
            while(item->next)
              item= item->next;
            item->next= gcol_arena.free_list;
    
    The bug occurs due to the following:
    -each time refix_gc_items() is called for this generated
     column expression, two new item objects are produced and
     added to the end of the item_free_list which is on table's
     mem_root.
    -memory increase happens because item_free_list is growing.
    -the performance drop happens due to spending time in the
     above while loop to find the end of the ever growing
     item_free_list.
    
    The code that adds new items to the
    gcol_info->item_free_list was added in the fix for
    Bug#22392268. Before that fix, items added to the item tree
    for the generated column expression as part of calling
    TABLE::refix_gc_items() would be deleted when the statement
    ended, since they were created on the THD's stmt_arena. If
    the item was part of a permanent transformation, the next
    time this TABLE object was used, we could access deleted
    memory when using the item tree for the generated column
    expression.
    
    The fix for Bug#22392268 was to make sure that any created
    items that are added to gcol_info->item_free_list have the
    same life-span as the TABLE object. This worked fine for
    generated column expressions where TABLE::refix_gc_items()
    does permanent changes to the item tree but not in cases
    where new items are produced on every call to
    fix_fields_gcol_func().
    
    SOLUTION:
    ---------
    A new boolean flag permanent_changes_completed is added to
    the Generated_column class. This flag is set only when the
    permanent changes to the gcol function's item tree are
    completed.
    
    The fix for Bug#22392268 has been made subject to
    permanent_changes_completed. We create objects on the
    table's mem_root only when the permanent changes to the
    gcol function's item tree haven't been completed.
Loading